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.
- 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. - Select the
Permissions
tab - Adjust the
Override Keyboard Shortcuts
setting.
Here are some recent (April 2020) screen shots for each step.
- If you use the mouse to open the Page Info window:
- Select the
Permissions
tab:
- Adjust the permissions appropriately:
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
Extensive research shows that as of current version of Firefox (3.6.x) this is impossible - all key binding conflicts are resolved with priorities: System > Website > Firefox - a rather stupid order that is. None of addons I've tried seems to be able to fix it.
Possibly it might become doable in future versions, but right now the answer is - Impossible.