Skip to content

Commit 3e698b6

Browse files
committed
Combine duplicate code from two places into one
1 parent 2915b60 commit 3e698b6

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ def _set_chrome_options(
129129
chrome_options = _add_chrome_proxy_extension(
130130
chrome_options, proxy_string, proxy_user, proxy_pass)
131131
chrome_options.add_argument('--proxy-server=%s' % proxy_string)
132+
if headless:
133+
if not proxy_auth:
134+
# Headless Chrome doesn't support extensions, which are
135+
# required when using a proxy server that has authentication.
136+
# Instead, base_case.py will use PyVirtualDisplay when not
137+
# using Chrome's built-in headless mode. See link for details:
138+
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
139+
chrome_options.add_argument("--headless")
140+
chrome_options.add_argument("--disable-gpu")
141+
chrome_options.add_argument("--no-sandbox")
132142
return chrome_options
133143

134144

@@ -280,16 +290,6 @@ def get_remote_driver(
280290
chrome_options = _set_chrome_options(
281291
downloads_path, headless, proxy_string, proxy_auth,
282292
proxy_user, proxy_pass, user_agent, disable_csp)
283-
if headless:
284-
if not proxy_auth:
285-
# Headless Chrome doesn't support extensions, which are
286-
# required when using a proxy server that has authentication.
287-
# Instead, base_case.py will use PyVirtualDisplay when not
288-
# using Chrome's built-in headless mode. See link for details:
289-
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
290-
chrome_options.add_argument("--headless")
291-
chrome_options.add_argument("--disable-gpu")
292-
chrome_options.add_argument("--no-sandbox")
293293
capabilities = chrome_options.to_capabilities()
294294
for key in desired_caps.keys():
295295
capabilities[key] = desired_caps[key]
@@ -491,16 +491,6 @@ def get_local_driver(
491491
chrome_options = _set_chrome_options(
492492
downloads_path, headless, proxy_string, proxy_auth,
493493
proxy_user, proxy_pass, user_agent, disable_csp)
494-
if headless:
495-
# Headless Chrome doesn't support extensions, which are
496-
# required when using a proxy server that has authentication.
497-
# Instead, base_case.py will use PyVirtualDisplay when not
498-
# using Chrome's built-in headless mode. See link for details:
499-
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
500-
if not proxy_auth:
501-
chrome_options.add_argument("--headless")
502-
chrome_options.add_argument("--disable-gpu")
503-
chrome_options.add_argument("--no-sandbox")
504494
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
505495
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
506496
return webdriver.Chrome(

0 commit comments

Comments
 (0)