ServiceWorkerGlobalScope extension type
@AvailableInWorkers("service")
The ServiceWorkerGlobalScope
interface of the
Service Worker API
represents the global execution context of a service worker.
Developers should keep in mind that the ServiceWorker state is not persisted across the termination/restart cycle, so each event handler should assume it's being invoked with a bare, default global state.
Once successfully registered, a service worker can and will be terminated
when idle to conserve memory and processor power. An active service worker
is automatically restarted to respond to events, such as
ServiceWorkerGlobalScope.fetch_event
or
ServiceWorkerGlobalScope.message_event
.
Additionally, synchronous requests are not allowed from within a service worker — only asynchronous requests, like those initiated via the fetch method, can be used.
This interface inherits from the WorkerGlobalScope interface, and its parent EventTarget.
API documentation sourced from MDN Web Docs.
- on
- Implemented types
- Available extensions
Properties
- caches → CacheStorage
-
The
caches
read-only property of the WorkerGlobalScope interface 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.no setterinherited - clients → Clients
-
@AvailableInWorkers("service")
no setter
- crossOriginIsolated → bool
-
The
crossOriginIsolated
read-only property of the WorkerGlobalScope interface returns a boolean value that indicates whether the website is in a cross-origin isolation state. That state mitigates the risk of side-channel attacks and unlocks a few capabilities:no setterinherited - crypto → Crypto
-
The
crypto
read-only property of the WorkerGlobalScope interface returns the Crypto object for this worker. This object gives workers access to certain cryptographic related services.no setterinherited - fonts → FontFaceSet
-
The
fonts
property of the WorkerGlobalScope interface returns the FontFaceSet interface of the worker.no setterinherited - hashCode → int
-
The hash code for this object.
no setterinherited
- indexedDB → IDBFactory
-
The
indexedDB
read-only property of the WorkerGlobalScope interface provides a mechanism for workers to asynchronously access the capabilities of indexed databases.no setterinherited - isSecureContext → bool
-
The
isSecureContext
read-only property of the WorkerGlobalScope interface returns a boolean indicating whether the current context is secure (true
) or not (false
).no setterinherited - location → WorkerLocation
-
The
location
read-only 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.no setterinherited -
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.no setterinherited - onactivate ↔ EventHandler?
-
getter/setter pair
- onerror ↔ OnErrorEventHandler?
-
getter/setter pairinherited
- onfetch ↔ EventHandler?
-
getter/setter pair
- oninstall ↔ EventHandler?
-
getter/setter pair
- onlanguagechange ↔ EventHandler?
-
getter/setter pairinherited
- onmessage ↔ EventHandler?
-
getter/setter pair
- onmessageerror ↔ EventHandler?
-
getter/setter pair
- onnotificationclick ↔ EventHandler?
-
getter/setter pair
- onnotificationclose ↔ EventHandler?
-
getter/setter pair
- onoffline ↔ EventHandler?
-
getter/setter pairinherited
- ononline ↔ EventHandler?
-
getter/setter pairinherited
- onpush ↔ EventHandler?
-
getter/setter pair
- onpushsubscriptionchange ↔ EventHandler?
-
getter/setter pair
- onrejectionhandled ↔ EventHandler?
-
getter/setter pairinherited
- onsync ↔ EventHandler?
-
getter/setter pair
- onunhandledrejection ↔ EventHandler?
-
getter/setter pairinherited
- origin → String
-
The
origin
read-only property of the WorkerGlobalScope interface returns the origin of the global scope, serialized as a string.no setterinherited - performance → Performance
-
The
performance
property of the WorkerGlobalScope interface returns a Performance object, which can be used to gather performance information about code running in the worker's scope.no setterinherited - registration → ServiceWorkerRegistration
-
@AvailableInWorkers("service")
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scheduler → Scheduler
-
The
scheduler
read-only property of the WorkerGlobalScope interface is the entry point for using the Prioritized Task Scheduling API.no setterinherited - self → WorkerGlobalScope
-
The
self
read-only property of the WorkerGlobalScope interface returns a reference to theWorkerGlobalScope
itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScope, SharedWorkerGlobalScope, or ServiceWorkerGlobalScope.no setterinherited - serviceWorker → ServiceWorker
-
@AvailableInWorkers("service")
no setter
- trustedTypes → TrustedTypePolicyFactory
-
The
trustedTypes
read-only property of the WorkerGlobalScope interface returns the TrustedTypePolicyFactory object associated with the global object, providing the entry point for using theTrusted Types API
.no setterinherited
Methods
-
addEventListener(
String type, EventListener? callback, [JSAny options]) → void -
The
addEventListener()
method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.inherited -
atob(
String data) → String -
The
atob()
method of the WorkerGlobalScope interface decodes a string of data which has been encoded using encoding. You can use the WorkerGlobalScope.btoa method to encode and transmit data which may otherwise cause communication problems, then transmit it and use theatob()
method to decode the data again. For example, you can encode, transmit, and decode control characters such as values 0 through 31.inherited -
btoa(
String data) → String -
The
btoa()
method of the WorkerGlobalScope interface creates a -encoded string from a binary string (i.e., a string in which each character in the string is treated as a byte of binary data).inherited -
clearInterval(
[int id]) → void -
inherited
-
clearTimeout(
[int id]) → void -
inherited
-
createImageBitmap(
ImageBitmapSource image, [JSAny optionsOrSx, int sy, int sw, int sh, ImageBitmapOptions options]) → JSPromise< ImageBitmap> -
inherited
-
dispatchEvent(
Event event) → bool -
The
dispatchEvent()
method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually withdispatchEvent()
.inherited -
fetch(
RequestInfo input, [RequestInit init]) → JSPromise< Response> -
inherited
-
importScripts(
JSAny urls) → void -
The
importScripts()
method of the WorkerGlobalScope interface synchronously imports one or more scripts into the worker's scope.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
queueMicrotask(
VoidFunction callback) → void -
inherited
-
removeEventListener(
String type, EventListener? callback, [JSAny options]) → void -
The
removeEventListener()
method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.inherited -
reportError(
JSAny? e) → void -
inherited
-
setInterval(
TimerHandler handler, JSAny? arguments, [int timeout]) → int -
inherited
-
setTimeout(
TimerHandler handler, JSAny? arguments, [int timeout]) → int -
inherited
-
skipWaiting(
) → JSPromise< JSAny?> - @AvailableInWorkers("service")
-
structuredClone(
JSAny? value, [StructuredSerializeOptions options]) → JSAny? -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited