W3cubDocs

/DOM

Web Workers API: Functions and classes available to 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.

Workers run in another global context, DedicatedWorkerGlobalScope, different from the current window. By default, methods and properties of Window are not available to them, but DedicatedWorkerGlobalScope, like Window, implements WindowTimers and WindowBase64.

Comparison of the properties and methods of the different type of workers

Function Dedicated workers Shared workers Service workers Chrome workers Outside workers
atob() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
btoa() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
clearInterval() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
clearTimeout() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
dump() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
setInterval() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
setTimeout() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on Window
importScripts() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, on WorkerGlobalScope no
close() yes, on WorkerGlobalScope yes, on WorkerGlobalScope yes, but is a no-op. Unknown no
postMessage() yes, on DedicatedWorkerGlobalScope no no Unknown no

APIs available in workers

Function Functionality Support in Gecko (Firefox) Support in IE Support in Blink (Chrome and Opera) Support in WebKit (Safari)
Broadcast Channel API Allows simple communication between browsing contexts (that is windows, tabs, frames, or iframes) with the same origin (usually pages from the same site). 38 (38) No support No support No support
Cache Cache API provides the ability to programmatically control cache storage associated with current origin. (Yes) No support 43 ?
Channel Messaging API Allows two separate scripts running in different browsing contexts attached to the same document (e.g., two IFrames, or the main document and an IFrame, two documents via a SharedWorker, or two workers) to communicate directly via two ports. 41 (41) (Yes) (Yes) (Yes)
Console API Provides access to the browser's debugging console (e.g., the Web Console in Firefox). The specifics of how it works vary from browser to browser, but there is a de facto set of features that are typically provided. 38 (38) (Yes) (Yes) (Yes)
CustomEvent The CustomEvent interface represents events initialized by an application for any purpose. 48 (48) (Yes) (Yes) (Yes)
Data Store A powerful, flexible storage mechanism for multiple Firefox OS applications to use to store and share data between one another quickly, efficiently, and securely. Only in Firefox OS internal (certified) applications, since v1.0.1. No support No support No support
DOMRequest and DOMCursor Respectively, these objects represents an ongoing operation (with listeners for reacting to the operation completely successfully, or failing, for example), and an ongoing operation over a list of results. 41 (41) ? ? ?
Fetch The Fetch spec provides an up-to-date definition of, and API for, fetching resources (e.g. across the network.) Mostly in 34 (34) behind pref, although a few features are later. No support 42
41 behind pref
No support
FileReader This API allows asynchronous read of Blob and File objects. 46 (46) No support (Yes) No support
FileReaderSync This API allows synchronous read of Blob and File objects. This is an API that works only in workers. 8 (8) No support No support No support
FormData FormData objects provide a way to easily construct a set of key/value pairs representing form fields and their values, which can then be easily sent using the XMLHttpRequest send() method. ? (should be in 39 (39)) ? (Yes) ?
ImageData The underlying pixel data of an area of a canvas element. Manipulating such data can be a complex task better suited to be delegated to a Web Worker. 25 (25) No support No support No support
IndexedDB Database to store records holding simple values and hierarchical objects. 37 (37), 42 (42) for IDBCursorWithValue. 10.0 (Yes) No support
Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi', 'cellular', etc.). 53.0 (53) only on mobile (Yes) only on mobile No support No support
Notifications Allows web pages to control the display of system notifications to the end user 41 (41) ? ? ?
Performance The Performance interface represents timing-related performance information for the given page. 34.0 (34.0) ? 33.0 ?
Promise JavaScript objects that allow you to write asynchronous functions. 28 (28) (Yes) (Yes) (Yes)
Server-sent events Allows a server to push data to a web page at any point, after a connection has been opened to it. 53 (53) (currently only available in dedicated and shared workers; not service workers.) ? (Yes) ?
ServiceWorkerRegistration You can register a service worker from inside a standard worker, and use associated functionality. 40 (40) No support (Yes) No support
TextEncoder and TextDecoder Create and return a new TextEncoder, or respectively TextDecoder, allowing to encode or decode strings into specific encodings. 20 (20) No support No support No support
URL Workers can use the static methods URL.createObjectURL and URL.revokeObjectURL with Blob objects accesible to the worker.
Workers can also create a new URL using the URL() constructor and call any normal method on the returned object.
21 (21) and 26 (26) for URL() constructor No support No support No support
WebGL with OffscreenCanvas WebGL (Web Graphics Library) is a JavaScript API for rendering interactive 3D and 2D graphics within any compatible web browser without the use of plug-ins. 44 (44) behind a feature preference setting. In about:config, set gfx.offscreencanvas.enabled to true. No support No support No support
WebSocket Creates and returns a new WebSocket object; this mimics the behavior of the standard WebSocket() constructor. 37 (37) 11.0 (Yes) (Yes)
Worker Creates a new Worker. Yes, workers can spawn more workers. 3.5 (1.9.1) 10.0 No support See crbug.com/31666 No support
WorkerGlobalScope The global scope of workers. This objects defines worker-specific functions. (Yes) 10.0 (Yes) (Yes)
WorkerLocation The subset of the Location interface available to workers. 3.6 (1.9.2) 10.0 (Yes) (Yes)
WorkerNavigator The subset of the Navigator interface available to workers. Basic implementation (Yes)
appCodeName, product, taintEnabled(): 28 (28)
onLine: 29 (29)
NavigatorLanguage: (Yes)
appName, appVersion, onLine, platform, userAgent: 10.0
Other: No support
(Yes) (Yes)
XMLHttpRequest Creates and returns a new XMLHttpRequest object; this mimics the behavior of the standard XMLHttpRequest() constructor. Note that the responseXML and channel attributes on XMLHttpRequest always return null.

Basic: 3.5 (1.9.1)

response and responseType are available since 10 (10)

timeout and ontimeout are available since 13 (13)

(Yes) (Yes) (Yes)

See also

© 2005–2018 Mozilla Developer Network and individual 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