Disable Ctrl+q with userChrome.js in Firefox Quantum
This can be accomplished without an external application by a tiny bit of javascript in your Firefox profile.
As a prerequisite, you must enable userChrome.js (see below, or obtain from the original GitHub repo)
After copying the chrome directory and its contents into your user profile, create a file <profile-dir>/chrome/disable_ctrl_q.uc.js
with the following content:
var kqa = document.getElementById('key_quitApplication');
if (kqa) kqa.remove();
Lastly, restart Firefox, and ctrl+q will no longer cause the application to exit.
Enabling userChrome.js in Firefox Quantum
For completeness, below are the full contents of the modified chrome files. To enable userChrome javascript, create these two files inside a chrome
directory within your Firefox profile.
- Type
about:support
in the address bar.
- Under Application Basics > Profile Directory click the Open Directory button to open your Firefox profile directory.
- Within the profile directory, make a new directory called
chrome
- Within the
chrome
directory, create new files userChrome.css
and userChrome.xml
with the contents listed below.
- Restart Firefox (you probably also want to create the .uc.js file above if you're following these steps to disable ctrl+q)
userChrome.css
/* Copyright (c) 2017 Haggai Nuchi
Available for use under the MIT License:
https://opensource.org/licenses/MIT
*/
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
toolbarbutton#alltabs-button {
-moz-binding: url("userChrome.xml#js");
}
userChrome.xml
<?xml version="1.0"?>
<!-- Copyright (c) 2017 Haggai Nuchi
Available for use under the MIT License:
https://opensource.org/licenses/MIT
-->
<bindings id="generalBindings"
xmlns="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xbl="http://www.mozilla.org/xbl">
<binding id="js" extends="chrome://global/content/bindings/toolbarbutton.xml#menu">
<implementation>
<constructor><![CDATA[
function makeRelativePathURI(name) {
let absolutePath = Components.stack.filename;
return absolutePath.substring(0, absolutePath.lastIndexOf("/") + 1) + name;
}
// The following code executes in the browser context,
// i.e. chrome://browser/content/browser.xul
Services.scriptloader.loadSubScript(makeRelativePathURI("userChrome.js"), window);
]]></constructor>
</implementation>
</binding>
</bindings>
Interesting question, but the answer may depend on the use case. Accidental key presses? Kiosk mode? – l0b0 – 2018-04-29T21:13:10.163
4@l0b0 Accidental key presses. This is regular PC, nothing fancy. – rob006 – 2018-04-29T21:14:24.313
In that case, do you have more details? I'm just checking if there is some way the system can be set up to Do What You Want™, such as save the tabs when you quit, to avoid something which I suspect will be a brittle hack. – l0b0 – 2018-04-29T21:46:42.527
7@l0b0 I want to prevent closing browser by accidental key presses. There is a too many things are changing after closing browser (closing sessions, terminating connections), I would prefer to prevent closing browser than fixing its effects. – rob006 – 2018-04-29T22:30:27.973