Web Workers
Sentry's Browser SDK supports Web Workers API. To capture unhandled errors from Web Workers:
Install @sentry/browser
using yarn
or npm
:
# Using yarn
yarn add @sentry/browser
# Using npm
npm install --save @sentry/browser
Then you can use it:
index.js
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
});
const worker = new Worker("worker.js");
// Errors from `onmessage` callback of `worker.js`
// will be captured.
worker.postMessage("Hello!");
Manual Capturing
To capture errors or messages manually, such as to use captureMessage
or captureError
inside Web Workers, Sentry should be initialized inside each Web Workers' own scope. Only unhandled errors will be captured and sent to Sentry without worker-level initialization.
Usage Without Worker-Level Initialization
worker.js
import * as Sentry from "@sentry/browser";
self.onmessage = message => {
// This will fail silently.
Sentry.captureMessage("Message received");
// This error will be captured.
throw new Error();
};
Usage With Worker-Level Initialization
worker.js
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
});
self.onmessage = message => {
// This message will be captured
Sentry.captureMessage("Message received");
// This error will also be captured.
throw new Error();
};
Integrations
Using non-default integrations such as @sentry/tracing inside Web Workers may not work as expected. Non-default integrations enabled outside workers' scope are not affected by worker-level configurations and will still work as expected.
Source Maps
Sentry's source maps integration is supported inside Web Workers, if provided. Learn more about providing your source maps to Sentry.
- Package:
- npm:@sentry/capacitor
- Version:
- 0.18.0
- Repository:
- https://github.com/getsentry/sentry-capacitor