7/21/2023Â Remapping firefox keys on MacOS
Tested with firefox version 129.0.2 on MacOS Sonoma 14.1
Create two files
touch /Applications/Firefox.app/Contents/Resources/defaults/pref/config-prefs.js
touch /Applications/Firefox.app/Contents/Resources/config.js
// config-prefs.js
pref('general.config.filename', 'config.js');
pref('general.config.obscure_value', 0);
pref('general.config.sandbox_enabled', false);
// config.js
// Add Ctrl-J and Ctrl-K as nextTab and PrevTab
const Services = globalThis.Services;
function ConfigJS() {
Services.obs.addObserver(this, 'chrome-document-global-created', false);
}
try {
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 nextTabKey = window.document
.createElementNS(
'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
'key',
);
nextTabKey.setAttribute('id', 'key_nextTabCustom');
nextTabKey.setAttribute('modifiers', 'control');
nextTabKey.setAttribute('key', 'J');
nextTabKey.setAttribute('command', 'Browser:NextTab');
let previousTabKey = window.document
.createElementNS(
'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
'key',
);
previousTabKey.setAttribute('id', 'key_previousTabCustom');
previousTabKey.setAttribute('modifiers', 'control');
previousTabKey.setAttribute('key', 'K');
previousTabKey.setAttribute('command', 'Browser:PrevTab');
let mainKeyset = window.document.getElementById('mainKeyset');
mainKeyset.appendChild(nextTabKey);
mainKeyset.appendChild(previousTabKey);
}
}
},
};
if (!Services.appinfo.inSafeMode) new ConfigJS();
} catch (ex) {}
Tips
To find all key or command names, activate the Browser Toolbox : In developer tools > ... > Settings > Advanced Settings activate both :
Enable browser chrome and add-on debugging tools
Enable remote debugging
then you sould be able to go into Settings > More Tools > Browser Toolbox and search the DOM for
#mainKeyset
#mainCommandset
Error when modifying Firefox files
If you install Firefox and then modify files as explained above, you might encounter an error at Firefox startup :
This application is damaged, you should put it to trash...
Or you might already have Firefox installed,
but you get Operation not permitted
when you try to touch
any new file in
/Applications/Firefox.app/Contents/Resources/
Here are the steps to avoid this kind of error :
First uninstall and reinstall Firefox
Then, before opening Firefox for the first time, run this command to prevent macOS verification :
cd /Applications
xattr -r -d com.apple.quarantine Firefox.app
Then do the modifications as explained above.
Firefox should now startup without any error.