docs.rodeo

MDN Web Docs mirror

WorkerGlobalScope

{{APIRef("Web Workers API")}} {{AvailableInWorkers("worker")}} 

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 {{domxref("Window")}}  objects — in this case event handlers, the console or the associated {{domxref("WorkerNavigator")}}  object. Each WorkerGlobalScope has its own event loop.

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

{{InheritanceDiagram}} 

Instance properties

This interface inherits properties from the {{domxref("EventTarget")}}  interface.

Instance methods

This interface inherits methods from the {{domxref("EventTarget")}}  interface.

Events

Example

You won’t access WorkerGlobalScope directly in your code; however, its properties and methods are inherited by more specific global scopes such as {{domxref("DedicatedWorkerGlobalScope")}}  and {{domxref("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:

importScripts("foo.js");
console.log(navigator);

[!NOTE] Since the global scope of the worker script is effectively the global scope of the worker you are running ({{domxref("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.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN