How to disable Ctrl+Q shortcut in Firefox on Linux

In about:config set preferences.

Firefox >= 87

browser.quitShortcut.disabled true

https://bugzilla.mozilla.org/show_bug.cgi?id=52821

Firefox >= 65

browser.sessionstore.warnOnQuit true
browser.warnOnQuit true

enter image description here

Source

Older Firefox

browser.showQuitWarning true
browser.warnOnQuit true

Tested in all version I've come across 61.0.2-64.0.2 on 64bit Linux (and the 60esr channel on Win10). screenshot


tl/dr: assign a global shortcut to Ctrl-Q

In Firefox Quantum, the about:config settings that used to warn against Firefox closures via an accidental Ctrl-Q keypress no longer work.

Workaround: on Arch Linux | XFCE desktop environment (other Linux distros &/or desktops may allow a similar approach):

  • Whiskers menu >> All Settings >> Keyboard >> Application Shortcuts >> Add

  • Add a new "application", null; assign it to the Ctrl-Q keypress

    • Update (comment by @justderb): "Using 'true' instead of 'null' is nice if you don't want the error window to pop up."

Firefox - 'disable' Ctrl-Q

Invocation: here, I pressed Ctrl-Q in Firefox Quantum v. 60.0.1 (64-bit); instead of quitting Firefox, I get this popup,

Firefox - Ctrl-Q 'disabled'

Caveat: this, of course, globally affects all Ctrl-Q keypresses. However, -- per my own preference -- that shortcoming is outweighed by nullifying those accidental Firefox Ctrl-Q closures (after which I must re-login into websites: GitHub; reddit; ...).

Update 1

@crazypyro 's answer also works for me (FF Quantum 63.0 on x86_64 Linux) giving a popup warning if you try to Quit Firefox. That should be probably regarded as the specific answer, with my solution as a more general workaround.

about:config (both of the following set to true):

  • browser.showQuitWarning
  • browser.warnOnQuit

Update 2 [2020-03-01]

For some time in Vim I've encountered the occasional and frustrating issue where the terminal "freezes" and I lose keystroke control of Vim (requiring me to kill/restart Vim).

After some investigating, it turns out the issue is Software Flow Control (XON/XOFF flow control). Ctrl-s freezes the terminal until Ctrl-q is pressed -- which, per my solution presented above, is globally remapped to "dummy application" true.

The workaround to this issue is to add the lines

# enable Ctrl-s and Ctrl-q:
stty -ixon

near the top of your ~/.bashrc, then open a new terminal and start Vim.

Relevant links/discussion:

  • https://unix.stackexchange.com/questions/72086/ctrl-s-hang-terminal-emulator
  • https://stackoverflow.com/questions/3419820/sometimes-my-file-just-freezes-in-my-vi-vim-what-happened
  • https://unix.stackexchange.com/questions/478532/why-is-vim-frozen

  • https://unix.stackexchange.com/questions/72086/ctrl-s-hang-terminal-emulator | ... Before there were keyboards with the scroll lock key C-s and C-q were the old days "scroll lock toggle". You can disable this functionality by adding stty ixany and stty ixoff -ixon to your ~/.bashrc [... and restarting terminal]


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.

  1. Type about:support in the address bar.
  2. Under Application Basics > Profile Directory click the Open Directory button to open your Firefox profile directory.
  3. Within the profile directory, make a new directory called chrome
  4. Within the chrome directory, create new files userChrome.css and userChrome.xml with the contents listed below.
  5. 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>