How to prevent keystroke grabbing/hijacking by websites in Firefox?

6,002

You could use Vimperator plugin. Aimed at making Firefox a keyboard-only interface, it first listens to any keystroke that you press and performs its own actions. Sometimes when you would require to use the site's defined keyboard hijacks, you could easily enable/disable a pass-through mode for sometime.

Let's take the case of GMail, which offres a host of keyboard shortcuts. But when you press any such shortcut, it is handled by Vimperator itself. For example, pressing / inside GMail usually places the cursor in the search box. But pressing / in a GMail page when Vimperator is active triggers its default page search (ala searching in Vim editor). Same case for other GMail shortcuts like o c or even Ctrl+Enter. What this means is that, Vimperator will be the 0th listener for keystrokes in Firefox, over-riding even the 1st possible listeners so that your keyboard shortcuts are global throughout the browser.

Vimperator is basically a Vim wrapper over Firefox. If you are comfortable with Vim, Vimperator will seem like a long-lost friend. :-)

Anyway, a few Vimperator keyboard shortcuts to get you started with:

o<link> opens the . This sequences causes the Vimperator command line (at the bottom of the screen) to be activated and the command open <link> will be placed there, with the space in the middle inserted for you. Press Enter to load the page.

t<link activates the command tabopen and opens the link in a new tab.

gt switches to next tab. Ctrl+Tab and Ctrl+PgUp/Dn also work.

gT switches to previous tabs.

ZZ closes FF after saving the session.

f labels all the links in the page view with highlighted numbers. Typing a number opens the link. All the highlighted fields are searchable. So, instead of typing numbers, you could type any of the text in the highlighted link that you want to go to.

F opens links in a background tab.

h j k l to navigate the page left down upand right

Vimperator offers a host of keyboard shortcuts (and certainly makes the whole experience painlessly mouse-free), and most of FF's default shortcuts function as they normally do. You can find shortcuts to highlight text, copy them, navigate the page as if it were a text document, zoom in/out, simulate the hover on a link, and simply put, anything that would make Firefox respond to a mouse.

The only place where it doesn't work as far as I've used it, is inside Flash boxes, because, FF can't reach what's inside them.

It might take a bit of getting used to if you don't know about Vim or are new to it. However, really extensive online help is just a :h<Enter> away.

Here is the link.

Share:
6,002

Related videos on Youtube

user
Author by

user

Updated on September 18, 2022

Comments

  • user
    user over 1 year

    Some web sites (an increasing number of them these days, it seems) hijack various key combinations to perform actions within and defined by the web site itself. There's the specific example of / in GMail in an inappropriately titled question; there's the StackExchange edit box which hijacks Ctrl+G for "Add image" (rather than Firefox's normal "Find next"); there's Facebook hijacking Esc to hide an overlay rather than the usual "stop loading". I'm sure I could go on and on with examples, but this should be enough to illustrate that this question is not about any one specific website.

    I use the keyboard extensively and keyboard shortcuts behaving differently based on which web site I am on is a major annoyance to me. If I press a browser-defined keyboard shortcut, I want the action defined by the browser to be taken, not something else. I also don't want certain features which are normally accessible by keyboard to not be accessible by keyboard, or suddenly be remapped to other key combinations.

    I realize that this may make some things more cumbersome on some sites, but in this case I prefer consistency.

    Is it possible to set up Firefox to prevent or ignore such hijackings by web sites and favor Firefox's own defined behavior?

    A solution that works at least for Firefox versions 20, 21 and 22 on both Linux and Windows would be ideal.

    Edit Mozilla Bugzilla Bug 380637 Should web pages be able to override the browser's keyboard shortcuts? seems to indicate it is at least being looked at. That bug was initially submitted in mid-2007 and is still active as of mid-2013. Interestingly enough, bug 775002 Enable users to disable javascript to hijack keyboard shortcuts was considered a duplicate around Firefox 15.

    • Admin
      Admin almost 11 years
      I suspect they're doing this via Javascript. If so there would be no generic way to disable it without disabling Javascript.
    • Admin
      Admin almost 11 years
      yep maybe api.jquery.com/keypress . It would be interesting if there was an addon that allowed selective .js re-writing at the client side. you could then just comment out these calls using regex or similar
    • Admin
      Admin almost 11 years
      Even if done through Javascript,somewhere there has to be a key press listener involved, and that functionality is provided by the browser. I see no reason why that code couldn't be modified such that the browser interprets any keystrokes (maybe with modifier keys) first, and if the browser takes any action in response, the key press is not passed on to the Javascript provided by the web page. Making such behavior configurable (if you don't want to expose it through the settings GUI, there's still about:config which already allows access to many such advanced settings) should be fairly easy.
    • Admin
      Admin almost 11 years
      @Downvoter Why the downvote?
    • Admin
      Admin almost 11 years
      @Karan Correction bugzilla.mozilla.org/show_bug.cgi?id=380637 indicates it is in the development pipeline at least.
    • Admin
      Admin almost 11 years
      @MichaelKjörling: Doesn't really matter IMO how old the other one is, your question is almost an exact duplicate. If you want to draw attention to the issue and want updated answers place a bounty on that question. You're a long-time member and so I don't need to tell you how the bounty process works.
    • Admin
      Admin about 6 years
      After 11 years, Mozilla finally took action on the bug linked in the question. Unfortunately the implementation is buggy (if you like to use Del or Backspace keys), but it's sort-of fixed. See the linked "duplicate" question; specifically, this answer: superuser.com/a/1305827/158390
  • Homer Simpsons
    Homer Simpsons almost 11 years
    try marking the script as untrusted Pic: i.stack.imgur.com/45aAv.png or use proxy to block any response from a script eg. fiddler
  • user
    user almost 11 years
    If I use NoScript to mark e.g. facebook.com as untrusted, no Javascript originating from facebook.com will execute. This is not what I want. Please re-read the question.
  • Homer Simpsons
    Homer Simpsons almost 11 years
    Got it use this Link: addons.mozilla.org/sv-se/firefox/addon/greasemonkey and script link: userscripts.org/scripts/show/125936 <= look here ("if (src.search(/bad\.js/) != -1) {")
  • user
    user almost 11 years
    I still don't see how that helps me. Can you edit it into your answer with a fuller explanation of how it answers the question?
  • Bob Brown
    Bob Brown almost 6 years
    apparently, vimperator is no longer compatible with modern builds of firefox.