Fix CDP Mode issues
This commit is contained in:
parent
004f22ffbd
commit
a68f33ce0d
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue