diff --git a/devtools/client/framework/devtools-browser.js b/devtools/client/framework/devtools-browser.js index 46be3fdfa6ef..e421da95ec75 100644 --- a/devtools/client/framework/devtools-browser.js +++ b/devtools/client/framework/devtools-browser.js @@ -70,6 +70,10 @@ const L10N = new LocalizationHelper( const BROWSER_STYLESHEET_URL = "chrome://devtools/skin/devtools-browser.css"; +// XXX: This could also be moved to DevToolsStartup, which is the first +// "entry point" for DevTools shortcuts and forwards the events +// devtools-browser. +const DEVTOOLS_F12_DISABLED_PREF = "devtools.experiment.f12.shortcut_disabled"; /** * gDevToolsBrowser exposes functions to connect the gDevTools instance with a * Firefox instance. @@ -299,9 +303,24 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = { // Otherwise implement all other key shortcuts individually here switch (key.id) { case "toggleToolbox": - case "toggleToolboxF12": await gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, startTime); break; + case "toggleToolboxF12": + // See Bug 1630228. F12 is responsible for most of the accidental usage + // of DevTools. The preference here is used as part of an experiment to + // disable the F12 shortcut by default. + const isF12Disabled = Services.prefs.getBoolPref( + DEVTOOLS_F12_DISABLED_PREF, + false + ); + + if (!isF12Disabled) { + await gDevToolsBrowser.toggleToolboxCommand( + window.gBrowser, + startTime + ); + } + break; case "browserToolbox": BrowserToolboxLauncher.init(); break; diff --git a/devtools/client/framework/toolbox.js b/devtools/client/framework/toolbox.js index 5328c65a434c..2792a3e6549a 100644 --- a/devtools/client/framework/toolbox.js +++ b/devtools/client/framework/toolbox.js @@ -212,6 +212,8 @@ loader.lazyRequireGetter( "devtools/shared/picker-constants" ); +const DEVTOOLS_F12_DISABLED_PREF = "devtools.experiment.f12.shortcut_disabled"; + /** * A "Toolbox" is the component that holds all the tools for one specific * target. Visually, it's a document that includes the tools tabs and all @@ -253,6 +255,12 @@ function Toolbox( // must use the time since the system wide epoch as the session ID. this.sessionId = msSinceProcessStart; + // If the user opened the toolbox, we can now enable the F12 shortcut. + if (Services.prefs.getBoolPref(DEVTOOLS_F12_DISABLED_PREF, false)) { + // Flip the preference. + Services.prefs.setBoolPref(DEVTOOLS_F12_DISABLED_PREF, false); + } + // Map of the available DevTools WebExtensions: // Map this._webExtensions = new Map(); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 59bb80f717a0..590c31ac4a0c 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4911,6 +4911,9 @@ pref("devtools.devices.url", "https://code.cdn.mozilla.net/devices/devices.json" // Enable Inactive CSS detection; used both by the client and the server. pref("devtools.inspector.inactive.css.enabled", true); +// The F12 experiment aims at disabling f12 on selected profiles. +pref("devtools.experiment.f12.shortcut_disabled", false); + #if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION) // Define in StaticPrefList.yaml and override here since StaticPrefList.yaml // doesn't provide a way to lock the pref