MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / uc_open_with_reconnect

Function uc_open_with_reconnect

seleniumbase/core/browser_launcher.py:589–636  ·  view source on GitHub ↗

Open a url, disconnect chromedriver, wait, and reconnect.

(driver, url, reconnect_time=None)

Source from the content-addressed store, hash-verified

587
588
589def uc_open_with_reconnect(driver, url, reconnect_time=None):
590 """Open a url, disconnect chromedriver, wait, and reconnect."""
591 if (
592 hasattr(sb_config, "_cdp_browser")
593 and sb_config._cdp_browser in ["comet", "opera", "atlas"]
594 ):
595 if not __is_cdp_swap_needed(driver):
596 if not driver.current_url.startswith(
597 ("about", "data", "chrome")
598 ):
599 driver.get("about:blank")
600 uc_activate_cdp_mode(driver, url)
601 else:
602 driver.cdp.open(url)
603 return
604 url = shared_utils.fix_url_as_needed(url)
605 if __is_cdp_swap_needed(driver):
606 driver.cdp.get(url)
607 time.sleep(0.3)
608 return
609 if not reconnect_time:
610 reconnect_time = constants.UC.RECONNECT_TIME
611 if (url.startswith("http:") or url.startswith("https:")):
612 script = 'window.open("%s","_blank");' % url
613 if not hasattr(driver, "cdp_base"):
614 driver.execute_script(script)
615 time.sleep(0.05)
616 driver.close()
617 else:
618 driver.cdp.open(url)
619 if reconnect_time == "disconnect":
620 driver.disconnect()
621 time.sleep(0.008)
622 else:
623 driver.reconnect(reconnect_time)
624 time.sleep(0.004)
625 try:
626 page_actions.switch_to_window(
627 driver, driver.window_handles[-1], 2
628 )
629 except InvalidSessionIdException:
630 time.sleep(0.05)
631 page_actions.switch_to_window(
632 driver, driver.window_handles[-1], 2
633 )
634 else:
635 driver.default_get(url) # The original one
636 return None
637
638
639def uc_open_with_cdp_mode(driver, url=None, **kwargs):

Callers 1

get_local_driverFunction · 0.85

Calls 10

uc_activate_cdp_modeFunction · 0.85
closeMethod · 0.80
disconnectMethod · 0.80
reconnectMethod · 0.80
__is_cdp_swap_neededFunction · 0.70
getMethod · 0.45
openMethod · 0.45
sleepMethod · 0.45
execute_scriptMethod · 0.45
switch_to_windowMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…