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.
On this page
Functions and classes available to Web Workers
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:
DedicatedWorkerGlobalScopefor dedicated workersSharedWorkerGlobalScopefor shared workersServiceWorkerGlobalScopefor service workers
Some of the functions (a subset) that are common to all workers and to the main thread (from WindowOrWorkerGlobalScope) are:
atob()btoa()clearInterval()clearTimeout()dump()Non-standardqueueMicrotask()setInterval()setTimeout()structuredClone()window.requestAnimationFrame(dedicated workers only)window.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:
Barcode Detection APIBroadcast Channel APICache APIChannel Messaging APIConsole API- Web Crypto API (e.g.
Crypto) - CSS Font Loading API
CustomEventEncoding API(e.g.TextEncoder,TextDecoder)Fetch APIFileReaderFileReaderSync(only works in workers!)FormDataImageBitmapImageDataIndexedDB- Media Source Extensions API (dedicated workers only)
- Network Information API
Notifications APIOffscreenCanvas(and all the canvas context APIs)Performance API, including:- Server-sent events
ServiceWorkerRegistrationURL API(e.g.URL)- WebCodecs_API
WebSocketXMLHttpRequest
Workers can also spawn other workers, so these APIs are also available:
See also
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Functions_and_classes_available_to_workers