Skip to content

CDP Mode: Patch 46 #3717

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 3 commits into from
Apr 30, 2025
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 requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.37.10"
__version__ = "4.37.11"
10 changes: 10 additions & 0 deletions seleniumbase/core/browser_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions seleniumbase/fixtures/base_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions seleniumbase/plugins/sb_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions seleniumbase/undetected/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions seleniumbase/undetected/cdp_driver/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down