Skip to content

Commit 90ce85a

Browse files
committed
Add support for beta builds of Chromium
1 parent 0e9afde commit 90ce85a

File tree

1 file changed

+136
-17
lines changed

1 file changed

+136
-17
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 136 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ def make_driver_executable_if_not(driver_path):
9090
make_executable(driver_path)
9191

9292

93+
def requests_get(url):
94+
import requests
95+
96+
response = None
97+
try:
98+
response = requests.get(url)
99+
except Exception:
100+
# Prevent SSLCertVerificationError / CERTIFICATE_VERIFY_FAILED
101+
url = url.replace("https://", "http://")
102+
response = requests.get(url)
103+
return response
104+
105+
106+
def get_latest_chromedriver_version():
107+
last = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
108+
url_request = requests_get(last)
109+
if url_request.ok:
110+
return url_request.text
111+
else:
112+
return None
113+
114+
93115
def chromedriver_on_path():
94116
paths = os.environ["PATH"].split(os.pathsep)
95117
for path in paths:
@@ -2101,15 +2123,23 @@ def get_local_driver(
21012123
constants.MultiBrowser.DRIVER_FIXING_LOCK
21022124
)
21032125
with edgedriver_fixing_lock:
2126+
try:
2127+
if not _was_driver_repaired():
2128+
_repair_edgedriver(edge_version)
2129+
_mark_driver_repaired()
2130+
except Exception:
2131+
pass
2132+
else:
2133+
try:
21042134
if not _was_driver_repaired():
21052135
_repair_edgedriver(edge_version)
2106-
_mark_driver_repaired()
2107-
else:
2108-
if not _was_driver_repaired():
2109-
_repair_edgedriver(edge_version)
2110-
_mark_driver_repaired()
2136+
_mark_driver_repaired()
2137+
except Exception:
2138+
pass
21112139
service = EdgeService(
2112-
executable_path=LOCAL_EDGEDRIVER, log_path=os.devnull
2140+
executable_path=LOCAL_EDGEDRIVER,
2141+
log_path=os.devnull,
2142+
service_args=["--disable-build-check"],
21132143
)
21142144
driver = Edge(service=service, options=edge_options)
21152145
return driver
@@ -2169,6 +2199,7 @@ def get_local_driver(
21692199
driver = Edge(
21702200
executable_path=LOCAL_EDGEDRIVER,
21712201
service_log_path=os.devnull,
2202+
service_args=["--disable-build-check"],
21722203
capabilities=capabilities,
21732204
)
21742205
return driver
@@ -2346,6 +2377,7 @@ def get_local_driver(
23462377
driver_version = output
23472378
except Exception:
23482379
pass
2380+
disable_build_check = False
23492381
if (
23502382
LOCAL_CHROMEDRIVER
23512383
and os.path.exists(LOCAL_CHROMEDRIVER)
@@ -2385,7 +2417,32 @@ def get_local_driver(
23852417
msg = "chromedriver not found. Getting it now:"
23862418

23872419
print("\nWarning: %s" % msg)
2388-
sb_install.main(override="chromedriver %s" % use_version)
2420+
try:
2421+
sb_install.main(
2422+
override="chromedriver %s" % use_version
2423+
)
2424+
except Exception:
2425+
d_latest = get_latest_chromedriver_version()
2426+
if (
2427+
d_latest
2428+
and use_version != "latest"
2429+
and int(use_version) > int(d_latest.split(".")[0])
2430+
):
2431+
disable_build_check = True
2432+
d_latest_major = d_latest.split(".")[0]
2433+
if (
2434+
not path_chromedriver
2435+
or (
2436+
driver_version
2437+
and (
2438+
int(driver_version)
2439+
< int(d_latest_major)
2440+
)
2441+
)
2442+
):
2443+
sb_install.main(
2444+
override="chromedriver latest"
2445+
)
23892446
sys.argv = sys_args # Put back the original sys args
23902447
else:
23912448
chromedriver_fixing_lock = fasteners.InterProcessLock(
@@ -2396,10 +2453,39 @@ def get_local_driver(
23962453
sys_args = sys.argv # Save a copy of sys args
23972454
msg = "chromedriver not found. Getting it now:"
23982455
print("\nWarning: %s" % msg)
2399-
sb_install.main(
2400-
override="chromedriver %s" % use_version
2401-
)
2456+
try:
2457+
sb_install.main(
2458+
override="chromedriver %s" % use_version
2459+
)
2460+
except Exception:
2461+
d_latest = get_latest_chromedriver_version()
2462+
if (
2463+
d_latest
2464+
and use_version != "latest"
2465+
and (
2466+
int(use_version)
2467+
> int(d_latest.split(".")[0])
2468+
)
2469+
):
2470+
disable_build_check = True
2471+
d_latest_major = d_latest.split(".")[0]
2472+
if (
2473+
not path_chromedriver
2474+
or (
2475+
driver_version
2476+
and (
2477+
int(driver_version)
2478+
< int(d_latest_major)
2479+
)
2480+
)
2481+
):
2482+
sb_install.main(
2483+
override="chromedriver latest"
2484+
)
24022485
sys.argv = sys_args # Put back original sys args
2486+
service_args = []
2487+
if disable_build_check:
2488+
service_args = ["--disable-build-check"]
24032489
if is_using_uc(undetectable, browser_name):
24042490
uc_lock = fasteners.InterProcessLock(
24052491
constants.MultiBrowser.DRIVER_FIXING_LOCK
@@ -2474,7 +2560,7 @@ def get_local_driver(
24742560
uc_lock = fasteners.InterProcessLock(
24752561
constants.MultiBrowser.DRIVER_FIXING_LOCK
24762562
)
2477-
with uc_lock: # No UC multithreaded tests
2563+
with uc_lock:
24782564
try:
24792565
uc_path = None
24802566
if os.path.exists(LOCAL_UC_DRIVER):
@@ -2510,6 +2596,7 @@ def get_local_driver(
25102596
service = ChromeService(
25112597
executable_path=LOCAL_CHROMEDRIVER,
25122598
log_path=os.devnull,
2599+
service_args=service_args,
25132600
)
25142601
driver = webdriver.Chrome(
25152602
service=service,
@@ -2519,18 +2606,24 @@ def get_local_driver(
25192606
driver = webdriver.Chrome(
25202607
executable_path=LOCAL_CHROMEDRIVER,
25212608
service_log_path=os.devnull,
2609+
service_args=service_args,
25222610
options=chrome_options,
25232611
)
25242612
else:
25252613
if selenium4_or_newer:
2526-
service = ChromeService(log_path=os.devnull)
2614+
service = ChromeService(
2615+
log_path=os.devnull,
2616+
service_args=service_args,
2617+
)
25272618
driver = webdriver.Chrome(
2528-
service=service, options=chrome_options
2619+
service=service,
2620+
options=chrome_options,
25292621
)
25302622
else:
25312623
driver = webdriver.Chrome(
2532-
options=chrome_options,
25332624
service_log_path=os.devnull,
2625+
service_args=service_args,
2626+
options=chrome_options,
25342627
)
25352628
except Exception as e:
25362629
if not hasattr(e, "msg"):
@@ -2629,7 +2722,8 @@ def get_local_driver(
26292722
if os.path.exists(LOCAL_CHROMEDRIVER):
26302723
if selenium4_or_newer:
26312724
service = ChromeService(
2632-
executable_path=LOCAL_CHROMEDRIVER
2725+
executable_path=LOCAL_CHROMEDRIVER,
2726+
service_args=["--disable-build-check"],
26332727
)
26342728
driver = webdriver.Chrome(
26352729
service=service,
@@ -2638,10 +2732,23 @@ def get_local_driver(
26382732
else:
26392733
driver = webdriver.Chrome(
26402734
executable_path=LOCAL_CHROMEDRIVER,
2735+
service_args=["--disable-build-check"],
26412736
options=chrome_options,
26422737
)
26432738
else:
2644-
driver = webdriver.Chrome(options=chrome_options)
2739+
if selenium4_or_newer:
2740+
service = ChromeService(
2741+
service_args=["--disable-build-check"],
2742+
)
2743+
driver = webdriver.Chrome(
2744+
service=service,
2745+
options=chrome_options,
2746+
)
2747+
else:
2748+
driver = webdriver.Chrome(
2749+
service_args=["--disable-build-check"],
2750+
options=chrome_options,
2751+
)
26452752
return driver
26462753
else: # Running headless on Linux (and not using --uc)
26472754
try:
@@ -2702,7 +2809,19 @@ def get_local_driver(
27022809
pass
27032810
_mark_driver_repaired()
27042811
try:
2705-
return webdriver.Chrome(options=chrome_options)
2812+
if selenium4_or_newer:
2813+
service = ChromeService(
2814+
service_args=["--disable-build-check"],
2815+
)
2816+
return webdriver.Chrome(
2817+
service=service,
2818+
options=chrome_options,
2819+
)
2820+
else:
2821+
return webdriver.Chrome(
2822+
service_args=["--disable-build-check"],
2823+
options=chrome_options,
2824+
)
27062825
except Exception:
27072826
pass
27082827
# Use the virtual display on Linux during headless errors

0 commit comments

Comments
 (0)