How to disable Ctrl+Q shortcut in Firefox on Linux

60

11

Since Firefox 57 there is no way to disable Ctrl+Q shortcut by plugin on Linux (see this bug). All workarounds I've found are based on setting the global Ctrl+Q shortcut to "steal" it from Firefox. But this will disable this shortcut in every application, and I want to disable this shortcut only in Firefox, without affecting any other app.

Is there a way to disable or catch shortcut only for one application? I'm using Ubuntu with Unity.

rob006

Posted 2018-04-29T20:57:03.873

Reputation: 741

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

Answers

50

In about:config set preferences.

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

CrazyPyro

Posted 2018-04-29T20:57:03.873

Reputation: 712

2Any constructive feedback with that downvote? – CrazyPyro – 2018-09-13T17:05:54.320

1Thanks, works for me at least on FF 62.0.3 (64-Bit Ubuntu). – Pont – 2018-10-08T20:51:05.887

thank you. This is smart solution, without touching anything. – luca76 – 2018-10-15T09:25:59.697

^ This is the right answer! – Ole Tange – 2018-10-19T17:07:56.033

1That doesn't work along with "Restore Previous Session" or "Show my windows and tabs from last time", which is even worse. – chefarov – 2018-11-06T10:02:09.150

@chefarov can you explain what you mean? I've seen no problems getting my tabs back after a crash or reboot. – CrazyPyro – 2018-11-14T23:14:34.467

5And now, as of FF 63.0.3 (64-Bit Ubuntu), ctrl-Q once again quits instantly for me, despite both those options being enabled. It's astonishing what a mess they've made of this simple (mis-)feature. Ah well, maybe it will be working again in v64... – Pont – 2018-11-23T12:33:32.387

4I don't see the browser.showQuitWarning on ff quantum 64.0 64bit on linux. browser.warnOnQuit is enabled but does nothing? – bool3max – 2019-01-19T21:22:23.507

1Thanks @rofrol for finding the missing piece - some FF versions have changed the relevant key name - just search for "quit" and you should be good. – CrazyPyro – 2019-02-01T16:22:37.487

1In bugfox 65.0.2 this just completely disabled ctrl+q (which is completely fine for me). – wlfbck – 2019-03-12T20:41:22.390

5

This is not working for me in Firefox 66.0.5 in Manjaro Linux. Will have to deal with browser.tabs.warnOnClose;true now. Related: https://bugzilla.mozilla.org/show_bug.cgi?id=502908#c73

– aguadopd – 2019-05-19T02:02:43.093

3Selected answer no longer resolves the issue. – Paul – 2019-06-06T01:24:39.627

still works with Firefox 68.0 – dayer4b – 2019-07-31T16:54:24.063

1Does not work anymore on Firefox 69.0.2 in Archlinux. browser.showQuitWarning is missing and both browser.warnOnQuit and browser.sessionstore.warnOnQuit seem to be ignored. – JoL – 2019-10-08T17:07:44.080

2After a little more digging, it turns out it's now necessary to enable Preferences > General > Startup > Restore previous session for Warn you when quitting the browser to work. – JoL – 2019-10-08T17:22:28.463

17

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

@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

Victoria Stuart

Posted 2018-04-29T20:57:03.873

Reputation: 355

8Using true instead of null is nice if you don't want the error window to pop up. – justderb – 2018-08-20T19:59:59.323

@justderb: nice! :-D – Victoria Stuart – 2018-09-18T02:29:09.700

1for me in archlinux/kde 5 plasma I could not do global shortcut without choosing an application first - could not be true|null, but thanks to your suggestion i was able to remapped it to toggle microphone - which on work computer is pointless for me anyway.. thanks! – JTC – 2018-10-08T11:35:05.380

Mapping CTRL+q in sxhkd also hijacks the shortcut, preventing Firefox to quit. – Simon Cedergren Malmqvist – 2019-03-08T09:15:59.453

Works in Mint 19. – Paul – 2019-06-06T01:25:36.203

7

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>

thinkmassive

Posted 2018-04-29T20:57:03.873

Reputation: 274

1This doesn't work in Firefox 62 – Grief – 2018-08-16T10:54:37.597

1It works with the latest stable, Firefox 61. Hopefully 62 is fixed before it leaves beta. – thinkmassive – 2018-08-16T16:40:24.960

I now use the solution from CrazyPyro https://superuser.com/a/1352295/308508

– thinkmassive – 2019-02-08T20:36:40.203

Doesn't work in 69.0.2 (not beta). Also, document.getElementById('key_quitApplication') returns null. Has the name of this element changed? – tsbertalan – 2019-10-18T17:22:33.173

6

An ugly, but simple and effective workaround is always keeping a page open that has an active onbeforeunload handler, i.e. will trigger the "This page is asking you to confirm that you want to leave - data you have entered may not be saved." dialog when you attempt to close it.

That way, if you accidentally try to CTRL+Q, you will receive that dialog, and can choose "stay on this page" to cancel the exit.

Edit: Custom page I made just for this purpose

Jan Schejbal

Posted 2018-04-29T20:57:03.873

Reputation: 1 014

nice hacker spirit there! – Daniel Hitzel – 2019-01-15T15:55:52.403

Thanks! Added a link to my implementation. – Jan Schejbal – 2019-04-22T21:44:07.690

Thanks for this. Works for me, and so cheezy I love it (: It's astounding to me that FF has messed up this simple thing. – jwd – 2019-10-31T22:06:57.467

3

I was able get what I need with AutoKey. After installation I created empty script with assigned Ctrl+Q as "Hotkey" and .*Firefox as "Window filter".

enter image description here

Then in AutoKey preferences I added it to autostart and disabled notification icon, so it becomes transparent for me.

enter image description here

I used it for a few hours and it looks promising - no false-positives or missed catches so far. Right now Ctrl+Q does not working for Firefox, but it works perfectly fine in PhpStorm for example.


In addition bug 1215061 gives some hope that this will be easier in future and Firefox will finally get some decent keyboard shortcuts settings.

rob006

Posted 2018-04-29T20:57:03.873

Reputation: 741