Functions and classes available to Web Workers
In addition to the standard JavaScript set of functions (such as String
, Array
, Object
, JSON
, etc.), there are a variety of functions available from the DOM to workers. This article provides a list of those.
Worker Contexts & Functions
Workers run in a different global context than the current window! While Window
is not directly available to workers, many of the same methods are defined in a shared mixin (WindowOrWorkerGlobalScope
), and made available to workers through their own WorkerGlobalScope
-derived contexts:
DedicatedWorkerGlobalScope
for dedicated workersSharedWorkerGlobalScope
for shared workersServiceWorkerGlobalScope
for service workers
Some of the functions (a subset) that are common to all workers and to the main thread (from WindowOrWorkerGlobalScope
) are:
WorkerGlobalScope.atob()
WorkerGlobalScope.btoa()
WorkerGlobalScope.clearInterval()
WorkerGlobalScope.clearTimeout()
WorkerGlobalScope.createImageBitmap()
WorkerGlobalScope.dump()
Non-standardWorkerGlobalScope.fetch()
WorkerGlobalScope.queueMicrotask()
WorkerGlobalScope.reportError()
WorkerGlobalScope.setInterval()
WorkerGlobalScope.setTimeout()
WorkerGlobalScope.structuredClone()
DedicatedWorkerGlobalScope.requestAnimationFrame()
(dedicated workers only)DedicatedWorkerGlobalScope.cancelAnimationFrame()
(dedicated workers only)
The following functions are only available to workers:
WorkerGlobalScope.importScripts()
(all workers)DedicatedWorkerGlobalScope.postMessage()
(dedicated workers only)
Web APIs available in workers
Note: If a listed API is supported by a platform in a particular version, then it can generally be assumed to be available in web workers. You can also test support for a particular object/function using the site: https://worker-playground.glitch.me/
The following Web APIs are available to workers:
- Background Fetch API
- Background Synchronization API
- Barcode Detection API
- Broadcast Channel API
- Canvas API
- Channel Messaging API
- Compression Streams API
- Compute Pressure API
- Console API
- Content Index API
- Cookie Store API (service workers only)
- CSS Font Loading API
- Encoding API
- Fetch API
- File API
- File System API
- Idle Detection API
- IndexedDB API
- Media Capabilities API
- Media Source Extensions API (dedicated workers only)
- Network Information API
- Notifications API
- Payment Handler API
- Performance API
- Permissions API
- Prioritized Task Scheduling API
- Push API
- Reporting API
- Server-Sent Events
- Service Worker API
- Streams API
- Trusted Types API
- URL API
- URL Pattern API
- User-Agent Client Hints API
- Web Crypto API
- Web Locks API
- Web Serial API
- Web Periodic Background Synchronization API
- WebCodecs API
- WebGL API
- WebGPU API
- WebHID API (dedicated and service workers only)
- WebUSB API
- WebSockets API
- XMLHttpRequest API
Workers can also spawn other workers, so these APIs are also available: