Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8664467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:14:48+00:00 2026-06-12T17:14:48+00:00

I have a userscript for Google Reader , and as part of that userscript

  • 0

I have a userscript for Google Reader, and as part of that userscript I need to trigger a refresh, which I do in Firefox by simulating a keypress for the letter r.

function simulateRefresh()
{
    var e = document.createEvent('KeyboardEvent');
    e.initKeyEvent('keypress', true, true, window, false, false, false, false, 82, 82);
    document.body.dispatchEvent(e);
}

This works in Firefox, but not in Chrome. Apparently initKeyEvent is not supported, and I’m supposed to use initKeyboardEvent.
So far I’ve had zero luck with this (There is no error in the console, but the refresh does not fire.) I am using jQuery if that matters.

I also tried triggering click on the refresh button, but this failed in both browsers (not sure why, the click event is firing according to the Chrome debugger, but the code is obfuscated, so I can’t figure it out).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:14:50+00:00Added an answer on June 12, 2026 at 5:14 pm

    Google webapps often do not use a simple keypress or click, when a complex sequence of states will do. 😉

    So sending a “click” to the refresh button does not work, but sending an “over, down, up” triad does. Like so:

    var refreshBtn = document.querySelector ('#viewer-refresh');
    
    //--- Click by itself does not work!
    triggerMouseEvent (refreshBtn, 'mouseover');
    triggerMouseEvent (refreshBtn, 'mousedown');
    triggerMouseEvent (refreshBtn, 'mouseup');
    
    function triggerMouseEvent (node, eventType) {
        var clickEvent = document.createEvent('MouseEvents');
        clickEvent.initEvent (eventType, true, true);
        node.dispatchEvent (clickEvent);
    }
    


    A similar kind of state-sequence may be required for the keyboard shortcut. (Testing continues.)

    Update: For the keyboard events, see this answer which mentions Webkit Bug 16735: “Keyboard events created with DOM have keyCode and charCode of 0” — which is still open after 4.5 years(!!) and might apply here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a userscript that has to change a whole list of options depending
I have a userscript (read: my Javascript on someone else's site) that allows users
I have this in my UserScript file: window.testMyFunctionBLah = function() { alert('hey'); } window.setTimeout(
I have a UserScript which should remove all images of a certain class on
I have a Greasemonkey userscript which runs most of its code in an unprivileged
I have userscript. I recentyly added jquery to it. Before I added jquery that
I'm writing a UserScript (=Greasemonkey) which I am developing in FireFox but works in
For this userscript I'm writing, I need to use a third-party JavaScript library which
So currently I am trying to add a feature to a userscript I have
have written this little class, which generates a UUID every time an object of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.