mirror of
https://github.com/User0332/rewards-farmer.git
synced 2026-09-16 09:31:36 +00:00
ensure tabs always feign focus
This commit is contained in:
@@ -21,6 +21,8 @@ class RewardsTaskUtils:
|
|||||||
self.driver.get("https://rewards.bing.com/")
|
self.driver.get("https://rewards.bing.com/")
|
||||||
|
|
||||||
self.tab_utils = tab_utils.TabUtils(driver)
|
self.tab_utils = tab_utils.TabUtils(driver)
|
||||||
|
self.tab_utils.ensure_focus()
|
||||||
|
|
||||||
self.mouse = mouse_trajectory.MouseUtils(driver)
|
self.mouse = mouse_trajectory.MouseUtils(driver)
|
||||||
self.keyboard = mimic_typing.KeyboardUtils(driver)
|
self.keyboard = mimic_typing.KeyboardUtils(driver)
|
||||||
self.elements = element_selectors.ElementSelectionUtils(driver)
|
self.elements = element_selectors.ElementSelectionUtils(driver)
|
||||||
@@ -150,6 +152,7 @@ class RewardsTaskUtils:
|
|||||||
searches_needed = (max_pts - points_earned) // 5
|
searches_needed = (max_pts - points_earned) // 5
|
||||||
|
|
||||||
self.driver.get("https://www.bing.com/")
|
self.driver.get("https://www.bing.com/")
|
||||||
|
self.tab_utils.ensure_focus()
|
||||||
|
|
||||||
self.wait_for_element(self.elements.get_bing_search_bar)
|
self.wait_for_element(self.elements.get_bing_search_bar)
|
||||||
|
|
||||||
@@ -167,6 +170,7 @@ class RewardsTaskUtils:
|
|||||||
self.move_to_and_click(self.elements.get_clear_bing_search_query_button())
|
self.move_to_and_click(self.elements.get_clear_bing_search_query_button())
|
||||||
|
|
||||||
self.driver.get("https://rewards.bing.com/")
|
self.driver.get("https://rewards.bing.com/")
|
||||||
|
self.tab_utils.ensure_focus()
|
||||||
|
|
||||||
self.switch_to_earn_page()
|
self.switch_to_earn_page()
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,15 @@ class TabUtils:
|
|||||||
self.driver = driver
|
self.driver = driver
|
||||||
self.problematic_tabs = set()
|
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):
|
def switch_to_other_tab(self):
|
||||||
current_window = self.driver.current_window_handle
|
current_window = self.driver.current_window_handle
|
||||||
|
|
||||||
@@ -16,6 +25,8 @@ class TabUtils:
|
|||||||
self.driver.switch_to.window(handle)
|
self.driver.switch_to.window(handle)
|
||||||
|
|
||||||
if self.driver.current_url == GHOST_TAB_URL: continue
|
if self.driver.current_url == GHOST_TAB_URL: continue
|
||||||
|
|
||||||
|
self.ensure_focus()
|
||||||
return
|
return
|
||||||
|
|
||||||
def close_all_other_tabs(self, exceptions: list[str] = None):
|
def close_all_other_tabs(self, exceptions: list[str] = None):
|
||||||
|
|||||||
Reference in New Issue
Block a user