mirror of
https://github.com/User0332/rewards-farmer.git
synced 2026-09-16 01:31:36 +00:00
add better handling for ghost tab
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from selenium.common.exceptions import WebDriverException
|
||||
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"
|
||||
|
||||
class TabUtils:
|
||||
def __init__(self, driver: webdriver.Edge):
|
||||
@@ -13,6 +14,8 @@ class TabUtils:
|
||||
for handle in self.driver.window_handles:
|
||||
if handle != current_window and handle not in self.problematic_tabs:
|
||||
self.driver.switch_to.window(handle)
|
||||
|
||||
if self.driver.current_url == GHOST_TAB_URL: continue
|
||||
return
|
||||
|
||||
def close_all_other_tabs(self, exceptions: list[str] = None):
|
||||
@@ -24,6 +27,9 @@ class TabUtils:
|
||||
for handle in self.driver.window_handles:
|
||||
if handle not in exceptions and handle not in self.problematic_tabs:
|
||||
self.driver.switch_to.window(handle)
|
||||
|
||||
if self.driver.current_url == GHOST_TAB_URL: continue
|
||||
|
||||
try: self.driver.close()
|
||||
except WebDriverException:
|
||||
print(f"[WARNING] Could not close tab with handle {handle}.")
|
||||
|
||||
Reference in New Issue
Block a user