The WorkerGlobalScope is an interface representing the scope of any worker. Workers having no browsing context, this scope contains the information usually conveyed by the Window objects, like 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. The self property returns the specialized scope for each context.
Properties
This interface inherits properties from the EventTarget interface and implements properties from WindowTimers, WindowBase64, and WindowEventHandlers.
-
WorkerGlobalScope.selfRead only -
Returns a reference to the
WorkerGlobalScopeitself. Most of the time it is a specific scope likeDedicatedWorkerGlobalScope,SharedWorkerGlobalScopeorServiceWorkerGlobalScope. -
WorkerGlobalScope.consoleRead only -
Returns the
Consoleassociated with the worker. -
WorkerGlobalScope.locationRead only -
Returns the
WorkerLocationassociated with the worker. It is a specific location object, mostly a subset of theLocationfor browsing scopes, but adapted to workers. -
WorkerGlobalScope.navigatorRead only -
Returns the
WorkerNavigatorassociated with the worker. It is a specific navigator object, mostly a subset of theNavigatorfor browsing scopes, but adapted to workers. -
WorkerGlobalScope.performanceRead only -
Returns the
Performanceassociated with the worker. Also it is the regular performance object, only a subset of its property and methods are available to workers.
Methods
This interface inherits methods from the EventTarget interface and implements methods from WindowTimers, WindowBase64, and WindowEventHandlers.
-
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 each X milliseconds.
-
WindowTimers.setTimeout() - Sets a delay for executing a function.
-
WorkerGlobalScope.close() -
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');
Event Handlers
This interface inherits event handlers from the EventTarget interface and implements event handlers from WindowTimers, and WindowBase64.
-
WorkerGlobalScope.onerror -
Is an
EventHandlerrepresenting the code to be called when theerrorevent is raised. -
WorkerGlobalScope.onoffline -
Is an
EventHandlerrepresenting the code to be called when theofflineevent is raised. -
WorkerGlobalScope.ononline -
Is an
EventHandlerrepresenting the code to be called when theonlineevent is raised. -
WorkerGlobalScope.onclose -
Is an
EventHandlerrepresenting the code to be called when thecloseevent is raised.
Specifications
| Specification | Status | Comment |
|---|---|---|
| Web Workers The definition of 'WorkerNavigator' in that specification. |
Candidate Recommendation | Initial definition |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | ? | 3.5 (1.9.1) | ? | ? | ? |
ononline, onoffline |
? | 29 (29) | ? | ? | ? |
console |
? | 29 (29) as WorkerConsole30 (30) as the regular Console |
? | ? | ? |
performance |
? | 34 (34) | ? | ? | ? |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | ? | ? | 1.0 (1.9.1) | ? | ? | ? |
ononline, onoffline |
? | ? | 29.0 (29) as a specific WorkerConsole30.0 (30) as the regular Console |
? | ? | ? |
console |
? | ? | 29.0 (29) | ? | ? | ? |
performance |
? | ? | 34.0 (34) | ? | ? | ? |
See also
- Other global object interface:
Window,DedicatedWorkerGlobalScope, ,SharedWorkerGlobalScope, ,ServiceWorkerGlobalScope - Other Worker-related interfaces:
Worker,WorkerLocation, andWorkerGlobalScope. - Using web workers.