Skip to content

Commit 5c8a94b

Browse files
committed
Improve UC Mode reliability
1 parent a14b74f commit 5c8a94b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from selenium import webdriver
1313
from selenium.common.exceptions import ElementClickInterceptedException
1414
from selenium.common.exceptions import InvalidSessionIdException
15+
from selenium.common.exceptions import SessionNotCreatedException
1516
from selenium.webdriver.chrome.service import Service as ChromeService
1617
from selenium.webdriver.common.options import ArgOptions
1718
from selenium.webdriver.common.service import utils as service_utils
@@ -4277,11 +4278,11 @@ def get_local_driver(
42774278
driver.quit()
42784279
except Exception:
42794280
pass
4281+
uc_path = None
4282+
if os.path.exists(LOCAL_UC_DRIVER):
4283+
uc_path = LOCAL_UC_DRIVER
4284+
uc_path = os.path.realpath(uc_path)
42804285
try:
4281-
uc_path = None
4282-
if os.path.exists(LOCAL_UC_DRIVER):
4283-
uc_path = LOCAL_UC_DRIVER
4284-
uc_path = os.path.realpath(uc_path)
42854286
driver = undetected.Chrome(
42864287
options=chrome_options,
42874288
user_data_dir=user_data_dir,
@@ -4298,6 +4299,19 @@ def get_local_driver(
42984299
mac_certificate_error = True
42994300
else:
43004301
raise
4302+
except SessionNotCreatedException:
4303+
time.sleep(0.2)
4304+
driver = undetected.Chrome(
4305+
options=chrome_options,
4306+
user_data_dir=user_data_dir,
4307+
driver_executable_path=uc_path,
4308+
browser_executable_path=b_path,
4309+
enable_cdp_events=cdp_events,
4310+
headless=False, # Xvfb needed!
4311+
version_main=uc_chrome_version,
4312+
use_subprocess=True, # Always!
4313+
)
4314+
uc_activated = True
43014315
if mac_certificate_error:
43024316
cf_lock_path = (
43034317
constants.MultiBrowser.CERT_FIXING_LOCK

0 commit comments

Comments
 (0)