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

Method connect

seleniumbase/undetected/__init__.py:538–580  ·  view source on GitHub ↗

Starts the chromedriver service that runs in the background and recreates the session.

(self)

Source from the content-addressed store, hash-verified

536 self._is_connected = False
537
538 def connect(self):
539 """Starts the chromedriver service that runs in the background
540 and recreates the session."""
541 if hasattr(self, "service"):
542 with suppress(Exception):
543 self.service.start()
544 with suppress(Exception):
545 already_quit = False
546 if hasattr(self, "_already_quit") and self._already_quit:
547 already_quit = True
548 if not already_quit:
549 self.start_session()
550 time.sleep(0.0075)
551 with suppress(Exception):
552 for window_handle in self.window_handles:
553 self.switch_to.window(window_handle)
554 current_url = None
555 if hasattr(self, "cdp") and hasattr(self.cdp, "driver"):
556 with suppress(Exception):
557 current_url = self.cdp.get_current_url()
558 if not current_url:
559 current_url = self.current_url
560 if current_url.startswith("chrome-extension://"):
561 # https://issues.chromium.org/issues/396611138
562 # (Remove the Linux conditional when resolved)
563 # (So that close() is always called)
564 if "linux" in sys.platform:
565 self.close()
566 if self.service.is_connectable():
567 self.stop_client()
568 try:
569 self.service.send_remote_shutdown_command()
570 except TypeError:
571 pass
572 finally:
573 with suppress(Exception):
574 self.service._terminate_process()
575 self.service.start()
576 self.start_session()
577 time.sleep(0.003)
578 with suppress(Exception):
579 self.switch_to.window(self.window_handles[-1])
580 self._is_connected = True
581
582 def start_session(self, capabilities=None):
583 if not capabilities:

Callers 14

get_local_driverFunction · 0.95
open_new_tabMethod · 0.80
__init__Method · 0.80
uc_execute_cdp_cmdFunction · 0.80
uc_open_with_disconnectFunction · 0.80
_uc_gui_handle_captcha_Function · 0.80
sendMethod · 0.80
aopenMethod · 0.80
activate_cdp_modeMethod · 0.80
assert_textMethod · 0.80

Calls 5

start_sessionMethod · 0.95
startMethod · 0.80
closeMethod · 0.80
sleepMethod · 0.45
get_current_urlMethod · 0.45

Tested by 1

test_presentation_4Method · 0.64