Web Workers

Sentry's Browser SDK supports Web Workers API. To capture unhandled errors from Web Workers:

Install @sentry/browser using yarn or npm:

Copied
# Using yarn
yarn add @sentry/browser

# Using npm
npm install --save @sentry/browser

Then you can use it:

index.js
Copied
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!");

Usage Without Worker-Level Initialization

worker.js
Copied
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
Copied
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.