Bug 1410360 - reselect original tab after closing about:devtools;r=ochameau
MozReview-Commit-ID: 3bInaF7Zeg9
--- a/devtools/shim/aboutdevtools/aboutdevtools.js
+++ b/devtools/shim/aboutdevtools/aboutdevtools.js
@@ -16,16 +16,17 @@ const MESSAGES = {
KeyShortcut: "key-shortcut-message",
SystemMenu: "menu-message",
};
// URL constructor doesn't support about: scheme,
// we have to use http in order to have working searchParams.
let url = new URL(window.location.href.replace("about:", "http://"));
let reason = url.searchParams.get("reason");
+let tabid = parseInt(url.searchParams.get("tabid"), 10);
function getToolboxShortcut() {
const bundleUrl = "chrome://devtools-shim/locale/key-shortcuts.properties";
const bundle = Services.strings.createBundle(bundleUrl);
const modifier = Services.appinfo.OS == "Darwin" ? "Cmd+Opt+" : "Ctrl+Shift+";
return modifier + bundle.GetStringFromName("toggleToolbox.commandkey");
}
@@ -70,13 +71,32 @@ window.addEventListener("load", function
let installButton = document.getElementById("install");
installButton.addEventListener("click", onInstallButtonClick);
// Update the current page based on the current value of DEVTOOLS_ENABLED_PREF.
updatePage();
}, { once: true });
+window.addEventListener("beforeunload", function () {
+ // Focus the tab that triggered the DevTools onboarding.
+ if (document.visibilityState != "visible") {
+ // Only try to focus the correct tab if the current tab is the about:devtools page.
+ return;
+ }
+
+ // Retrieve the original tab if it is still available.
+ let browserWindow = Services.wm.getMostRecentWindow("navigator:browser");
+ let { gBrowser } = browserWindow;
+ let originalBrowser = gBrowser.getBrowserForOuterWindowID(tabid);
+ let originalTab = gBrowser.getTabForBrowser(originalBrowser);
+
+ if (originalTab) {
+ // If the original tab was found, select it.
+ gBrowser.selectedTab = originalTab;
+ }
+}, {once: true});
+
window.addEventListener("unload", function () {
let installButton = document.getElementById("install");
installButton.removeEventListener("click", onInstallButtonClick);
Services.prefs.removeObserver(DEVTOOLS_ENABLED_PREF, updatePage);
}, {once: true});
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -524,18 +524,29 @@ DevToolsStartup.prototype = {
!location.startsWith("about:devtools-toolbox")) {
// Focus the existing about:devtools tab and bail out.
gBrowser.selectedTab = tab;
return;
}
}
let url = "about:devtools";
+
+ let params = [];
if (reason) {
- url += "?reason=" + encodeURIComponent(reason);
+ params.push("reason=" + encodeURIComponent(reason));
+ }
+
+ let selectedBrowser = gBrowser.selectedBrowser;
+ if (selectedBrowser) {
+ params.push("tabid=" + selectedBrowser.outerWindowID);
+ }
+
+ if (params.length > 0) {
+ url += "?" + params.join("&");
}
// Set relatedToCurrent: true to open the tab next to the current one.
gBrowser.selectedTab = gBrowser.addTab(url, {relatedToCurrent: true});
},
handleConsoleFlag: function (cmdLine) {
let window = Services.wm.getMostRecentWindow("devtools:webconsole");