diff --git a/devtools/client/webconsole/hudservice.js b/devtools/client/webconsole/hudservice.js index 34828bc629af..3dd2f1385354 100644 --- a/devtools/client/webconsole/hudservice.js +++ b/devtools/client/webconsole/hudservice.js @@ -12,6 +12,7 @@ var WebConsoleUtils = require("devtools/shared/webconsole/utils").Utils; var Heritage = require("sdk/core/heritage"); var {TargetFactory} = require("devtools/client/framework/target"); var {Tools} = require("devtools/client/definitions"); +const { Task } = require("resource://gre/modules/Task.jsm"); var promise = require("promise"); loader.lazyImporter(this, "Services", "resource://gre/modules/Services.jsm"); @@ -587,10 +588,9 @@ WebConsole.prototype = { } } - let onDestroy = function WC_onDestroyUI() { + let onDestroy = Task.async(function*() { try { - let tabWindow = this.target.isLocalTab ? this.target.window : null; - tabWindow && tabWindow.focus(); + yield this.target.activeTab.focus() } catch (ex) { // Tab focus can fail if the tab or target is closed. @@ -599,7 +599,7 @@ WebConsole.prototype = { let id = WebConsoleUtils.supportsString(this.hudId); Services.obs.notifyObservers(id, "web-console-destroyed", null); this._destroyer.resolve(null); - }.bind(this); + }.bind(this)); if (this.ui) { this.ui.destroy().then(onDestroy); diff --git a/devtools/server/actors/webbrowser.js b/devtools/server/actors/webbrowser.js index 8d309eaed515..196ea8c67572 100644 --- a/devtools/server/actors/webbrowser.js +++ b/devtools/server/actors/webbrowser.js @@ -1399,6 +1399,16 @@ TabActor.prototype = { return { type: "detached" }; }, + /** + * Bring the tab's window to front. + */ + onFocus: function() { + if (this.window) { + this.window.focus(); + } + return {}; + }, + /** * Reload the page in this tab. */ @@ -1900,6 +1910,7 @@ TabActor.prototype = { TabActor.prototype.requestTypes = { "attach": TabActor.prototype.onAttach, "detach": TabActor.prototype.onDetach, + "focus": TabActor.prototype.onFocus, "reload": TabActor.prototype.onReload, "navigateTo": TabActor.prototype.onNavigateTo, "reconfigure": TabActor.prototype.onReconfigure, diff --git a/devtools/shared/client/main.js b/devtools/shared/client/main.js index bad301d38056..03fbda5d9339 100644 --- a/devtools/shared/client/main.js +++ b/devtools/shared/client/main.js @@ -1315,6 +1315,13 @@ TabClient.prototype = { telemetry: "TABDETACH" }), + /** + * Bring the window to the front. + */ + focus: DebuggerClient.requester({ + type: "focus" + }, {}), + /** * Reload the page in this tab. *