Skip to content

Commit

Permalink
[PLAT-9606] Update autoDetectErrors to false (#1919)
Browse files Browse the repository at this point in the history
* fix: 🔧 set autoDetectErrors default value to false

* test: ✅ update e2e test to set autoDetectErrors to true

* docs: 📝 update CHANGELOG.md

* test: ✅ rename unhandled promise rejection test and enable autoDetectErrors

* test: ✅ test autoDetectErrors when default and overridden to true

* docs: 📝 update CHANGELOG.md
  • Loading branch information
gingerbenw committed Feb 7, 2023
1 parent b49b594 commit deb8f69
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## TBD

### Changes

- (web-worker) Change default configuration for autoDetectErrors to false [#1919](https://github.com/bugsnag/bugsnag-js/pull/1919)

## 7.20.0 (2023-01-31)

This release adds support for service workers and web workers [#1915](https://github.com/bugsnag/bugsnag-js/pull/1915)
Expand Down
6 changes: 5 additions & 1 deletion packages/web-worker/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ module.exports = {
}),
autoTrackSessions: {
...schema.autoTrackSessions,
defaultValue: val => false
defaultValue: () => false
},
autoDetectErrors: {
...schema.autoTrackSessions,
defaultValue: () => false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script type="text/javascript">
var NOTIFY = decodeURIComponent(window.location.search.match(/NOTIFY=([^&]+)/)[1])
var SESSIONS = decodeURIComponent(window.location.search.match(/SESSIONS=([^&]+)/)[1])
var API_KEY = decodeURIComponent(window.location.search.match(/API_KEY=([^&]+)/)[1])
</script>
</head>
<body>
<script>
var worker = new Worker('worker.js')
worker.postMessage({ type: 'bugsnag-start', payload: { NOTIFY, SESSIONS, API_KEY } })
worker.onmessage = function () { worker.postMessage({ type: 'bugsnag-throw' }) }
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
importScripts("/node_modules/@bugsnag/web-worker/dist/bugsnag.web-worker.min.js")

onmessage = function (e) {
var payload = e.data.payload;

switch (e.data.type) {
case 'bugsnag-start':
Bugsnag.start({
apiKey: payload.API_KEY,
autoDetectErrors: true,
endpoints: {
notify: payload.NOTIFY,
sessions: payload.SESSIONS
}
})
postMessage('bugsnag-ready')
break;
case 'bugsnag-throw':
throw new Error('I am an error')
default:
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ onmessage = function (e) {
case 'bugsnag-start':
Bugsnag.start({
apiKey: payload.API_KEY,
autoDetectErrors: true,
endpoints: {
notify: payload.NOTIFY,
sessions: payload.SESSIONS
Expand Down
10 changes: 7 additions & 3 deletions test/browser/features/web_worker.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ Feature: worker notifier
And the exception "errorMessage" equals "I am an error"
And I should receive no sessions

Scenario: unhandled error in worker
When I navigate to the test URL "/web_worker/worker_unhandled_error"
Scenario: config.autoDetectErrors defaults to false
Given I navigate to the test URL "/web_worker/worker_auto_detect_errors/default"
Then I should receive no errors

Scenario: setting config.autoDetectErrors option to true
Given I navigate to the test URL "/web_worker/worker_auto_detect_errors/enabled"
And I wait to receive an error
Then the error is a valid browser payload for the error reporting API
And the error payload field "events.0.exceptions.0.stacktrace" is a non-empty array
Expand All @@ -30,7 +34,7 @@ Feature: worker notifier
And I should receive no sessions

Scenario: unhandled promise rejection
When I navigate to the test URL "/web_worker/unhandled_promise_rejection"
When I navigate to the test URL "/web_worker/worker_unhandled_promise_rejection"
And I wait to receive an error
Then the error is a valid browser payload for the error reporting API
And the exception "errorClass" equals "Error"
Expand Down

0 comments on commit deb8f69

Please sign in to comment.