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.

This interface is usually specialized by each worker type: DedicatedWorkerGlobalScope for dedicated workers, SharedWorkerGlobalScope for shared workers, and ServiceWorkerGlobalScope for ServiceWorker. The self property returns the specialized scope for each context.


This interface inherits properties from the EventTarget interface and implements properties from the WindowOrWorkerGlobalScope and WindowEventHandlers mixins.

Standard properties

WorkerGlobalScope.navigator Read only

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.
WorkerGlobalScope.self Read only
Returns a reference to the WorkerGlobalScope itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScopeSharedWorkerGlobalScope or ServiceWorkerGlobalScope.
WorkerGlobalScope.location Read only
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.

Non-standard properties

WorkerGlobalScope.performance Read only
Returns the Performance associated with the worker. It is a regular performance object, except that only a subset of its property and methods are available to workers.
WorkerGlobalScope.console Read only
Returns the Console associated with the worker.

Properties implemented from elsewhere

WindowOrWorkerGlobalScope.caches Read only
Returns the CacheStorage object associated with the current context. This object enables functionality such as storing assets for offline use, and generating custom responses to requests.
WindowOrWorkerGlobalScope.indexedDB Read only
Provides a mechanism for applications to asynchronously access capabilities of indexed databases; returns an IDBFactory object.
WindowOrWorkerGlobalScope.isSecureContext Read only
Returns a boolean indicating whether the current context is secure (true) or not (false).
WindowOrWorkerGlobalScope.origin Read only
Returns the global object's origin, serialized as a string. (This does not yet appear to be implemented in any browser.)

Event Handlers

This interface inherits event handlers from the EventTarget interface (which includes those from GlobalEventHandlers), and implements event handlers from the WindowTimers mixin.

Is an EventHandler representing the code to be called when the error event is raised.
Is an EventHandler representing the code to be called when the offline event is raised.
Is an EventHandler representing the code to be called when the online event is raised.
An EventHandler fired at the global/worker scope object when the user's preferred languages change.
Is an EventHandler representing the code to be called when the close event is raised.
An event handler for handled Promise rejection events.
An event handler for unhandled Promise rejection events.


This interface inherits methods from the EventTarget interface and implements properties from the WindowOrWorkerGlobalScope and WindowEventHandlers mixins.

Standard methods

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');

Non-standard methods

Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's window.dump, but for workers.

Methods implemented from elsewhere

Decodes a string of data which has been encoded using base-64 encoding.
Creates a base-64 encoded ASCII string from a string of binary data.
Cancels the repeated execution set using WindowOrWorkerGlobalScope.setInterval().
Cancels the delayed execution set using WindowOrWorkerGlobalScope.setTimeout().
Accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.
Starts the process of fetching a resource from the network.
Schedules a function to execute every time a given number of milliseconds elapses.
Schedules a function to execute in a given amount of time.

Deprecated methods

Discards any tasks queued in the WorkerGlobalScope's event loop, effectively closing this particular scope. In newer browser versions, close() is available on DedicatedWorkerGlobalScope and SharedWorkerGlobalScope instead. This change was made to stop close() being available on service workers, as it isn't supposed to be used there and always throws an exception when called (see bug 1336043).


You won't access WorkerGlobalScope directly in your code; however, its properties and methods are inherited by more specific global scopes such as DedicatedWorkerGlobalScope and SharedWorkerGlobalScope. For example, you could import another script into the worker and print out the contents of the worker scope's navigator object using the following two lines:


Since the global scope of the worker script is effectively the global scope of the worker you are running (DedicatedWorkerGlobalScope or whatever) and all worker global scopes inherit methods, properties, etc. from WorkerGlobalScope, you can run lines such as those above without specifying a parent object.


Specification Status Comment
HTML Living Standard
The definition of 'WorkerGlobalScope' in that specification.
Living Standard  

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support4 Yes3.51010.64
location4 ?3.5 Yes11.54
navigator4173.5 Yes11.54
onerror4 ?3.5 Yes11.54
onlanguagechange4 ?3.5 Yes11.54
onoffline4 ?29 ? ? ?
ononline4 ?29 ? ? ?
performance Yes ?34 ? ? ?
self4 ?3.5 Yes11.54
console4 ?291 Yes Yes Yes
close4 ?3.5 Yes11.54
dump No No No No No No
importScripts Yes Yes Yes Yes Yes Yes
onclose4 ?3.5 — 50 Yes11.54
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support ? Yes Yes411.55.1 Yes
location ?40 ?4 Yes5.14.0
navigator ?40174 Yes5.14.0
onerror ?40 ?4 Yes5.14.0
onlanguagechange ?40 ?4 Yes5.14.0
onoffline Yes40 ?29 ? ?4.0
ononline Yes40 ?29 ? ?4.0
performance ? Yes ?34 ? ? Yes
self ?40 ?34 Yes5.14.0
console ? Yes ?291 ? ? Yes
close ? Yes ?4 ? ? Yes
dump No No No4 No No No
importScripts Yes Yes Yes4 Yes Yes Yes
onclose ?40 No4 — 50 Yes5.14.0

1. Before Firefox 30, the console would be of type WorkerConsole instead of Console.

See also

Document Tags and Contributors

Last updated by: connorshea,