ServiceWorkerContainer Class
The service workers of a window or a worker (https://w3c.github.io/ServiceWorker/#serviceworkercontainer-interface), navigator.serviceWorker: registers the service workers of its origin, gives the service worker that controls the client (ServiceWorkerContainer.Controller), and receives the messages of the service workers.
public sealed class ServiceWorkerContainer : EventTargetRemarks
The registrations are stored by BrowsingContextOptions.ServiceWorkers. The service workers need a script engine (BrowsingContextOptions.ScriptEngine): they run on their own thread, with their own event loop.
See also
- Inheritance
EventTargetServiceWorkerContainer
Properties
| Name | Description |
|---|---|
| Controller | Gets the service worker that controls the client (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-controller), or null. |
| OnControllerChange | Gets or sets the event handler of the controllerchange event. |
| OnMessage | Gets or sets the event handler of the message event: setting it enables the client message queue. |
| OnMessageError | Gets or sets the event handler of the messageerror event. |
| Ready | Gets a promise fulfilled with the registration of the client once it has an active worker (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-ready). |
Controller
ServiceWorkerContainer.csGets the service worker that controls the client (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-controller), or null.
public ServiceWorker? Controller { get; }Property value
See also
OnControllerChange
ServiceWorkerContainer.csGets or sets the event handler of the controllerchange event.
OnMessage
ServiceWorkerContainer.csGets or sets the event handler of the message event: setting it enables the client message queue.
Property value
See also
OnMessageError
ServiceWorkerContainer.csGets or sets the event handler of the messageerror event.
Gets a promise fulfilled with the registration of the client once it has an active worker (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-ready).
public Task<ServiceWorkerRegistration> Ready { get; }Methods
| Name | Description |
|---|---|
| GetRegistration(string) | Returns the registration whose scope matches a URL (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistration). |
| GetRegistrations() | Returns the registrations of the origin of the client (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistrations). |
| Register(TrustedScriptUrl, RegistrationOptions?) | Registers a service worker whose script URL was created by a Trusted Types policy (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-register). |
| Register(string, RegistrationOptions?) | Registers a service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-register). |
| StartMessages() | Enables the client message queue: the messages of the service workers are dispatched (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-startmessages). |
GetRegistration(string)
ServiceWorkerContainer.csReturns the registration whose scope matches a URL (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistration).
public Task<ServiceWorkerRegistration?> GetRegistration(string clientUrl = "")Parameters
clientUrlstring- The URL, relative to the API base URL of the client (the URL of the client by default).
Returns
Task<ServiceWorkerRegistration?>
See also
GetRegistrations()
ServiceWorkerContainer.csReturns the registrations of the origin of the client (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-getregistrations).
public Task<IReadOnlyList<ServiceWorkerRegistration>> GetRegistrations()Register overloads
Register(TrustedScriptUrl, RegistrationOptions?)
ServiceWorkerContainer.csRegisters a service worker whose script URL was created by a Trusted Types policy (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-register).
public Task<ServiceWorkerRegistration> Register(TrustedScriptUrl scriptUrl, RegistrationOptions? options = null)Parameters
scriptUrlTrustedScriptUrloptionsRegistrationOptions?
Returns
Task<ServiceWorkerRegistration>
See also
Register(string, RegistrationOptions?)
ServiceWorkerContainer.csRegisters a service worker (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-register).
public Task<ServiceWorkerRegistration> Register(string scriptUrl, RegistrationOptions? options = null)Parameters
scriptUrlstring- The URL of the script, relative to the API base URL of the client.
optionsRegistrationOptions?- The options: the scope, the type of the script and the update via cache mode.
Returns
Task<ServiceWorkerRegistration>
See also
StartMessages()
ServiceWorkerContainer.csEnables the client message queue: the messages of the service workers are dispatched (https://w3c.github.io/ServiceWorker/#dom-serviceworkercontainer-startmessages).
public void StartMessages()