home
Shared Worker Demo
I'm a new Window
A [SharedWorker](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker) is a type of [Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Work_Workers_API) that allows **multiple browser contexts** (like tabs, windows, or iframes) from the **same origin** to communicate with a **single shared script** running in the background.
Unlike a regular [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker), which is scoped to a single window or tab, a `SharedWorker` creates a **shared execution context** that can be accessed by all windows of the same origin — making it ideal for coordinating state or data **across multiple browser windows**.
Key Features
- **Multiple contexts**: A single `SharedWorker` can be accessed by multiple windows or tabs, allowing them to share data and state.
- **Shared execution context**: The worker runs in a separate thread, allowing it to perform tasks without blocking the main UI thread.
- **Shared state**: The worker can maintain a shared state that all connected windows can access and modify.
- **Communication**: The worker can communicate with all connected windows using the `port` object, which is a communication channel between the worker and the main thread.
- **Lifecycle management**: The worker remains alive as long as at least one window is connected to it, allowing it to maintain state and perform tasks in the background.
- **Same-origin policy**: All communicating pages must come from the same origin (protocol + domain + port).
Open New Window