Skip to content

Commit 71032cf

Browse files
committed
Keep the Content Security Policy on headless Chrome
1 parent 2b09b8f commit 71032cf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _add_chrome_disable_csp_extension(chrome_options):
9494

9595

9696
def _set_chrome_options(
97-
downloads_path, proxy_string, proxy_auth,
97+
downloads_path, headless, proxy_string, proxy_auth,
9898
proxy_user, proxy_pass, user_agent):
9999
chrome_options = webdriver.ChromeOptions()
100100
prefs = {
@@ -119,7 +119,9 @@ def _set_chrome_options(
119119
chrome_options.add_argument("--disable-single-click-autofill")
120120
chrome_options.add_argument("--disable-translate")
121121
chrome_options.add_argument("--disable-web-security")
122-
if settings.DISABLE_CONTENT_SECURITY_POLICY:
122+
if settings.DISABLE_CONTENT_SECURITY_POLICY and not headless:
123+
# Headless Chrome doesn't support extensions, which are required
124+
# for disabling the Content Security Policy on Chrome
123125
chrome_options = _add_chrome_disable_csp_extension(chrome_options)
124126
if proxy_string:
125127
if proxy_auth:
@@ -261,7 +263,7 @@ def get_remote_driver(
261263
desired_caps = capabilities_parser.get_desired_capabilities(cap_file)
262264
if browser_name == constants.Browser.GOOGLE_CHROME:
263265
chrome_options = _set_chrome_options(
264-
downloads_path, proxy_string, proxy_auth,
266+
downloads_path, headless, proxy_string, proxy_auth,
265267
proxy_user, proxy_pass, user_agent)
266268
if headless:
267269
if not proxy_auth:
@@ -472,7 +474,7 @@ def get_local_driver(
472474
elif browser_name == constants.Browser.GOOGLE_CHROME:
473475
try:
474476
chrome_options = _set_chrome_options(
475-
downloads_path, proxy_string, proxy_auth,
477+
downloads_path, headless, proxy_string, proxy_auth,
476478
proxy_user, proxy_pass, user_agent)
477479
if headless:
478480
# Headless Chrome doesn't support extensions, which are

0 commit comments

Comments
 (0)