There is a way. It's not super official, but basically you can unpack browser/omni.ja, edit the keybindings in chrome/browser/content/browser/browser.xul, repack it, delete startup cache and it will work.
Alternatively, you can compile your own firefox and then you don't need to unpack the binary, if you consider unpacking and repacking more hacky, than building.
Another advantage of building is that you can store your modifications on top of the official sources in git and always rebase, like I do here: https://github.com/errge/gecko-dev/tree/gregzilla-patched-20181223
I advise you to first start with the binary option, because you will have working keyboard shortcuts in 20 minutes, instead of just being at the start of the mercurial clone procedure :)
Both of these methods are independent of any extensions/webextensions and will ALWAYS work, even in the location bar and even on protected pages (as you asked in the comments). So they will work better than remapping webextensions.
I have an article written up with all the details that may interest you: https://github.com/nilcons/firefox-hacks
If you have more questions, please report issues on github.
Answer from errge on Stack ExchangeIs there really no way(without weird 3rd party add-ons) to update the default keyboard shortcuts in Firefox? "/" key is literally a hotkey for quick search. I can't run / commands in browser without Firefox being stupid.
How to change Firefox keyboard shortcuts
Change default keyboard shortcuts (on Firefox) - Zotero Forums
Override Keyboard Shortcuts in Firefox - Stack Overflow
How to change a keyboard shortcut in Firefox? - Hardware and technical stuff - Quarter To Three Forums
Videos
There is a way. It's not super official, but basically you can unpack browser/omni.ja, edit the keybindings in chrome/browser/content/browser/browser.xul, repack it, delete startup cache and it will work.
Alternatively, you can compile your own firefox and then you don't need to unpack the binary, if you consider unpacking and repacking more hacky, than building.
Another advantage of building is that you can store your modifications on top of the official sources in git and always rebase, like I do here: https://github.com/errge/gecko-dev/tree/gregzilla-patched-20181223
I advise you to first start with the binary option, because you will have working keyboard shortcuts in 20 minutes, instead of just being at the start of the mercurial clone procedure :)
Both of these methods are independent of any extensions/webextensions and will ALWAYS work, even in the location bar and even on protected pages (as you asked in the comments). So they will work better than remapping webextensions.
I have an article written up with all the details that may interest you: https://github.com/nilcons/firefox-hacks
If you have more questions, please report issues on github.
You can change key bindings in Firefox with AutoConfig, without having to unpack and modify the Firefox binary.
Create a config-prefs.js and config.js file:
on Windows:
C:\Program Files\Mozilla Firefox\defaults\pref\config-prefs.jsC:\Program Files\Mozilla Firefox\defaults\pref\config.js
on macOS:
Firefox.app\Contents\Resources\config.jsFirefox.app\Contents\Resources\defaults\pref\config-prefs.js
on Linux:
/usr/lib/firefox/config.js(resp/usr/lib64/firefox/config.js)/usr/lib/firefox/browser/defaults/preferences/config-prefs.js(resp/usr/lib64/firefox/browser/defaults/preferences/config-prefs.js)
If the above path is not correct, use
whereis firefoxto find the correct directory on your system.
with the following content:
config-prefs.js:
pref("general.config.filename", "config.js");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);
config.js:
try {
let { classes: Cc, interfaces: Ci, manager: Cm } = Components;
const Services = globalThis.Services;
// Firefox 148+: use browser-delayed-startup-finished instead of
// chrome-document-global-created (Bug 2002767 changed startup sequence)
function ConfigJS() { Services.obs.addObserver(this, 'browser-delayed-startup-finished', false); }
ConfigJS.prototype = {
observe: function (window) {
// Place your keyboard shortcut changes here
// ...
// ...
}
};
if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
} catch(ex) {};
After modifying these files, you always have to go to about:support and run Clear startup cache, to restart the browser with the new config.
Some examples what you can do:
Put these snippets into config.js, where I wrote Place your keyboard shortcut changes here.
Remove an existing keyboard shortcut
// remove Ctrl-Shift-X, so that I can map it to 1Password in the 1Password app later
let keySwitchDirection = window.document.getElementById('key_switchTextDirection');
keySwitchDirection.remove();
Change an existing keyboard shortcut
// remap Ctrl-J to downloads (removing it from focusing the browser bar)
let search2 = window.document.getElementById('key_search2')
search2.remove();
let openDownloads = window.document.getElementById('key_openDownloads')
openDownloads.setAttribute("modifiers", "accel");
openDownloads.setAttribute("key", "J");
Create a new keyboard shortcut
// create keyboard shortcut to Toolbar > Settings with Ctrl-,
let mainKeyset = window.document.getElementById("mainKeyset");
let settingsKey = window.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'key');
settingsKey.setAttribute("id", "key_Settings");
settingsKey.setAttribute("modifiers", "accel,shift");
settingsKey.setAttribute("key", "U");
settingsKey.setAttribute("oncommand", "openPreferences()");
settingsKey.addEventListener('command', this, false);
mainKeyset.appendChild(settingsKey);
Something completely custom. (Firefox introduced the Shift-Ctrl-T as an universal undo (change set), so the example here is not necessary anymore. I'll leave it here to serve as an example for other customizations.)
// make Ctrl-Shift-T reopen last tab OR last window, depending on which one was closed last
let undoCloseTabKey = window.document.getElementById('key_undoCloseTab');
undoCloseTabKey.removeAttribute('command');
undoCloseTabKey.setAttribute('oncommand', 'undoCloseLastClosedTabOrWindow()');
undoCloseTabKey.addEventListener('command', this, false);
window.undoCloseLastClosedTabOrWindow = function() {
// don't have any tabs to restore
if (SessionStore.getClosedTabCount(window) == 0) {
// we don't need to worry whether there are any windows to restore - undoCloseWindow does that for us
window.undoCloseWindow();
}
// don't have any windows to restore
else if (SessionStore.getClosedWindowCount() == 0) {
// we don't need to worry whether there are any tabs to restore - undoCloseTab does that for us
window.undoCloseTab();
}
// restore whichever was closed more recently
else if (SessionStore.getClosedTabData(window)[0].closedAt > SessionStore.getClosedWindowData()[0].closedAt) {
window.undoCloseTab();
} else {
window.undoCloseWindow();
}
}
Instructions:
To find existing keyboard shortcuts:
- Hamburger menu > More Tools > Browser Toolbox
- In the Inspector, search for
#mainKeyset - There, you see all assigned keyboard shortcuts
To find menu actions that you can trigger with keyboard shortcuts
- Hamburger menu > More Tools > Browser Toolbox
- Use the Inspector to find the element that you want to trigger with a keyboard shortcut, for example
appMenu-settings-button - Take the
oncommandattribute from the menu item, and use it asoncommandattribute for the key tag
or
- Use the Inspector, search for
#mainCommandSet - and take the commands's
id, and use it ascommand(notoncommand) attribute for the key tag.
Defining keyboard shortcuts:
- specify modifiers with the
modifiersattribute. You can useaccel(for Ctrl),shiftandalt - specify the key itself with the
keyattribute
Source for all of this: Reddit, u/aveyo, Restore Ctrl+Shift+B = Library by setting config.js
More details: Firefox Keyboard Shortcuts (Web Archive)
I found a way by adding two files under the Firefox directory
Firefox64\defaults\pref\config-prefs.js
pref("general.config.filename", "config.js");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);
Firefox64\config.js
let { classes: Cc, interfaces: Ci, manager: Cm } = Components;
const {Services} = Components.utils.import('resource://gre/modules/Services.jsm');
function ConfigJS() { Services.obs.addObserver(this, 'chrome-document-global-created', false); }
ConfigJS.prototype = {
observe: function (aSubject) { aSubject.addEventListener('DOMContentLoaded', this, {once: true}); },
handleEvent: function (aEvent) {
let document = aEvent.originalTarget; let window = document.defaultView; let location = window.location;
if (/^(chrome:(?!\/\/(global\/content\/commonDialog|browser\/content\/webext-panels)\.x?html)|about:(?!blank))/i.test(location.href)) {
if (window._gBrowser) {
let keys = ["key_find", "key_findAgain", "key_findPrevious", "key_gotoHistory", "addBookmarkAsKb", "bookmarkAllTabsKb", "showAllHistoryKb", "manBookmarkKb", "viewBookmarksToolbarKb", "key_savePage", "key_search", "key_search2", "focusURLBar", "focusURLBar2", "key_openDownloads", "openFileKb", "key_reload_skip_cache", "key_viewSource", "key_viewInfo", "key_privatebrowsing", "key_quitApplication", "context-bookmarklink"];
for (var i=0; i < keys.length; i++) {
let keyCommand = window.document.getElementById(keys[i]);
if (keyCommand != undefined) {
keyCommand.removeAttribute("command");
keyCommand.removeAttribute("key");
keyCommand.removeAttribute("modifiers");
keyCommand.removeAttribute("oncommand");
keyCommand.removeAttribute("data-l10n-id");
}
}
}
}
}
};
if (!Services.appinfo.inSafeMode) { new ConfigJS(); }
You can get a list of ids for the keys from the source by putting the following URL in your browser
view-source:chrome://browser/content/browser.xhtml
For those on Linux or similar Unix/Unix-like systems, replace Firefox64 with /usr/lib/firefox. Don't be confused with $HOME/.mozilla/firefox
Related to zackhalil's answer:
For those on Linux or simillar Unix/Unix-like systems replace Firefox64 for /usr/lib/firefox. Don't be confused with $HOME/.mozilla/firefox