File tree Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Expand file tree Collapse file tree 1 file changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -117,13 +117,30 @@ def wait_for_jquery_active(driver, timeout=None):
117
117
118
118
119
119
def raise_unable_to_load_jquery_exception (driver ):
120
- """ The most-likely reason for jQuery not loading on web pages. """
121
- raise Exception (
122
- """Unable to load jQuery on "%s" due to a possible violation """
123
- """of the website's Content Security Policy directive. """
124
- """To override this policy, add "--disable-csp" on the """
125
- """command-line when running your tests.""" % driver .current_url
126
- )
120
+ has_csp_error = False
121
+ csp_violation = "violates the following Content Security Policy directive"
122
+ browser_logs = []
123
+ try :
124
+ browser_logs = driver .get_log ("browser" )
125
+ except (ValueError , WebDriverException ):
126
+ pass
127
+ for entry in browser_logs :
128
+ if entry ["level" ] == "SEVERE" :
129
+ if csp_violation in entry ["message" ]:
130
+ has_csp_error = True
131
+ if has_csp_error :
132
+ raise Exception (
133
+ """Unable to load jQuery on "%s" due to a violation """
134
+ """of the website's Content Security Policy directive. """
135
+ """To override this policy, add "--disable-csp" on the """
136
+ """command-line when running your tests.""" % driver .current_url
137
+ )
138
+ else :
139
+ raise Exception (
140
+ """Unable to load jQuery on "%s" because this website """
141
+ """restricts external JavaScript resources from loading."""
142
+ % driver .current_url
143
+ )
127
144
128
145
129
146
def activate_jquery (driver ):
You can’t perform that action at this time.
0 commit comments