-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In iOS9 Safari, a request that violates the Content Security Policy (CSP) rules causes a `DOMException` to be thrown. Since v4.7.0, bugsnag calls `startSession()` synchronously upon startup, which means that any thrown error in that tick of the event loop results in the libary (and anything else in that synchronous execution context) to be unusable. The behaviour of iOS Safari was fixed in version 10, but since we support 9, this needs a workaround. The xml-http-request transport mechanism already wrapped request.send() with a try/catch, but the error in this instance was coming from the request.open() call. The try/catch block was moved out out to include all of the synchronous code inside sendReport()/sendSession().
- Loading branch information
1 parent
8811c44
commit 11921b2
Showing
9 changed files
with
102 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@csp | ||
Feature: Compatibility with a Content Security Policy | ||
|
||
Scenario Outline: notifer does not crash for CSP violations | ||
When I navigate to the URL "/csp/<type>/a.html" | ||
And the test should run in this browser | ||
Then I let the test page run for up to 10 seconds | ||
Examples: | ||
| type | | ||
| script | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'unsafe-inline' 'self';"> | ||
<script src="/node_modules/bugsnag-js/dist/bugsnag.min.js"></script> | ||
<script type="text/javascript"> | ||
var ENDPOINT = decodeURIComponent(window.location.search.match(/ENDPOINT=(.+)/)[1]) | ||
var bugsnagClient = bugsnag({ | ||
apiKey: 'ABC', | ||
endpoints: { | ||
notify: ENDPOINT, | ||
sessions: ENDPOINT | ||
}, | ||
autoNotify: false | ||
}) | ||
</script> | ||
</head> | ||
<body> | ||
<pre id="bugsnag-test-should-run">YES</pre> | ||
<pre id="bugsnag-test-state">PENDING</pre> | ||
<script> | ||
throw new Error('this should not get through') | ||
</script> | ||
<script> | ||
setTimeout(function () { | ||
var el = document.getElementById('bugsnag-test-state') | ||
// if the CSP violation caused bugsnag not to init, bugsnagClient won't be defined | ||
el.textContent = el.innerText = (bugsnagClient ? 'DONE' : 'ERROR') | ||
}, 5000) | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "bugsnag-js-fixtures-csp-script", | ||
"private": true, | ||
"scripts": { | ||
"build": "echo 'Done'" | ||
}, | ||
"dependencies": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters