How to forbid keyboard shortcut stealing by websites in Firefox

Thanks to Greasemonkey's new @run-at property, this is now possible!

I took inspiration from this script and this script to combine them into a Userscript that sucessfully intercepts the keyboard shortcuts Ctrl+T and Ctrl+S. I tested in in Firefox 17 ESR and Firefox 25.

// ==UserScript==
// @name           Disable Ctrl+s and Ctrl+t interceptions
// @description    Stop websites from highjacking keyboard shortcuts
//
// @run-at         document-start
// @include        *
// @grant          none
// ==/UserScript==

// Keycode for 's' and 't'. Add more to disable other ctrl+X interceptions
keycodes = [83, 84];  

(window.opera ? document.body : document).addEventListener('keydown', function(e) {
    // alert(e.keyCode ); //uncomment to find more keyCodes
    if (keycodes.indexOf(e.keyCode) != -1 && e.ctrlKey) {
        e.cancelBubble = true;
        e.stopImmediatePropagation();
    // alert("Gotcha!"); //ucomment to check if it's seeing the combo
    }
    return false;
}, !window.opera);

11 years after the bug was filed, Mozilla finally got to work on this popular feature request, and it seems to be working okay now (tested in Firefox 66.0.3/Ubuntu).

(Thanks to @PerJohansson for pointing out that they've made the setting much more difficult to find since FF 59.)

I've just updated this answer with some easier steps, tested with Firefox 75.

You can find screenshots for each step below.

  1. Press Ctrl-I (if you can) to show the Page Info window; or else right-click on an empty portion on the web page, and select View Page Info from the context menu.
  2. Select the Permissions tab
  3. Adjust the Override Keyboard Shortcuts setting.

Here are some recent (April 2020) screen shots for each step.

  1. If you use the mouse to open the Page Info window:

Firefox context menu

  1. Select the Permissions tab:

Firefox Page Info window

  1. Adjust the permissions appropriately:

Firefox Permissions tab

Mozilla has more information on the Page Info window here:

https://support.mozilla.org/en-US/kb/firefox-page-info-window

And if you're interested in the history of this fix, here are the related Mozilla tickets: https://bugzilla.mozilla.org/show_bug.cgi?id=380637 and https://bugzilla.mozilla.org/show_bug.cgi?id=1445942