{{APIRef("Web Workers API")}}
The SharedWorkerGlobalScope
object (the {{domxref("SharedWorker")}} global scope) is accessible through the {{domxref("window.self","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 {{domxref("WorkerGlobalScope")}} interface, and its parent {{domxref("EventTarget")}}, and therefore implements properties from {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, and {{domxref("WindowEventHandlers")}}.
- {{domxref("SharedWorkerGlobalScope.name")}} {{readOnlyinline}}
- The name that the {{domxref("SharedWorker")}} was (optionally) given when it was created. This is the name that the {{domxref("SharedWorker.SharedWorker", "SharedWorker()")}} constructor can pass to get a reference to the {{domxref("SharedWorkerGlobalScope")}}.
- {{domxref("SharedWorkerGlobalScope.applicationCache")}} {{readOnlyinline}}
- This property returns the {{domxref("ApplicationCache")}} object for the worker (see Using the application cache).
Properties inherited from WorkerGlobalScope
- {{domxref("WorkerGlobalScope.self")}}
- Returns an object reference to the
DedicatedWorkerGlobalScope
object itself. - {{domxref("WorkerGlobalScope.console")}} {{readOnlyinline}}
- Returns the {{domxref("Console")}} associated with the worker.
- {{domxref("WorkerGlobalScope.location")}} {{readOnlyinline}}
- Returns the {{domxref("WorkerLocation")}} associated with the worker.
WorkerLocation
is a specific location object, mostly a subset of the {{domxref("Location")}} for browsing scopes, but adapted to workers. - {{domxref("WorkerGlobalScope.navigator")}} {{readOnlyinline}}
- Returns the {{domxref("WorkerNavigator")}} associated with the worker.
WorkerNavigator
is a specific navigator object, mostly a subset of the {{domxref("Navigator")}} for browsing scopes, but adapted to workers. - {{domxref("WorkerGlobalScope.performance")}} {{readOnlyinline}} {{Non-standard_inline}}
- Returns the {{domxref("Performance")}} object 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 {{domxref("WorkerGlobalScope")}} interface, and its parent {{domxref("EventTarget")}}, and therefore implements event handlers from {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, and {{domxref("WindowEventHandlers")}}.
- {{domxref("SharedWorkerGlobalScope.onconnect")}}
- Is an {{domxref("EventHandler")}} representing the code to be called when the {{event("connect")}} event is raised — that is, when a {{domxref("MessagePort")}} connection is opened between the associated {{domxref("SharedWorker")}} and the main thread.
Methods
This interface inherits methods from the {{domxref("WorkerGlobalScope")}} interface, and its parent {{domxref("EventTarget")}}, and therefore implements methods from {{domxref("WindowTimers")}}, {{domxref("WindowBase64")}}, and {{domxref("WindowEventHandlers")}}.
Inherited from WorkerGlobalScope
- {{domxref("WorkerGlobalScope.close()")}}
- Discards any tasks queued in the
WorkerGlobalScope
's event loop, effectively closing this particular scope. - {{domxref("WorkerGlobalScope.dump()")}} {{non-standard_inline}}
- Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's {{domxref("window.dump")}}, but for workers.
- {{domxref("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
- {{domxref("WindowBase64.atob()")}}
- Decodes a string of data which has been encoded using base-64 encoding.
- {{domxref("WindowBase64.btoa()")}}
- Creates a base-64 encoded ASCII string from a string of binary data.
- {{domxref("WindowTimers.clearInterval()")}}
- Cancels the repeated execution set using {{domxref("WindowTimers.setInterval()")}}.
- {{domxref("WindowTimers.clearTimeout()")}}
- Cancels the repeated execution set using {{domxref("WindowTimers.setTimeout()")}}.
- {{domxref("WindowTimers.setInterval()")}}
- Schedules the execution of a function every X milliseconds.
- {{domxref("WindowTimers.setTimeout()")}}
- Sets a delay for executing a function.
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', '#sharedworkerglobalscope', 'SharedWorkerGlobalScope')}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName("Web Workers")}}. |
{{SpecName('Web Workers', '#sharedworkerglobalscope', 'SharedWorkerGlobalScope')}} | {{Spec2('Web Workers')}} | Initial definition. |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Support | {{CompatChrome(4)}} | {{CompatGeckoDesktop(29.0)}} | {{CompatNo}} | {{CompatOpera(10.60)}} | 5, but unsupported as of 6.1 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Support | {{CompatNo}} | {{ CompatNo() }} | {{CompatGeckoMobile("33.0")}} | 2.1 | {{CompatNo}} | 11.5 | 5.1, but unsupported as of 7.1 |
See also
- {{domxref("SharedWorker")}}
- {{domxref("WorkerGlobalScope")}}
- Using Web workers
- Functions available to workers