Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fuser-guides%2Frum%2Fsdk-features%2Fweb-workers-support.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fuser-guides%2Frum%2Fsdk-features%2Fweb-workers-support.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# Web worker support

Web Worker support enables the SDK to capture events from within Web Workers, including unhandled exceptions, custom log messages, and other SDK-provided features, ensuring complete visibility across all execution contexts.

## Overview[​](#overview "Direct link to Overview")

Enabling Web Worker support ensures complete visibility into background execution contexts. This allows you to monitor, debug, and optimize multi-threaded workflows just as effectively as your main application logic.

### Gain full observability[​](#gain-full-observability "Direct link to Gain full observability")

* Capture unhandled errors and logs from Web Workers to monitor all execution contexts.

* Expose hard-to-detect issues like silent failures in background threads.

### Simplify debugging[​](#simplify-debugging "Direct link to Simplify debugging")

* Trace issues across main-thread and worker contexts with unified logs.

* Identify race conditions and background logic failures with contextual event data.

### Extend SDK capabilities[​](#extend-sdk-capabilities "Direct link to Extend SDK capabilities")

* Enable full use of SDK features, such as error tracking, custom logging, and more, within workers.

* Unify your observability pipeline across both synchronous and asynchronous code paths.

### Support scalable architectures[​](#support-scalable-architectures "Direct link to Support scalable architectures")

* Instrument background tasks in performance-optimized apps using workers.

* Ensure reliable monitoring in modern, multi-threaded front-end architectures.

## Enable Web Worker support[​](#enable-web-worker-support "Direct link to Enable Web Worker support")

By default, Web Worker support is disabled. Enable this mode as follows.

```
CoralogixRum.init({

  workerSupport: true,

});
```

### Examples[​](#examples "Direct link to Examples")

**Creating a Web Worker**

Instantiate a Web Worker from your main application. The Coralogix RUM SDK automatically detects the worker and starts capturing unhandled errors and supported events, no additional instrumentation needed on the main thread.

```
// App code – creating a worker. The SDK will automatically capture errors from it.



const worker = new Worker('my-worker.js');
```

**Logging from inside a Web Worker**

Log an informational message directly from within the Web Worker. This ensures that background logs are recorded and appear alongside main-thread events in Coralogix.

```
// Log a basic info log

worker.CoralogixRum.log(CoralogixLogSeverity.Info, 'Test log from worker');
```

**Capturing errors with context**

Catch and manually report errors using `captureError`. Add contextual metadata (e.g. the worker’s role or custom labels) to enrich your observability and streamline debugging.

```
// Manually capture errors

try {

  // Some code that might throw an error

} catch (error) {

  CoralogixRum.captureError(error, { worker: 'analytics-worker' }, { label1: 'value1' });

}
```

**Logging incoming messages in the Worker**

Track and log messages received by the worker via `postMessage`. This helps monitor interactions between the main thread and the worker, improving traceability of distributed logic.

```
// Log messages received in the worker

self.onmessage = (message) => {

  worker.CoralogixRum.log(CoralogixLogSeverity.Info, message);

};
```
