ServiceWorkerGlobalScope extension type

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.

on
Implemented types

Properties

caches CacheStorage
no setterinherited
clients Clients
no setter
crossOriginIsolated bool
no setterinherited
crypto Crypto
no setterinherited
fonts FontFaceSet
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
indexedDB IDBFactory
no setterinherited
isSecureContext bool
no setterinherited
location WorkerLocation
no setterinherited
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
onunhandledrejection EventHandler?
getter/setter pairinherited
origin String
no setterinherited
performance Performance
no setterinherited
registration ServiceWorkerRegistration
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
self WorkerGlobalScope
no setterinherited
serviceWorker ServiceWorker
no setter
trustedTypes TrustedTypePolicyFactory
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
inherited
btoa(String data) String
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 with dispatchEvent().
inherited
fetch(RequestInfo input, [RequestInit init]) JSPromise<Response>
inherited
importScripts(String 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?>
The ServiceWorkerGlobalScope.skipWaiting() method of the ServiceWorkerGlobalScope forces the waiting service worker to become the active service worker.
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