The DedicatedWorkerGlobalScope object (the Worker global scope) is accessible through the self keyword. Some additional global functions, namespaces objects, and constructors, not typically associated with the worker global scope, but available on it, are listed in the JavaScript Reference. See also: Functions available to workers.
Properties
This interface inherits properties from the WorkerGlobalScope interface, and its parent EventTarget, and therefore implements properties from WindowTimers, WindowBase64, and WindowEventHandlers.
DedicatedWorkerGlobalScope.nameRead only- The name that the
Workerwas (optionally) given when it was created using theWorker()constructor. This is mainly useful for debugging purposes.
Properties inherited from WorkerGlobalScope
WorkerGlobalScope.self- Returns an object reference to the
DedicatedWorkerGlobalScopeobject itself. WorkerGlobalScope.consoleRead only- Returns the
Consoleassociated with the worker. WorkerGlobalScope.locationRead only- Returns the
WorkerLocationassociated with the worker.WorkerLocationis a specific location object, mostly a subset of theLocationfor browsing scopes, but adapted to workers. WorkerGlobalScope.navigatorRead only- Returns the
WorkerNavigatorassociated with the worker.WorkerNavigatoris a specific navigator object, mostly a subset of theNavigatorfor browsing scopes, but adapted to workers. WorkerGlobalScope.performanceRead only- Returns the
Performanceobject associated with the worker, which is a regular performance object, but with a subset of its properties and methods available.
Event handlers
This interface inherits event handlers from the WorkerGlobalScope interface, and its parent EventTarget, and therefore implements event handlers from WindowTimers, WindowBase64, and WindowEventHandlers.
DedicatedWorkerGlobalScope.onmessage- Is an
EventHandlerrepresenting the code to be called when themessageevent is raised. These events are of typeMessageEventand will be called when the worker receives a message from the document that started it (i.e. from theWorker.postMessagemethod.) DedicatedWorkerGlobalScope.onmessageerror- Is an
EventHandlerrepresenting the code to be called when themessageerrorevent is raised.
Methods
This interface inherits methods from the WorkerGlobalScope interface, and its parent EventTarget, and therefore implements methods from WindowTimers, WindowBase64, and WindowEventHandlers.
DedicatedWorkerGlobalScope.close()- Discards any tasks queued in the
WorkerGlobalScope's event loop, effectively closing this particular scope. DedicatedWorkerGlobalScope.postMessage()- Sends a message — which can consist of
anyJavaScript object — to the parent document that first spawned the worker.
Inherited from WorkerGlobalScope
WorkerGlobalScope.dump()- Writes a message to the console.
WorkerGlobalScope.importScripts()- Imports one or more scripts into the worker's scope. You can specify as many as you'd like, separated by commas. For example:
importScripts('foo.js', 'bar.js');
Implemented from other places
WindowBase64.atob()- Decodes a string of data which has been encoded using base-64 encoding.
WindowBase64.btoa()- Creates a base-64 encoded ASCII string from a string of binary data.
WindowTimers.clearInterval()- Cancels the repeated execution set using
WindowTimers.setInterval(). WindowTimers.clearTimeout()- Cancels the repeated execution set using
WindowTimers.setTimeout(). WindowTimers.setInterval()- Schedules the execution of a function every X milliseconds.
WindowTimers.setTimeout()- Sets a delay for executing a function.
Events
message- Fired when the worker receives a message from its parent.
Also available via theonmessageproperty. messageerror- Fired when a worker receives a message that can't be deserialized.
Also available via theonmessageerrorproperty.
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'DedicatedWorkerGlobalScope' in that specification. |
Living Standard |
Browser compatibility
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
DedicatedWorkerGlobalScope | Chrome Full support 4 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 10 | Opera Full support 10.6 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5.1 | Samsung Internet Android Full support 1.0 |
close | Chrome Full support Yes | Edge Full support ≤79 | Firefox Full support 54 | IE ? | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 54 | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
message event | Chrome Full support 4 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 10 | Opera Full support 10.6 | Safari Full support 4 | WebView Android Full support 37 | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support 11.5 | Safari iOS Full support 5.1 | Samsung Internet Android Full support Yes |
messageerror event | Chrome Full support 60 | Edge Full support ≤79 | Firefox Full support 57 | IE ? | Opera Full support 47 | Safari ? | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android Full support 57 | Opera Android Full support 47 | Safari iOS ? | Samsung Internet Android Full support 8.0 |
name | Chrome Full support Yes | Edge Full support ≤79 | Firefox Full support 55 | IE No support No | Opera ? | Safari No support No | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 55 | Opera Android ? | Safari iOS No support No | Samsung Internet Android Full support Yes |
onmessage | Chrome Full support 4 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 10 | Opera Full support 10.6 | Safari Full support 4 | WebView Android Full support 37 | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5.1 | Samsung Internet Android Full support Yes |
onmessageerror | Chrome Full support 60 | Edge Full support ≤79 | Firefox Full support 57 | IE ? | Opera Full support 47 | Safari ? | WebView Android Full support 60 | Chrome Android Full support 60 | Firefox Android Full support 57 | Opera Android Full support 44 | Safari iOS ? | Samsung Internet Android Full support 8.0 |
postMessage | Chrome Full support 4 | Edge Full support 12 | Firefox Full support 3.5 | IE Full support 10 | Opera Full support 10.6 | Safari Full support 4 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support 11 | Safari iOS Full support 5.1 | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
