Skip to content

Fix Windows thread-locking bug in UC Mode #2890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion seleniumbase/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.28.2"
__version__ = "4.28.3"
2 changes: 1 addition & 1 deletion seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def uc_gui_handle_cf(driver, frame="iframe"):
if not is_in_frame:
# Make sure the window is on top
page_actions.switch_to_window(
driver, driver.current_window_handle, 2
driver, driver.current_window_handle, 2, uc_lock=False
)
if not is_in_frame or needs_switch:
# Currently not in frame (or nested frame outside CF one)
Expand Down
20 changes: 15 additions & 5 deletions seleniumbase/fixtures/page_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,8 +1430,12 @@ def switch_to_frame(driver, frame, timeout=settings.SMALL_TIMEOUT):
timeout_exception(Exception, message)


def __switch_to_window(driver, window_handle):
if hasattr(driver, "_is_using_uc") and driver._is_using_uc:
def __switch_to_window(driver, window_handle, uc_lock=True):
if (
hasattr(driver, "_is_using_uc")
and driver._is_using_uc
and uc_lock
):
gui_lock = fasteners.InterProcessLock(
constants.MultiBrowser.PYAUTOGUILOCK
)
Expand All @@ -1442,14 +1446,20 @@ def __switch_to_window(driver, window_handle):
return True


def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
def switch_to_window(
driver,
window,
timeout=settings.SMALL_TIMEOUT,
uc_lock=True,
):
"""
Wait for a window to appear, and switch to it. This should be usable
as a drop-in replacement for driver.switch_to.window().
@Params
driver - the webdriver object (required)
window - the window index or window handle
timeout - the time to wait for the window in seconds
uc_lock - if UC Mode and True, switch_to_window() uses thread-locking
"""
if window == -1:
window = len(driver.window_handles) - 1
Expand All @@ -1465,7 +1475,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
shared_utils.check_if_time_limit_exceeded()
try:
window_handle = driver.window_handles[window]
__switch_to_window(driver, window_handle)
__switch_to_window(driver, window_handle, uc_lock=uc_lock)
return True
except IndexError:
now_ms = time.time() * 1000.0
Expand All @@ -1486,7 +1496,7 @@ def switch_to_window(driver, window, timeout=settings.SMALL_TIMEOUT):
for x in range(int(timeout * 10)):
shared_utils.check_if_time_limit_exceeded()
try:
__switch_to_window(driver, window_handle)
__switch_to_window(driver, window_handle, uc_lock=uc_lock)
return True
except NoSuchWindowException:
now_ms = time.time() * 1000.0
Expand Down