ServiceWorkerGlobalScope

@native @JSType

The ServiceWorkerGlobalScope interface of the ServiceWorker 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.onfetch or ServiceWorkerGlobalScope.onmessage.

Additionally, synchronous requests are not allowed from within a service worker — only asynchronous requests, like those initiated via the fetch() method, can be used.

Companion:
object
class Object
trait Any
class Object
trait Matchable
class Any

Value members

Concrete methods

Returns the Clients object associated with the service worker.

Returns the Clients object associated with the service worker.

The registration read-only property of the ServiceWorkerGlobalScope interface returns a reference to the ServiceWorkerRegistration object, which represents the service worker's registration.

The registration read-only property of the ServiceWorkerGlobalScope interface returns a reference to the ServiceWorkerRegistration object, which represents the service worker's registration.

def skipWaiting(): Promise[Unit]

Forces the waiting service worker to become the active service worker. This method can be used with Clients.claim to ensure that updates to the underlying service worker take effect immediately for both the current client and all other active clients.

Forces the waiting service worker to become the active service worker. This method can be used with Clients.claim to ensure that updates to the underlying service worker take effect immediately for both the current client and all other active clients.

Inherited methods

def addEventListener[T <: Event](`type`: String, listener: Function1[T, _], options: EventListenerOptions): Unit

The EventTarget.addEventListener() method registers the specified listener on the EventTarget it's called on. The event target may be an Element in a document, the Document itself, a Window, or any other object that supports events (such as XMLHttpRequest).

The EventTarget.addEventListener() method registers the specified listener on the EventTarget it's called on. The event target may be an Element in a document, the Document itself, a Window, or any other object that supports events (such as XMLHttpRequest).

This implementation accepts a settings object of type EventListenerOptions.

Inherited from:
EventTarget
def addEventListener[T <: Event](`type`: String, listener: Function1[T, _], useCapture: Boolean): Unit

The EventTarget.addEventListener() method registers the specified listener on the EventTarget it's called on. The event target may be an Element in a document, the Document itself, a Window, or any other object that supports events (such as XMLHttpRequest).

The EventTarget.addEventListener() method registers the specified listener on the EventTarget it's called on. The event target may be an Element in a document, the Document itself, a Window, or any other object that supports events (such as XMLHttpRequest).

Inherited from:
EventTarget
def atob(encodedString: String): String

Decodes a string of data which has been encoded using base-64 encoding.

Decodes a string of data which has been encoded using base-64 encoding.

Inherited from:
WindowBase64
def btoa(rawString: String): String

Creates a base-64 encoded ASCII string from a "string" of binary data.

Creates a base-64 encoded ASCII string from a "string" of binary data.

Inherited from:
WindowBase64
def caches: UndefOr[CacheStorage]

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.

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.

Inherited from:
WindowOrWorkerGlobalScope
def clearInterval(handle: Int): Unit

Cancels repeated action which was set up using setInterval.

Cancels repeated action which was set up using setInterval.

Inherited from:
WindowTimers
def clearTimeout(handle: Int): Unit

Clears the delay set by window.setTimeout().

Clears the delay set by window.setTimeout().

Inherited from:
WindowTimers
def close(): Unit

The close() method of the WorkerGlobalScope interface discards any tasks queued in the WorkerGlobalScope's event loop, effectively closing this particular scope.

The close() method of the WorkerGlobalScope interface discards any tasks queued in the WorkerGlobalScope's event loop, effectively closing this particular scope.

Inherited from:
WorkerGlobalScope
def createImageBitmap(image: CreateImageBitmapInput, sx: Double, sy: Double, sw: Double, sh: Double, options: CreateImageBitmapOptions): Promise[ImageBitmap]
def createImageBitmap(image: CreateImageBitmapInput, sx: Double, sy: Double, sw: Double, sh: Double): Promise[ImageBitmap]

Accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.

