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
isDefinedAndNotNull bool

Available on JSAny?, provided by the NullableUndefineableJSAnyExtension extension

no setter
isNull bool

Available on JSAny?, provided by the NullableUndefineableJSAnyExtension extension

Whether this value corresponds to JavaScript null.
no setter
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
isTruthy JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of !!this in JavaScript.
no setter
isUndefined bool

Available on JSAny?, provided by the NullableUndefineableJSAnyExtension extension

Whether this value corresponds to JavaScript undefined.
no setter
isUndefinedOrNull bool

Available on JSAny?, provided by the NullableUndefineableJSAnyExtension extension

no setter
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
not JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of !this in JavaScript.
no setter
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 the WorkerGlobalScope 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 the Trusted Types API.
no setterinherited

Methods

add(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this + any in JavaScript.
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
and(JSAny? any) JSAny?

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this && any in JavaScript.
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 the atob() 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
callMethod<R extends JSAny?>(JSAny method, [JSAny? arg1, JSAny? arg2, JSAny? arg3, JSAny? arg4]) → R

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Calls method on this JSObject with up to four arguments.
callMethodVarArgs<R extends JSAny?>(JSAny method, [List<JSAny?>? arguments]) → R

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Calls method on this JSObject with a variable number of arguments.
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
dartify() Object?

Available on JSAny?, provided by the JSAnyUtilityExtension extension

Converts a JavaScript value to the Dart equivalent if possible.
delete(JSAny property) JSBoolean

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Deletes the property with key property from this JSObject.
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
divide(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this / any in JavaScript.
equals(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this == any in JavaScript.
exponentiate(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this ** any in JavaScript.
fetch(RequestInfo input, [RequestInit init]) JSPromise<Response>
inherited
getProperty<R extends JSAny?>(JSAny property) → R

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

The value of the property key property of this JSObject.
greaterThan(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this > any in JavaScript.
greaterThanOrEqualTo(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this >= any in JavaScript.
has(String property) bool

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Shorthand helper for hasProperty to check whether this JSObject contains the property key property, but takes and returns a Dart value.
hasProperty(JSAny property) JSBoolean

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Whether or not this JSObject contains the property key property.
importScripts(JSAny urls) → void
The importScripts() method of the WorkerGlobalScope interface synchronously imports one or more scripts into the worker's scope.
inherited
instanceof(JSFunction constructor) bool

Available on JSAny?, provided by the JSAnyUtilityExtension extension

Whether this JSAny? is an instanceof constructor.
instanceOfString(String constructorName) bool

Available on JSAny?, provided by the JSAnyUtilityExtension extension

Whether this JSAny? is an instanceof the constructor that is defined by constructorName, which is looked up in the globalContext.
isA<T extends JSAny?>() bool

Available on JSAny?, provided by the JSAnyUtilityExtension extension

Whether this JSAny? is an instance of the JavaScript type that is declared by T.
lessThan(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this < any in JavaScript.
lessThanOrEqualTo(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this <= any in JavaScript.
modulo(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this % any in JavaScript.
multiply(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this * any in JavaScript.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notEquals(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this != any in JavaScript.
or(JSAny? any) JSAny?

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this || any in JavaScript.
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
setProperty(JSAny property, JSAny? value) → void

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Write the value of property key property of this JSObject.
setTimeout(TimerHandler handler, JSAny? arguments, [int timeout]) int
inherited
skipWaiting() JSPromise<JSAny?>
@AvailableInWorkers("service")
strictEquals(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this === any in JavaScript.
strictNotEquals(JSAny? any) JSBoolean

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this !== any in JavaScript.
structuredClone(JSAny? value, [StructuredSerializeOptions options]) JSAny?
inherited
subtract(JSAny? any) JSAny

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this - any in JavaScript.
toString() String
A string representation of this object.
inherited
typeofEquals(String typeString) bool

Available on JSAny?, provided by the JSAnyUtilityExtension extension

Whether the result of typeof on this JSAny? is typeString.
unsignedRightShift(JSAny? any) JSNumber

Available on JSAny?, provided by the JSAnyOperatorExtension extension

The result of this >>> any in JavaScript.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator [](String property) JSAny?

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Shorthand helper for getProperty to get the value of the property key property of this JSObject, but takes and returns a Dart value.
operator []=(String property, JSAny? value) → void

Available on JSObject, provided by the JSObjectUnsafeUtilExtension extension

Shorthand helper for setProperty to write the value of the property key property of this JSObject, but takes a Dart value.