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
EventTarget ServiceWorker

Properties

NameDescription
OnErrorGets or sets the event handler of the error event.
OnStateChangeGets or sets the event handler of the statechange event.
ScriptUrlGets the URL of the script of the service worker.
StateGets the state of the service worker, as last set by a statechange task.

Gets or sets the event handler of the error event.

public Action<Event>? OnError { get; set; }

OnStateChange

ServiceWorker.cs

Gets or sets the event handler of the statechange event.

public Action<Event>? OnStateChange { get; set; }

Gets the URL of the script of the service worker.

public string ScriptUrl { get; }

Gets the state of the service worker, as last set by a statechange task.

public ServiceWorkerState State { get; }

Methods

NameDescription
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.cs

Posts 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
message object?
options StructuredSerializeOptions?
Exceptions
DomException
A DataCloneError when the message cannot be serialized, or an InvalidStateError when 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.cs

Posts a message to the service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworker-postmessage).

public void PostMessage(object? message, IReadOnlyList<object> transfer)