From af2eb68940931baea4e34a51d57931f9fdf3bbf4 Mon Sep 17 00:00:00 2001 From: Carl Furtado Date: Thu, 20 Aug 2026 10:43:07 -0400 Subject: [PATCH] add exception handling for possible redefinition of document focus handlers --- src/main.py | 2 +- src/tab_utils.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index f60b021..2e18910 100644 --- a/src/main.py +++ b/src/main.py @@ -19,7 +19,7 @@ keyboard = mimic_typing.KeyboardUtils(driver) rewards = rewards_tasks.RewardsTaskUtils(driver) -rewards.complete_required_searches() +rewards.complete_all_tasks() input("Press Enter to exit...") diff --git a/src/tab_utils.py b/src/tab_utils.py index 84b0611..ebb49c0 100644 --- a/src/tab_utils.py +++ b/src/tab_utils.py @@ -1,4 +1,4 @@ -from selenium.common.exceptions import WebDriverException +from selenium.common.exceptions import WebDriverException, JavascriptException from selenium import webdriver GHOST_TAB_URL = "https://ntp.msn.com/edge/ntp?locale=en-US&title=New%20tab&fre=1&dsp=1&sp=Bing&feed_dis=always&en_widget_reg=false&prerender=1&PC=U531" @@ -9,13 +9,15 @@ class TabUtils: self.problematic_tabs = set() def ensure_focus(self): - self.driver.execute_script(""" + try: + 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')); """) + except JavascriptException: pass # it's probably a property redef exc def switch_to_other_tab(self): current_window = self.driver.current_window_handle