Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 990701d

Browse files
authored
Merge pull request #3655 from seleniumbase/fix-cdp-mode-issues
Fix CDP Mode issues
2 parents 004f22f + 79e38de commit 990701d

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

‎seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.37.0"
2+
__version__ = "4.37.1"

‎seleniumbase/fixtures/base_case.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4871,6 +4871,13 @@ def deactivate_design_mode(self, url=None):
48714871

48724872
def activate_cdp_mode(self, url=None):
48734873
if hasattr(self.driver, "_is_using_uc") and self.driver._is_using_uc:
4874+
if self.__is_cdp_swap_needed():
4875+
return # CDP Mode is already active
4876+
if not self.is_connected():
4877+
self.driver.connect()
4878+
current_url = self.get_current_url()
4879+
if not current_url.startswith(("about", "data", "chrome")):
4880+
self.get_new_driver(undetectable=True)
48744881
self.driver.uc_open_with_cdp_mode(url)
48754882
else:
48764883
self.get_new_driver(undetectable=True)

‎seleniumbase/undetected/__init__.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,13 @@ def reconnect(self, timeout=0.1):
441441
with suppress(Exception):
442442
if self.service.is_connectable():
443443
self.stop_client()
444-
self.service.stop()
444+
try:
445+
self.service.send_remote_shutdown_command()
446+
except TypeError:
447+
pass
448+
finally:
449+
with suppress(Exception):
450+
self.service._terminate_process()
445451
if isinstance(timeout, str):
446452
if timeout.lower() == "breakpoint":
447453
breakpoint() # To continue:
@@ -466,7 +472,13 @@ def reconnect(self, timeout=0.1):
466472
self.close()
467473
if self.service.is_connectable():
468474
self.stop_client()
469-
self.service.stop()
475+
try:
476+
self.service.send_remote_shutdown_command()
477+
except TypeError:
478+
pass
479+
finally:
480+
with suppress(Exception):
481+
self.service._terminate_process()
470482
self.service.start()
471483
self.start_session()
472484
time.sleep(0.003)
@@ -482,7 +494,13 @@ def disconnect(self):
482494
if self.service.is_connectable():
483495
self.stop_client()
484496
time.sleep(0.003)
485-
self.service.stop()
497+
try:
498+
self.service.send_remote_shutdown_command()
499+
except TypeError:
500+
pass
501+
finally:
502+
with suppress(Exception):
503+
self.service._terminate_process()
486504
self._is_connected = False
487505

488506
def connect(self):
@@ -507,7 +525,13 @@ def connect(self):
507525
self.close()
508526
if self.service.is_connectable():
509527
self.stop_client()
510-
self.service.stop()
528+
try:
529+
self.service.send_remote_shutdown_command()
530+
except TypeError:
531+
pass
532+
finally:
533+
with suppress(Exception):
534+
self.service._terminate_process()
511535
self.service.start()
512536
self.start_session()
513537
time.sleep(0.003)
@@ -539,7 +563,13 @@ def quit(self):
539563
logger.debug("Stopping webdriver service")
540564
with suppress(Exception):
541565
self.stop_client()
542-
self.service.stop()
566+
try:
567+
self.service.send_remote_shutdown_command()
568+
except TypeError:
569+
pass
570+
finally:
571+
with suppress(Exception):
572+
self.service._terminate_process()
543573
with suppress(Exception):
544574
if self.reactor and isinstance(self.reactor, Reactor):
545575
logger.debug("Shutting down Reactor")

‎seleniumbase/undetected/cdp_driver/cdp_util.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,13 @@ async def create_from_driver(driver) -> Browser:
406406
browser = await start(conf)
407407
browser._process_pid = driver.browser_pid
408408
# Stop chromedriver binary
409-
driver.service.stop()
409+
try:
410+
driver.service.send_remote_shutdown_command()
411+
except TypeError:
412+
pass
413+
finally:
414+
with suppress(Exception):
415+
driver.service._terminate_process()
410416
driver.browser_pid = -1
411417
driver.user_data_dir = None
412418
return browser

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /