ServiceWorker Class
A service worker (https://w3c.github.io/ServiceWorker/#serviceworker-interface), as seen by a window or a worker: its script URL, its state, and the messages posted to it. Each global object has its own object per service worker.
public sealed class ServiceWorker : EventTarget- Inheritance
EventTargetServiceWorker
Properties
| Name | Description |
|---|---|
| OnError | Gets or sets the event handler of the error event. |
| OnStateChange | Gets or sets the event handler of the statechange event. |
| ScriptUrl | Gets the URL of the script of the service worker. |
| State | Gets the state of the service worker, as last set by a statechange task. |
OnError
ServiceWorker.csGets or sets the event handler of the error event.
OnStateChange
ServiceWorker.csGets or sets the event handler of the statechange event.
Property value
See also
ScriptUrl
ServiceWorker.csGets the URL of the script of the service worker.
public string ScriptUrl { get; }State
ServiceWorker.csGets the state of the service worker, as last set by a statechange task.
public ServiceWorkerState State { get; }Property value
See also
Methods
| Name | Description |
|---|---|
| PostMessage(object?, StructuredSerializeOptions?) | Posts a message to the service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworker-postmessage-message-options). |
| PostMessage(object?, IReadOnlyList<object>) | Posts a message to the service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworker-postmessage). |
PostMessage overloads
PostMessage(object?, StructuredSerializeOptions?)
ServiceWorker.csPosts a message to the service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworker-postmessage-message-options).
public void PostMessage(object? message, StructuredSerializeOptions? options = null)Parameters
messageobject?optionsStructuredSerializeOptions?
Exceptions
DomException- A
DataCloneErrorwhen the message cannot be serialized, or anInvalidStateErrorwhen the document of the window of the object is not fully active (e.g. its iframe was removed).
See also
PostMessage(object?, IReadOnlyList<object>)
ServiceWorker.csPosts a message to the service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworker-postmessage).
public void PostMessage(object? message, IReadOnlyList<object> transfer)