Skip to content

Commit 7c924ac

Browse files
committed
Update UC Mode / CDP Mode
1 parent c92181b commit 7c924ac

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,6 @@ def uc_open_with_cdp_mode(driver, url=None):
525525
js_utils.call_me_later(driver, script, 3)
526526
time.sleep(0.012)
527527
driver.close()
528-
driver.clear_cdp_listeners()
529-
driver.delete_all_cookies()
530-
driver.delete_network_conditions()
531528
driver.disconnect()
532529

533530
cdp_details = driver._get_cdp_details()
@@ -546,6 +543,7 @@ def uc_open_with_cdp_mode(driver, url=None):
546543
cdp_util.start(host=cdp_host, port=cdp_port)
547544
)
548545
page = loop.run_until_complete(driver.cdp_base.get(url))
546+
loop.run_until_complete(page.activate())
549547
if not safe_url:
550548
time.sleep(constants.UC.CDP_MODE_OPEN_WAIT)
551549
cdp = types.SimpleNamespace()

seleniumbase/undetected/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ def __init__(
133133
options = ChromeOptions()
134134
try:
135135
if hasattr(options, "_session") and options._session is not None:
136-
# Prevent reuse of options
137-
raise RuntimeError("You cannot reuse the ChromeOptions object")
136+
# Prevent reuse of options.
137+
# (Probably a port overlap. Quit existing driver and continue.)
138+
logger.debug("You cannot reuse the ChromeOptions object")
139+
with suppress(Exception):
140+
options._session.quit()
138141
except AttributeError:
139142
pass
140143
options._session = self

seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ async def start(
3737
Helper function to launch a browser. It accepts several keyword parameters.
3838
Conveniently, you can just call it bare (no parameters) to quickly launch
3939
an instance with best practice defaults.
40+
Note: Due to a Chrome-130 bug, use start_async or start_sync instead.
41+
(Calling this method directly could lead to an unresponsive browser)
4042
Note: New args are expected: Use kwargs only!
4143
Note: This should be called ``await start()``
4244
:param user_data_dir:
@@ -88,6 +90,20 @@ async def start(
8890
return await Browser.create(config)
8991

9092

93+
async def start_async(*args, **kwargs) -> Browser:
94+
headless = False
95+
if "headless" in kwargs:
96+
headless = kwargs["headless"]
97+
decoy_args = kwargs
98+
decoy_args["headless"] = True
99+
driver = await start(**decoy_args)
100+
kwargs["headless"] = headless
101+
kwargs["user_data_dir"] = driver.config.user_data_dir
102+
driver.stop() # Due to Chrome-130, must stop & start
103+
time.sleep(0.15)
104+
return await start(*args, **kwargs)
105+
106+
91107
def start_sync(*args, **kwargs) -> Browser:
92108
loop = asyncio.get_event_loop()
93109
headless = False

0 commit comments

Comments
 (0)