Accepts a variety of different image sources, and returns a Promise which resolves to an ImageBitmap. Optionally the source is cropped to the rectangle of pixels originating at (sx, sy) with width sw, and height sh.

Inherited from:
WindowOrWorkerGlobalScope
def crossOriginIsolated: Boolean

Returns a boolean value that indicates whether a SharedArrayBuffer can be sent via a Window.postMessage() call.

Returns a boolean value that indicates whether a SharedArrayBuffer can be sent via a Window.postMessage() call.

Inherited from:
WindowOrWorkerGlobalScope
def dispatchEvent(evt: Event): Boolean

Dispatches an Event at the specified EventTarget, invoking the affected EventListeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) apply to events dispatched manually with dispatchEvent().

Dispatches an Event at the specified EventTarget, invoking the affected EventListeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) apply to events dispatched manually with dispatchEvent().

Inherited from:
EventTarget
def fetch(info: RequestInfo, init: RequestInit): Promise[Response]

Starts the process of fetching a resource from the network.

Starts the process of fetching a resource from the network.

Inherited from:
WindowOrWorkerGlobalScope
def hasOwnProperty(v: String): Boolean
Inherited from:
Object
def importScripts(urls: Array[String]): Unit

The importScripts() method of the WorkerGlobalScope interface imports one or more scripts into the worker's scope.

The importScripts() method of the WorkerGlobalScope interface imports one or more scripts into the worker's scope.

Inherited from:
WorkerGlobalScope
def indexedDB: UndefOr[IDBFactory]

Provides a mechanism for applications to asynchronously access capabilities of indexed databases.

Provides a mechanism for applications to asynchronously access capabilities of indexed databases.

Inherited from:
WindowOrWorkerGlobalScope
def isPrototypeOf(v: Object): Boolean
Inherited from:
Object
def isSecureContext: Boolean

Returns a boolean indicating whether the current context is secure or not.

Returns a boolean indicating whether the current context is secure or not.

Inherited from:
WindowOrWorkerGlobalScope

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.

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.

Inherited from:
WorkerGlobalScope
def origin: String

Returns the origin of the global scope, serialized as a string.

Returns the origin of the global scope, serialized as a string.

Inherited from:
WindowOrWorkerGlobalScope
def propertyIsEnumerable(v: String): Boolean
Inherited from:
Object
def queueMicrotask(function: Function0[Any]): Unit

Enqueues a microtask—a short function to be executed after execution of the JavaScript code completes and control isn't being returned to a JavaScript caller, but before handling callbacks and other tasks.

Enqueues a microtask—a short function to be executed after execution of the JavaScript code completes and control isn't being returned to a JavaScript caller, but before handling callbacks and other tasks.

This lets your code run without interfering with other, possibly higher priority, code, but before the browser runtime regains control, potentially depending upon the work you need to complete.

Inherited from:
WindowOrWorkerGlobalScope
def removeEventListener[T <: Event](`type`: String, listener: Function1[T, _], options: EventListenerOptions): Unit

Removes the event listener previously registered with EventTarget.addEventListener.

Removes the event listener previously registered with EventTarget.addEventListener.

This implementation accepts a settings object of type EventListenerOptions.

Inherited from:
EventTarget
def removeEventListener[T <: Event](`type`: String, listener: Function1[T, _], useCapture: Boolean): Unit

Removes the event listener previously registered with EventTarget.addEventListener.

Removes the event listener previously registered with EventTarget.addEventListener.

Inherited from:
EventTarget

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.

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.

Inherited from:
WorkerGlobalScope
def setInterval(handler: Function0[Any], timeout: Double): Int

Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function.

Calls a function or executes a code snippet repeatedly, with a fixed time delay between each call to that function.

Inherited from:
WindowTimers
def setTimeout(handler: Function0[Any], timeout: Double): Int

Calls a function or executes a code snippet after a specified delay.

Calls a function or executes a code snippet after a specified delay.

Inherited from:
WindowTimers
def toLocaleString(): String
Inherited from:
Object
def valueOf(): Any
Inherited from:
Object

Concrete fields

var onactivate: Function1[ExtendableEvent, _]

An event handler fired whenever an activate event occurs (when the service worker activates). This happens after installation, when the page to be controlled by the service worker refreshes.

An event handler fired whenever an activate event occurs (when the service worker activates). This happens after installation, when the page to be controlled by the service worker refreshes.

var onfetch: Function1[FetchEvent, _]

An event handler fired whenever a fetch event occurs — when a fetch() is called.

An event handler fired whenever a fetch event occurs — when a fetch() is called.

var oninstall: Function1[ExtendableEvent, _]

An event handler fired whenever an install event occurs — when a ServiceWorkerRegistration acquires a new ServiceWorkerRegistration.installing worker.

An event handler fired whenever an install event occurs — when a ServiceWorkerRegistration acquires a new ServiceWorkerRegistration.installing worker.

var onmessage: Function1[MessageEvent, _]

An event handler fired whenever a message event occurs — when incoming messages are received. Controlled pages can use the MessagePort.postMessage method to send messages to service workers. The service worker can optionally send a response back via the MessagePort exposed in event.data.port, corresponding to the controlled page.

An event handler fired whenever a message event occurs — when incoming messages are received. Controlled pages can use the MessagePort.postMessage method to send messages to service workers. The service worker can optionally send a response back via the MessagePort exposed in event.data.port, corresponding to the controlled page.

var onpush: Function1[PushEvent, _]

The ServiceWorkerGlobalScope.onpush event of the ServiceWorkerGlobalScope interface is fired whenever a push message is received by a service worker via a push server.

The ServiceWorkerGlobalScope.onpush event of the ServiceWorkerGlobalScope interface is fired whenever a push message is received by a service worker via a push server.

The ServiceWorkerGlobalScope.onpushsubscriptionchange event of the ServiceWorkerGlobalScope interface is fired whenever a push subscription has been invalidated (or is about to become so). This offers an opportunity to resubscribe in order to continue receiving push messages, if desired. This might happen if, for example, the push service sets an expiration time a subscription.

The ServiceWorkerGlobalScope.onpushsubscriptionchange event of the ServiceWorkerGlobalScope interface is fired whenever a push subscription has been invalidated (or is about to become so). This offers an opportunity to resubscribe in order to continue receiving push messages, if desired. This might happen if, for example, the push service sets an expiration time a subscription.

Inherited fields

var onError: Function1[ErrorEvent, _]

The onerror property of the WorkerGlobalScope interface represents an EventHandler to be called when the error event occurs and bubbles through the Worker.

The onerror property of the WorkerGlobalScope interface represents an EventHandler to be called when the error event occurs and bubbles through the Worker.

Inherited from:
WorkerGlobalScope
var onlanguagechange: Function1[Event, _]

The onlanguagechange property of the WorkerGlobalScope interface represents an EventHandler to be called when the languagechange event occurs and bubbles through the Worker.

The onlanguagechange property of the WorkerGlobalScope interface represents an EventHandler to be called when the languagechange event occurs and bubbles through the Worker.

Inherited from:
WorkerGlobalScope
var onoffline: Function1[Event, _]

The onoffline property of the WorkerGlobalScope interface represents an EventHandler to be called when the offline event occurs and bubbles through the Worker.

The onoffline property of the WorkerGlobalScope interface represents an EventHandler to be called when the offline event occurs and bubbles through the Worker.

Inherited from:
WorkerGlobalScope
var ononline: Function1[Event, _]

The ononline property of the WorkerGlobalScope interface represents an EventHandler to be called when the online event occurs and bubbles through the Worker.

The ononline property of the WorkerGlobalScope interface represents an EventHandler to be called when the online event occurs and bubbles through the Worker.

Inherited from:
WorkerGlobalScope