ServiceWorkerContainer class
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.
Properties
- controller → ServiceWorker?
-
Returns a ServiceWorker object if its state is activated (the same object
returned by ServiceWorkerRegistration.active). This property returns null
if the request is a force refresh (Shift + refresh) or if there is no
active worker.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
onControllerChange
→ Stream<
Event> -
An event handler fired whenever a controllerchange event occurs — when
the document's associated ServiceWorkerRegistration acquires a new
ServiceWorkerRegistration.active worker.
no setter
-
onError
→ Stream<
ErrorEvent> -
An event handler fired whenever an error event occurs in the associated
service workers.
no setter
-
onMessage
→ Stream<
MessageEvent> -
An event handler fired whenever a message event occurs — when incoming
messages are received to the ServiceWorkerContainer object (e.g. via a
MessagePort.postMessage() call.)
no setter
-
ready
→ Future<
ServiceWorkerRegistration> -
Defines whether a service worker is ready to control a page or not.
It returns a Promise that will never reject, which resolves to a
ServiceWorkerRegistration with an ServiceWorkerRegistration.active worker.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
addEventListener<
K> (String type, dynamic listener(K event), [bool? useCapture]) → void - Attach an event listener.
-
getRegistration(
[String? scope]) → Future< ServiceWorkerRegistration> - Gets a ServiceWorkerRegistration object whose scope URL matches the provided document URL. If the method can't return a ServiceWorkerRegistration, it returns a Promise. scope URL of the registration object you want to return. This is usually a relative URL.
-
getRegistrations(
) → Future< List< ServiceWorkerRegistration> > - Returns all ServiceWorkerRegistrations associated with a ServiceWorkerContainer in an array. If the method can't return ServiceWorkerRegistrations, it returns a Promise.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
register(
String scriptURL, [ServiceWorkerRegisterOptions? options]) → Future< ServiceWorkerRegistration> - Creates or updates a ServiceWorkerRegistration for the given scriptURL. Currently available options are: scope: A USVString representing a URL that defines a service worker's registration scope; what range of URLs a service worker can control. This is usually a relative URL, and it defaults to '/' when not specified.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
API entry point for web apps (window.navigator.serviceWorker).
final