Skip to content

Commit 6ebfdbf

Browse files
committed
Use better error messages when trying to load JS resources
1 parent 4a8fd1f commit 6ebfdbf

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

seleniumbase/fixtures/js_utils.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,30 @@ def wait_for_jquery_active(driver, timeout=None):
117117

118118

119119
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+
)
127144

128145

129146
def activate_jquery(driver):

0 commit comments

Comments
 (0)