Merge pull request #3655 from seleniumbase/fix-cdp-mode-issues

Fix CDP Mode issues
This commit is contained in:
Michael Mintz 2025-04-07 16:30:39 -04:00 committed by GitHub
commit 990701d9ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 7 deletions

View File

@ -1,2 +1,2 @@
# seleniumbase package
__version__ = "4.37.0"
__version__ = "4.37.1"

View File

@ -4871,6 +4871,13 @@ class BaseCase(unittest.TestCase):
def activate_cdp_mode(self, url=None):
if hasattr(self.driver, "_is_using_uc") and self.driver._is_using_uc:
if self.__is_cdp_swap_needed():
return # CDP Mode is already active
if not self.is_connected():
self.driver.connect()
current_url = self.get_current_url()
if not current_url.startswith(("about", "data", "chrome")):
self.get_new_driver(undetectable=True)
self.driver.uc_open_with_cdp_mode(url)
else:
self.get_new_driver(undetectable=True)

View File

@ -441,7 +441,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
with suppress(Exception):
if self.service.is_connectable():
self.stop_client()
self.service.stop()
try:
self.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
self.service._terminate_process()
if isinstance(timeout, str):
if timeout.lower() == "breakpoint":
breakpoint() # To continue:
@ -466,7 +472,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
self.close()
if self.service.is_connectable():
self.stop_client()
self.service.stop()
try:
self.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
self.service._terminate_process()
self.service.start()
self.start_session()
time.sleep(0.003)
@ -482,7 +494,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
if self.service.is_connectable():
self.stop_client()
time.sleep(0.003)
self.service.stop()
try:
self.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
self.service._terminate_process()
self._is_connected = False
def connect(self):
@ -507,7 +525,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
self.close()
if self.service.is_connectable():
self.stop_client()
self.service.stop()
try:
self.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
self.service._terminate_process()
self.service.start()
self.start_session()
time.sleep(0.003)
@ -539,7 +563,13 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
logger.debug("Stopping webdriver service")
with suppress(Exception):
self.stop_client()
self.service.stop()
try:
self.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
self.service._terminate_process()
with suppress(Exception):
if self.reactor and isinstance(self.reactor, Reactor):
logger.debug("Shutting down Reactor")

View File

@ -406,7 +406,13 @@ async def create_from_driver(driver) -> Browser:
browser = await start(conf)
browser._process_pid = driver.browser_pid
# Stop chromedriver binary
driver.service.stop()
try:
driver.service.send_remote_shutdown_command()
except TypeError:
pass
finally:
with suppress(Exception):
driver.service._terminate_process()
driver.browser_pid = -1
driver.user_data_dir = None
return browser