From deb8f69a92758571c87178484391cd97cfb745d2 Mon Sep 17 00:00:00 2001 From: Benedict Wilson Date: Tue, 7 Feb 2023 14:33:01 +0000 Subject: [PATCH] [PLAT-9606] Update autoDetectErrors to false (#1919) * fix: :wrench: set autoDetectErrors default value to false * test: :white_check_mark: update e2e test to set autoDetectErrors to true * docs: :memo: update CHANGELOG.md * test: :white_check_mark: rename unhandled promise rejection test and enable autoDetectErrors * test: :white_check_mark: test autoDetectErrors when default and overridden to true * docs: :memo: update CHANGELOG.md --- CHANGELOG.md | 6 +++++ packages/web-worker/src/config.js | 6 ++++- .../default/index.html | 18 +++++++++++++++ .../default}/worker.js | 0 .../enabled}/index.html | 0 .../enabled/worker.js | 22 +++++++++++++++++++ .../index.html | 0 .../worker.js | 1 + test/browser/features/web_worker.feature | 10 ++++++--- 9 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/index.html rename test/browser/features/fixtures/web_worker/{worker_unhandled_error => worker_auto_detect_errors/default}/worker.js (100%) rename test/browser/features/fixtures/web_worker/{worker_unhandled_error => worker_auto_detect_errors/enabled}/index.html (100%) create mode 100644 test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/worker.js rename test/browser/features/fixtures/web_worker/{unhandled_promise_rejection => worker_unhandled_promise_rejection}/index.html (100%) rename test/browser/features/fixtures/web_worker/{unhandled_promise_rejection => worker_unhandled_promise_rejection}/worker.js (93%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec191be8f3..4053f761fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/web-worker/src/config.js b/packages/web-worker/src/config.js index 2ff035c1b7..e27ca52f3b 100644 --- a/packages/web-worker/src/config.js +++ b/packages/web-worker/src/config.js @@ -17,7 +17,11 @@ module.exports = { }), autoTrackSessions: { ...schema.autoTrackSessions, - defaultValue: val => false + defaultValue: () => false + }, + autoDetectErrors: { + ...schema.autoTrackSessions, + defaultValue: () => false } } diff --git a/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/index.html b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/index.html new file mode 100644 index 0000000000..9ee883a571 --- /dev/null +++ b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + diff --git a/test/browser/features/fixtures/web_worker/worker_unhandled_error/worker.js b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/worker.js similarity index 100% rename from test/browser/features/fixtures/web_worker/worker_unhandled_error/worker.js rename to test/browser/features/fixtures/web_worker/worker_auto_detect_errors/default/worker.js diff --git a/test/browser/features/fixtures/web_worker/worker_unhandled_error/index.html b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/index.html similarity index 100% rename from test/browser/features/fixtures/web_worker/worker_unhandled_error/index.html rename to test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/index.html diff --git a/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/worker.js b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/worker.js new file mode 100644 index 0000000000..5ea8895388 --- /dev/null +++ b/test/browser/features/fixtures/web_worker/worker_auto_detect_errors/enabled/worker.js @@ -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: + } +} diff --git a/test/browser/features/fixtures/web_worker/unhandled_promise_rejection/index.html b/test/browser/features/fixtures/web_worker/worker_unhandled_promise_rejection/index.html similarity index 100% rename from test/browser/features/fixtures/web_worker/unhandled_promise_rejection/index.html rename to test/browser/features/fixtures/web_worker/worker_unhandled_promise_rejection/index.html diff --git a/test/browser/features/fixtures/web_worker/unhandled_promise_rejection/worker.js b/test/browser/features/fixtures/web_worker/worker_unhandled_promise_rejection/worker.js similarity index 93% rename from test/browser/features/fixtures/web_worker/unhandled_promise_rejection/worker.js rename to test/browser/features/fixtures/web_worker/worker_unhandled_promise_rejection/worker.js index ae0b1c30b3..aa950d19b3 100644 --- a/test/browser/features/fixtures/web_worker/unhandled_promise_rejection/worker.js +++ b/test/browser/features/fixtures/web_worker/worker_unhandled_promise_rejection/worker.js @@ -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 diff --git a/test/browser/features/web_worker.feature b/test/browser/features/web_worker.feature index b4623ceb6e..17b72f8e6b 100644 --- a/test/browser/features/web_worker.feature +++ b/test/browser/features/web_worker.feature @@ -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 @@ -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"