ensure tabs always feign focus

This commit is contained in:
Carl Furtado
2026-08-20 10:35:35 -04:00
parent f392d3e7a3
commit a089b1f209
2 changed files with 15 additions and 0 deletions
+11
View File
@@ -8,6 +8,15 @@ class TabUtils:
self.driver = driver
self.problematic_tabs = set()
def ensure_focus(self):
self.driver.execute_script("""
Object.defineProperty(document, 'hidden', { get: () => false });
Object.defineProperty(document, 'visibilityState', { get: () => 'visible' });
Document.prototype.hasFocus = function() { return true; };
window.hasFocus = function() { return true; };
document.dispatchEvent(new Event('visibilitychange'));
""")
def switch_to_other_tab(self):
current_window = self.driver.current_window_handle
@@ -16,6 +25,8 @@ class TabUtils:
self.driver.switch_to.window(handle)
if self.driver.current_url == GHOST_TAB_URL: continue
self.ensure_focus()
return
def close_all_other_tabs(self, exceptions: list[str] = None):