# Web Workers | Sentry for Svelte

Sentry's Browser SDK supports [Web Workers API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API.md). To capture unhandled errors from Web Workers:

Install `@sentry/browser` using your package manager:

```bash
npm install @sentry/browser --save
```

Then you can use it:

`index.js`

```javascript
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 `captureException` 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](https://docs.sentry.io/.md#usage-without-worker-level-initialization)

`worker.js`

```javascript
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](https://docs.sentry.io/.md#usage-with-worker-level-initialization)

`worker.js`

```javascript
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](https://docs.sentry.io/.md#integrations)

Note, that if you use non-default integrations inside web workers, they may not function as expected. But non-default integrations that are enabled outside of a worker’s scope won’t be affected and will function as expected. This includes Session Replay.

### [Source Maps](https://docs.sentry.io/.md#source-maps)

Sentry's source maps integration is supported inside Web Workers, if provided. Learn more about providing your [source maps](https://docs.sentry.io/platforms/javascript/sourcemaps.md) to Sentry.
