Dedicated workers
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.
EventTarget WorkerGlobalScope DedicatedWorkerGlobalScope
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 4 | 12 | 3.5 | 4 | 18 | 5 | |
| The close() method of the DedicatedWorkerGlobalScope interface discards any tasks queued in the DedicatedWorkerGlobalScope's event loop, effectively closing this particular scope. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The name read-only property of the DedicatedWorkerGlobalScope interface returns the name that the Worker was (optionally) given when it was created. This is the name that the Worker.Worker constructor can pass to get a reference to the DedicatedWorkerGlobalScope. | 70 | 18 | 55 | 12.1 | 70 | 12.2 |
| The Worker interface of the Web Workers API represents a background task that can be created via script, which can send messages back to its creator. | 2 | 12 | 3.5 | 4 | 18 | 5 |
| The error event of the Worker interface fires when an error occurs in the worker. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The terminate() method of the Worker interface immediately terminates the Worker. This does not offer the worker an opportunity to finish its operations; it is stopped at once. | 2 | 12 | 3.5 | 4 | 18 | 5 |
| The Worker() constructor creates a Worker object that executes the classic script or module at the specified URL. | 4 | 12 | 3.5 | 4 | 18 | 5 |
worker_support Available in workers | 69 | 79 | 34 | 16.4 | 69 | 16.4 |
Worker (mime checks) Strict MIME type checks for worker scripts | | | 81 | 16 | | 16 |
Worker (options name parameter) `options.name` parameter | 70 | 18 | 55 | 12.1 | 70 | 12.2 |
| The WorkerGlobalScope interface of the Web Workers API is an interface representing the scope of any worker. Workers have no browsing context; this scope contains the information usually conveyed by Window objects — in this case event handlers, the console or the associated WorkerNavigator object. Each WorkerGlobalScope has its own event loop. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The error event of the WorkerGlobalScope interface fires when an error occurs in the worker. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The importScripts() method of the WorkerGlobalScope interface synchronously imports one or more scripts into the scope of a classic worker (a worker constructed from a classic script). | 4 | 12 | 4 | 4 | 18 | 5 |
importScripts (mime checks) Strict MIME type checks for `importScripts()` | 71 | 79 | 67 | 16 | 71 | 16 |
| The read-only location property of the WorkerGlobalScope interface returns the WorkerLocation associated with the worker. It is a specific location object, mostly a subset of the Location for browsing scopes, but adapted to workers. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The navigator read-only property of the WorkerGlobalScope interface returns the WorkerNavigator associated with the worker. It is a specific navigator object, mostly a subset of the Navigator for browsing scopes, but adapted to workers. | 4 | 17 | 3.5 | 4 | 18 | 5 |
| The rejectionhandled event is sent to the script's global scope (typically WorkerGlobalScope) whenever a rejected Promise is handled late, i.e., when a handler is attached to the promise after its rejection had caused an WorkerGlobalScope.unhandledrejection_event event. | 49 | 79 | 69 | 11 | 49 | 11 |
| The self read-only property of the WorkerGlobalScope interface returns a reference to the WorkerGlobalScope itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, or ServiceWorkerGlobalScope. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The unhandledrejection event is sent to the global scope (typically WorkerGlobalScope) of a script when a Promise that has no rejection handler is rejected. | 49 | 79 | 69 | 11 | 49 | 11 |
| The WorkerLocation interface defines the absolute location of the script executed by the Worker. Such an object is initialized for each worker and is available via the WorkerGlobalScope.location property obtained by calling self.location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The hash property of a WorkerLocation object returns the URL.hash part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The host property of a WorkerLocation object returns the URL.host part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The hostname property of a WorkerLocation object returns the URL.hostname part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The href property of a WorkerLocation object returns a string containing the serialized URL for the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The origin property of a WorkerLocation object returns the worker's URL.origin. | 38 | 14 | 29 | 10 | 38 | 10 |
| The pathname property of a WorkerLocation object returns the URL.pathname part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The port property of a WorkerLocation object returns the URL.port part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The protocol property of a WorkerLocation object returns the URL.protocol part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The search property of a WorkerLocation object returns the URL.search part of the worker's location. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The toString() stringifier method of a WorkerLocation object returns a string containing the serialized URL for the worker's location. It is a synonym for WorkerLocation.href. | 4 | 12 | 3.5 | 4 | 18 | 5 |
| The WorkerNavigator interface represents a subset of the Navigator interface allowed to be accessed from a Worker. Such an object is initialized for each worker and is available via the WorkerGlobalScope.navigator property. | 4 | 12 | 3.5 | 4 | 18 | 5 |
- This browser only partially implements this feature
- Not available in Shared Workers. See bug 40695450.
- This browser only partially implements this feature
- Not available in Shared Workers. See bug 40695450.
- This browser only partially implements this feature
- Not available in Shared Workers. See bug 265263.
- This browser only partially implements this feature
- Not available in Shared Workers. See bug 40695450.
- This browser only partially implements this feature
- Not available in Shared Workers. See bug 265263.
Use cases
-
Using Dedicated workers
The DedicatedWorkerGlobalScope object (the Worker global scope) is accessible through the self keyword.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.