16
16
from seleniumbase .fixtures import constants
17
17
from seleniumbase .fixtures import page_utils
18
18
from seleniumbase import drivers # webdriver storage folder for SeleniumBase
19
+ from seleniumbase import extensions # browser extensions storage folder
19
20
DRIVER_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" )
20
23
PROXY_ZIP_PATH = proxy_helper .PROXY_ZIP_PATH
21
24
PROXY_ZIP_PATH_2 = proxy_helper .PROXY_ZIP_PATH_2
22
25
PLATFORM = sys .platform
@@ -82,6 +85,14 @@ def _add_chrome_proxy_extension(
82
85
return chrome_options
83
86
84
87
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
+
85
96
def _set_chrome_options (
86
97
downloads_path , proxy_string , proxy_auth ,
87
98
proxy_user , proxy_pass , user_agent ):
@@ -108,6 +119,8 @@ def _set_chrome_options(
108
119
chrome_options .add_argument ("--disable-single-click-autofill" )
109
120
chrome_options .add_argument ("--disable-translate" )
110
121
chrome_options .add_argument ("--disable-web-security" )
122
+ if settings .DISABLE_CONTENT_SECURITY_POLICY :
123
+ chrome_options = _add_chrome_disable_csp_extension (chrome_options )
111
124
if proxy_string :
112
125
if proxy_auth :
113
126
chrome_options = _add_chrome_proxy_extension (
@@ -135,7 +148,8 @@ def _create_firefox_profile(downloads_path, proxy_string, user_agent):
135
148
profile .set_preference ("general.useragent.override" , user_agent )
136
149
profile .set_preference (
137
150
"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 )
139
153
profile .set_preference (
140
154
"browser.download.manager.showAlertOnComplete" , False )
141
155
profile .set_preference ("browser.privatebrowsing.autostart" , True )
0 commit comments