1616from seleniumbase .fixtures import constants
1717from seleniumbase .fixtures import page_utils
1818from seleniumbase import drivers # webdriver storage folder for SeleniumBase
19+ from seleniumbase import extensions # browser extensions storage folder
1920DRIVER_DIR = os .path .dirname (os .path .realpath (drivers .__file__ ))
21+ EXTENSIONS_DIR = os .path .dirname (os .path .realpath (extensions .__file__ ))
22+ DISABLE_CSP_ZIP_PATH = "%s/%s" % (EXTENSIONS_DIR , "disable_csp.zip" )
2023PROXY_ZIP_PATH = proxy_helper .PROXY_ZIP_PATH
2124PROXY_ZIP_PATH_2 = proxy_helper .PROXY_ZIP_PATH_2
2225PLATFORM = sys .platform
@@ -82,6 +85,14 @@ def _add_chrome_proxy_extension(
8285 return chrome_options
8386
8487
88+ def _add_chrome_disable_csp_extension (chrome_options ):
89+ """ Disable Chrome's Content-Security-Policy with a browser extension.
90+ See https://github.com/PhilGrayson/chrome-csp-disable for details. """
91+ disable_csp_zip = DISABLE_CSP_ZIP_PATH
92+ chrome_options .add_extension (disable_csp_zip )
93+ return chrome_options
94+
95+
8596def _set_chrome_options (
8697 downloads_path , proxy_string , proxy_auth ,
8798 proxy_user , proxy_pass , user_agent ):
@@ -108,6 +119,8 @@ def _set_chrome_options(
108119 chrome_options .add_argument ("--disable-single-click-autofill" )
109120 chrome_options .add_argument ("--disable-translate" )
110121 chrome_options .add_argument ("--disable-web-security" )
122+ if settings .DISABLE_CONTENT_SECURITY_POLICY :
123+ chrome_options = _add_chrome_disable_csp_extension (chrome_options )
111124 if proxy_string :
112125 if proxy_auth :
113126 chrome_options = _add_chrome_proxy_extension (
@@ -135,7 +148,8 @@ def _create_firefox_profile(downloads_path, proxy_string, user_agent):
135148 profile .set_preference ("general.useragent.override" , user_agent )
136149 profile .set_preference (
137150 "security.mixed_content.block_active_content" , False )
138- profile .set_preference ("security.csp.enable" , False )
151+ if settings .DISABLE_CONTENT_SECURITY_POLICY :
152+ profile .set_preference ("security.csp.enable" , False )
139153 profile .set_preference (
140154 "browser.download.manager.showAlertOnComplete" , False )
141155 profile .set_preference ("browser.privatebrowsing.autostart" , True )
0 commit comments