Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

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.

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)
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)
Worker Creates a new Worker. Yes, workers can spawn more workers. 3.5 (1.9.1) 10.0 Not supported See crbug.com/31666 Not supported
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 Not supported Not supported Not supported
TextEncoder and TextDecoder Create and return a new TextEncoder, or respectively TextDecoder, allowing to encode or decode strings into specific encodings. 20 (20) Not supported Not supported Not supported
WorkerNavigator The subset of the Navigator interface available to workers. Basic implementation (Yes)
appCodeName, product, taintEnabled(): 28 (28)
onLine: 29 (29)
NavigatorLanguage: Not supported
appName, appName, onLine, platform, userAgent: 10.0
Other: Not supported
(Yes) (Yes)
WorkerLocation The subset of the Location interface available to workers. 3.6 (1.9.2) 10.0 (Yes) (Yes)
WorkerGlobalScope The global scope of workers. This objects defines worker-specific functions. (Yes) 10.0 (Yes) (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) Not supported Not supported Not supported
FileReaderSync This API allows synchronous read of Blob and File objects. This is an API that works only in workers. 8 (8) Not supported Not supported Not supported
IndexedDB Database to store records holding simple values and hierarchical objects. 37 (37) 10.0 (Yes) Not supported
WebSocket Creates and returns a new WebSocket  object; this mimics the behavior of the standard WebSocket() constructor. 36 (36) 11.0 (Yes) (Yes)
Data Store API 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. Not supported Not supported Not supported
Promises JavaScript objects that allow you to write asynchronous functions. 28 (28) (Yes) (Yes) (Yes)

See also

Document Tags and Contributors

 Contributors to this page: teoli, romeodoitall
 Last updated by: teoli,