In Firefox, how can I prevent pages from overriding Firefox built-in keyboard shortcuts through Javascript on a per-key basis? Preferably on a per-site basis, too? The most frustrating override is the forward slash ('/') that's linked to "Find in page". Sites like Google search results, Twitter timelines, some wikis, and other pages steal the slash key for their own search boxes, which is completely wrong.

Since my rep lets me ask, edit, and answer questions, but not add comments, this is basically a duplicate of these other two questions that weren't properly answered:

How do a stop a website for overriding my keyboard short cuts

Firefox: don't allow websites to override the / (slash) key


4 Answers 4


Building on edymtt's answer, I've created a userscript which disables only specific keyboard shortcuts. You can add more shortcuts to disable by adding keycodes to the keycodes array, or restrict which sites to apply it to by replacing the @include tag with one or more patterns.

Install using greasemonkey.

// ==UserScript==
// @name           Disable keyboard shortcuts
// @description    Stop websites from hijacking keyboard shortcuts
// @run-at         document-start
// @include        *
// @grant          none
// ==/UserScript==

keycodes = [191] // Keycode for '/', add more keycodes to disable other key captures

document.addEventListener('keydown', function(e) {
//    alert(e.keyCode); //uncomment to find out the keycode for any given key
    if (keycodes.indexOf(e.keyCode) != -1)
        e.cancelBubble = true;
    return false;
  • 2
    Awesome! Almost complete solution for meta keys, too--- I was trying to keep Google Docs from intercepting Previous-tab (Cmd+Left) and Next-tab (Cmd+Right) and found that I also needed to set useCapture to true; i.e., document.addEventListener('keydown', yourHandlerFn, true)
    – chbrown
    Oct 6, 2014 at 2:28
  • 1
    note that the value 191 depends on your keyboard layout, as far as my azerty setup is concerned (I have 16 + 58 for the alpha area and 111 for the numpad)
    – sylvainulg
    May 9, 2018 at 8:08
  • 2
    and unfortunately doesn't to work anymore nowadays (tested on phabricator and twitter). custom listener is triggered but site's event is triggered anyway and 'search in page' doesn't show up.
    – sylvainulg
    May 9, 2018 at 8:14
  • 1
    @sylvainulg I see that it doesn’t work on Twitter, but at least it works on GitHub still. I wonder what changed.
    – binki
    Jun 11, 2018 at 23:42
  • This works everywhere I tried it except php.net. I wonder what event they are using.
    – qwazix
    Nov 9, 2018 at 10:51

Since Firefox 58 it is possible to disable keyboard shortcuts override per web site.

"Override Keyboard Shortcuts" and many other permissions are available in "Page Info -> Permissions" (under info icon in URL bar).

Firefox Permissions example for superuser.com

Keyboard override was introduced in Firefox #380637

  • 2
    Yes, after 11 years they finally did a half-assed job of fixing that ticket. Unfortunately the current implementation (still in FF 59) completely disables the Backspace and Delete keys, which really sucks.
    – Lambart
    Apr 26, 2018 at 18:05
  • 8
    Also, unfortunately it doesn't prevent web pages from capturing non-shifted (i.e., no Ctrl, Shift or Alt key) input--which means this doesn't help at all with the slash key mentioned in the original question.
    – Lambart
    Apr 26, 2018 at 18:08
  • @Lambart - good to know, I ended up not using this too, since firefox keyboard shortcuts became fixed in jira and confluence (somewhere around firefox 59) Apr 27, 2018 at 6:06
  • 3
    what was fixed? JIRA and Confluence both still grab all sorts of keys that constantly disrupt my workflow. I see this as Atlassian's problem: They need to allow people to disable (and/or change) their "shortcuts".
    – Lambart
    Apr 27, 2018 at 16:36
  • firefox bugzilla.mozilla.org/show_bug.cgi?id=1433592 fixed atlassian products for me (there might have been atlassian fixes in same timeframe) Apr 27, 2018 at 20:50

With regard to Google and the Quick Find shortcut, you can install this Greasemonkey script:


As the description says, it "stops google from focusing the search input on every key press" -- in particular, if you press / with the keyboard focus outside the search box the Quick Find will appear, as it will on other web sites.

I have only installed it without touching the code, but I think it could be easily adapted to work with other sites and/or other shortcuts.

  • To clarify: this userscript stops ALL keyboard shortcuts on pages which it is enabled for, preserving the browser's own functionality. To apply it to other websites just add more @include tags.
    – MikeFHay
    May 15, 2013 at 12:57
  • without any information about what is hiding behind the link, the answer is unfortunately useless when userscripts-mirror.org gets down, blocked by a firewall or whatever.
    – sylvainulg
    May 9, 2018 at 8:19

Here is a more general script - you can define any number of keypress events to disable.


// ==UserScript==
// @name           Disable website keyboard hooks
// @description    Stop websites from hijacking keyboard shortcuts.
// @author         Isaac Levy
// @run-at         document-start
// @include        *
// @grant          none
// @version        0.0.1
// @namespace      https://isaacrlevy.com
// ==/UserScript==

var keycodes = [ // Add keycodes as desired, keep sorted.
    37, 38, 39, 40 // Arrow keys.

var meta_keycodes = [ // Disable these when meta key is pressed.

// Don't change below this line.

var isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;

// Create a fast lookup.
// This saves work during normal typing. Maybe unnecessary.
var keycode_offset = keycodes[0];
var keycode_arr = Array(keycodes[keycodes.length - 1] - keycode_offset)
for (var i = 0, len = keycodes.length; i < len; i++) {
    keycode_arr[keycodes[i] - keycode_offset] = true;

document.addEventListener('keydown', function(e) {
    if ((isMac && e.metaKey) || (!isMac && e.ctrlKey)) {
        if (meta_keycodes.indexOf(e.keyCode) >= 0) {
    } else if (keycode_arr[e.keyCode - keycode_offset]) {
    return false;
  • I'm sorry - but I cant get this to work. Especially I want to disable the arrow keys left and right on a site - but with this script the arrow keys still control the site??? Dec 4, 2015 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.