Skip to content

Commit 91ec281

Browse files
committed
Refactoring options ordering
1 parent ab6931d commit 91ec281

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ def _set_chrome_options(
505505
"--disable-blink-features=AutomationControlled"
506506
)
507507
chrome_options.add_experimental_option("useAutomationExtension", False)
508+
if headless:
509+
chrome_options.add_argument("--headless")
508510
if (settings.DISABLE_CSP_ON_CHROME or disable_csp) and not headless:
509511
# Headless Chrome does not support extensions, which are required
510512
# for disabling the Content Security Policy on Chrome.
@@ -556,16 +558,6 @@ def _set_chrome_options(
556558
chrome_options, None, proxy_user, proxy_pass, zip_it
557559
)
558560
chrome_options.add_argument("--proxy-pac-url=%s" % proxy_pac_url)
559-
if headless:
560-
if not proxy_auth and not browser_name == constants.Browser.OPERA:
561-
# Headless Chrome doesn't support extensions, which are
562-
# required when using a proxy server that has authentication.
563-
# Instead, base_case.py will use PyVirtualDisplay when not
564-
# using Chrome's built-in headless mode. See link for details:
565-
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
566-
# Also, Opera Chromium doesn't support headless mode:
567-
# https://github.com/operasoftware/operachromiumdriver/issues/62
568-
chrome_options.add_argument("--headless")
569561
if browser_name != constants.Browser.OPERA:
570562
# Opera Chromium doesn't support these switches
571563
chrome_options.add_argument("--ignore-certificate-errors")
@@ -951,6 +943,20 @@ def get_driver(
951943
raise Exception('The proxy PAC URL must end with ".pac"!')
952944
if proxy_pac_url and proxy_user and proxy_pass:
953945
proxy_auth = True
946+
if (
947+
headless
948+
and proxy_auth
949+
and (
950+
browser_name == constants.Browser.GOOGLE_CHROME
951+
or browser_name == constants.Browser.EDGE
952+
)
953+
):
954+
# Headless Chrome/Edge doesn't support extensions, which are
955+
# required when using a proxy server that has authentication.
956+
# Instead, base_case.py will use the SBVirtualDisplay when not
957+
# using Chrome's built-in headless mode. See link for details:
958+
# https://bugs.chromium.org/p/chromium/issues/detail?id=706008
959+
headless = False
954960
if (
955961
browser_name == constants.Browser.GOOGLE_CHROME
956962
and user_data_dir
@@ -2148,6 +2154,9 @@ def get_local_driver(
21482154
"\nWarning: Could not make operadriver"
21492155
" executable: %s" % e
21502156
)
2157+
# Opera Chromium doesn't support headless mode.
2158+
# https://github.com/operasoftware/operachromiumdriver/issues/62
2159+
headless = False
21512160
opera_options = _set_chrome_options(
21522161
browser_name,
21532162
downloads_path,
@@ -2192,6 +2201,7 @@ def get_local_driver(
21922201
warnings.simplefilter("ignore", category=DeprecationWarning)
21932202
return webdriver.Opera(options=opera_options)
21942203
except Exception:
2204+
# Opera support was dropped! Downgrade to Python 3.6 to use it!
21952205
return webdriver.Opera()
21962206
elif browser_name == constants.Browser.PHANTOM_JS:
21972207
if selenium4_or_newer:

0 commit comments

Comments
 (0)