diff --git a/requirements.txt b/requirements.txt index e9c8f342e2f..8937da3e907 100755 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ pip>=25.0.1;python_version<"3.9" pip>=25.1;python_version>="3.9" packaging>=25.0 setuptools~=70.2;python_version<"3.10" -setuptools>=80.0.0;python_version>="3.10" +setuptools>=80.1.0;python_version>="3.10" wheel>=0.45.1 attrs>=25.3.0 certifi>=2025.4.26 diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index bea7b1e3230..5e17db8a265 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.37.10" +__version__ = "4.37.11" diff --git a/seleniumbase/core/browser_launcher.py b/seleniumbase/core/browser_launcher.py index c301734b015..a23496ba84c 100644 --- a/seleniumbase/core/browser_launcher.py +++ b/seleniumbase/core/browser_launcher.py @@ -519,6 +519,16 @@ def uc_open_with_cdp_mode(driver, url=None, **kwargs): import asyncio from seleniumbase.undetected.cdp_driver import cdp_util + if ( + hasattr(driver, "_is_using_cdp") + and driver._is_using_cdp + and hasattr(driver, "cdp") + and driver.cdp + ): + # CDP Mode was already initialized + driver.disconnect() + driver.cdp.open(url, **kwargs) + return current_url = None try: current_url = driver.current_url diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index 48cfb9d4d47..6d727227206 100644 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -3534,12 +3534,24 @@ def set_window_rect(self, x, y, width, height): def set_window_size(self, width, height): self.__check_scope() + if self.__is_cdp_swap_needed(): + position = self.cdp.get_window_position() + x = position["x"] + y = position["y"] + self.cdp.set_window_rect(x, y, width, height) + return self._check_browser() self.driver.set_window_size(width, height) self.__demo_mode_pause_if_active(tiny=True) def set_window_position(self, x, y): self.__check_scope() + if self.__is_cdp_swap_needed(): + size = self.cdp.get_window_size() + width = size["width"] + height = size["height"] + self.cdp.set_window_rect(x, y, width, height) + return self._check_browser() self.driver.set_window_position(x, y) self.__demo_mode_pause_if_active(tiny=True) diff --git a/seleniumbase/plugins/sb_manager.py b/seleniumbase/plugins/sb_manager.py index 330dbba387c..b56a8c585f9 100644 --- a/seleniumbase/plugins/sb_manager.py +++ b/seleniumbase/plugins/sb_manager.py @@ -1369,14 +1369,23 @@ def SB( "%s%s%s%s%s" % (c1, left_space, end_text, right_space, cr) ) - if undetectable and hasattr(sb, "_drivers_browser_map"): + python3_12_or_newer = (sys.version_info >= (3, 12)) + if undetectable: import asyncio - for driver in sb._drivers_browser_map.keys(): - if hasattr(driver, "cdp") and driver.cdp: - asyncio.set_event_loop(driver.cdp.loop) - tasks = [tab.aclose() for tab in driver.cdp.get_tabs()] - tasks.append(driver.cdp.driver.connection.aclose()) - driver.cdp.loop.run_until_complete(asyncio.gather(*tasks)) + if not python3_12_or_newer and hasattr(sb_config, "_cdp_aclose"): + with suppress(Exception): + loop = asyncio.get_event_loop() + asyncio.set_event_loop(loop) + loop.run_until_complete(sb_config._cdp_aclose()) + if python3_12_or_newer and hasattr(sb, "_drivers_browser_map"): + for driver in sb._drivers_browser_map.keys(): + if hasattr(driver, "cdp") and driver.cdp: + asyncio.set_event_loop(driver.cdp.loop) + tasks = [tab.aclose() for tab in driver.cdp.get_tabs()] + tasks.append(driver.cdp.driver.connection.aclose()) + driver.cdp.loop.run_until_complete( + asyncio.gather(*tasks) + ) driver.cdp.loop.close() gc.collect() if test and test_name and not test_passed and raise_test_failure: diff --git a/seleniumbase/undetected/__init__.py b/seleniumbase/undetected/__init__.py index 963790b4e33..8d4128cb1e3 100644 --- a/seleniumbase/undetected/__init__.py +++ b/seleniumbase/undetected/__init__.py @@ -523,9 +523,7 @@ def connect(self): with suppress(Exception): for window_handle in self.window_handles: self.switch_to.window(window_handle) - if self.current_url.startswith( - "chrome-extension://" - ): + if self.current_url.startswith("chrome-extension://"): # https://issues.chromium.org/issues/396611138 # (Remove the Linux conditional when resolved) # (So that close() is always called) diff --git a/seleniumbase/undetected/cdp_driver/connection.py b/seleniumbase/undetected/cdp_driver/connection.py index b3a91af3db9..5b146526691 100644 --- a/seleniumbase/undetected/cdp_driver/connection.py +++ b/seleniumbase/undetected/cdp_driver/connection.py @@ -19,6 +19,7 @@ ) import websockets from websockets.protocol import State +from seleniumbase import config as sb_config from . import cdp_util as util import mycdp as cdp import mycdp.network @@ -270,6 +271,7 @@ async def aopen(self, **kw): max_size=MAX_SIZE, ) self.listener = Listener(self) + sb_config._cdp_aclose = self.aclose except (Exception,) as e: logger.debug("Exception during opening of websocket: %s", e) if self.listener: @@ -444,6 +446,7 @@ async def send( if not _is_update: await self._register_handlers() await self.websocket.send(tx.message) + sb_config._cdp_aclose = self.aclose try: return await tx except ProtocolException as e: diff --git a/setup.py b/setup.py index d1f12df9ddb..32778b3fa40 100755 --- a/setup.py +++ b/setup.py @@ -151,7 +151,7 @@ 'pip>=25.1;python_version>="3.9"', 'packaging>=25.0', 'setuptools~=70.2;python_version<"3.10"', # Newer ones had issues - 'setuptools>=80.0.0;python_version>="3.10"', + 'setuptools>=80.1.0;python_version>="3.10"', 'wheel>=0.45.1', 'attrs>=25.3.0', "certifi>=2025.4.26",