The ServiceWorkerContainer interface of the ServiceWorker API provides an object representing the service worker as an overall unit in the network ecosystem, including facilities to register, unregister and update service workers, and access the state of service workers and their registrations.

Documentation ServiceWorkerContainer by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Variables

read onlycontroller:ServiceWorker

Returns a ServiceWorker object if its state is activated (the same object returned by ServiceWorkerRegistration.active). This property returns null during a force-refresh request (Shift + refresh) or if there is no active worker.

oncontrollerchange:Function

Fired whenever a controllerchange event occurs — when the document's associated ServiceWorkerRegistration acquires a new ServiceWorkerRegistration.active worker.

onerror:Function

Fired whenever an error event occurs in the associated service workers.

onmessage:Function

Fired whenever a message event occurs — when incoming messages are received to the ServiceWorkerContainer object (e.g. via a MessagePort.postMessage() call.)

read onlyready:Promise<ServiceWorkerRegistration>

Provides a way of delaying code execution until a service worker is active. It returns a Promise that will never reject, and which waits indefinitely until the ServiceWorkerRegistration associated with the current page has an ServiceWorkerRegistration.active worker. Once that condition is met, it resolves with the ServiceWorkerRegistration.

Methods

@:value({ documentURL : "" })getRegistration(documentURL:String = ""):Promise<Dynamic>

Gets a ServiceWorkerRegistration object whose scope matches the provided document URL.  If the method can't return a ServiceWorkerRegistration, it returns a Promise

getRegistrations():Promise<Array<ServiceWorkerRegistration>>

Returns all ServiceWorkerRegistration objects associated with a ServiceWorkerContainer in an array.  If the method can't return ServiceWorkerRegistration objects, it returns a Promise

Inherited Variables

Inherited Methods

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

Register an event handler of a specific event type on the EventTarget.

Throws:

null

DOMError

dispatchEvent(event:Event):Bool

Dispatch an event to this EventTarget.

Throws:

null

DOMError

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes an event listener from the EventTarget.

Throws:

null

DOMError