Skip to content
Browse files
Inspector window goes into an inactive state when extension tab is se…

Reviewed by Devin Rousso.

* Source/WebInspectorUI/UserInterface/Base/Main.js:
(WI.contentLoaded): Update event listeners to use a single _updateWindowInactiveState
and listen to visibilitychange.
(WI._updateWindowInactiveState): Combined from WI._windowFocused and WI._windowBlurred.
Use document.hasFocus() to check for an active window, which works for child frames too.
When an iframe is the active element, we will not get any more focus or blur events for
the main window, so use a 250ms timeout to keep checking while the iframe is focused.

Canonical link:
git-svn-id: 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
xeenon committed Jun 17, 2022
1 parent 898d71c commit 43ca250a881e0a0c30ecd09493d5cf73f1a28ebe
Showing 1 changed file with 11 additions and 14 deletions.
@@ -215,8 +215,9 @@ WI.contentLoaded = function()
document.addEventListener("dragover", WI._handleDragOver);
document.addEventListener("focus", WI._focusChanged, true);

window.addEventListener("focus", WI._windowFocused);
window.addEventListener("blur", WI._windowBlurred);
window.addEventListener("focus", WI._updateWindowInactiveState);
window.addEventListener("blur", WI._updateWindowInactiveState);
window.addEventListener("visibilitychange", WI._updateWindowInactiveState);
window.addEventListener("resize", WI._windowResized);
window.addEventListener("keydown", WI._windowKeyDown);
window.addEventListener("keyup", WI._windowKeyUp);
@@ -1821,22 +1822,18 @@ WI._saveCookieForOpenTabs = function()

WI._windowFocused = function(event)
WI._updateWindowInactiveState = function(event)
if ( !== Node.DOCUMENT_NODE)

// FIXME: We should use the :window-inactive pseudo class once is fixed.
document.body.classList.remove(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive");

WI._windowBlurred = function(event)
if ( !== Node.DOCUMENT_NODE)
if (document.activeElement?.tagName === "IFRAME") {
// An active iframe means an extension tab is active and we can't tell when the window blurs due to cross-origin restrictions.
// In this case we need to keep checking to know if the window loses focus since there is no event we can use.
setTimeout(WI._updateWindowInactiveState, 250);

// FIXME: We should use the :window-inactive pseudo class once is fixed.
document.body.classList.add(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive");
let inactive = !document.hasFocus();
document.body.classList.toggle(WI.dockConfiguration === WI.DockConfiguration.Undocked ? "window-inactive" : "window-docked-inactive", inactive);

WI._windowResized = function(event)

0 comments on commit 43ca250

Please sign in to comment.