Table of Contents

Class ServiceWorkerRegistration

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The ServiceWorkerRegistration interface of the Service Worker API represents the service worker registration. You register a service worker to control one or more pages that share the same origin.

[Value("ServiceWorkerRegistration")]
public class ServiceWorkerRegistration : EventTarget
Inheritance
ServiceWorkerRegistration
Inherited Members

Remarks

The lifetime of a service worker registration is beyond that of the ServiceWorkerRegistration objects that represent them within the lifetime of their corresponding service worker clients. The browser maintains a persistent list of active ServiceWorkerRegistration objects.

-Using Service Workers
-Service workers basic code example
-Using web workers

See also on MDN

Constructors

ServiceWorkerRegistration()

public ServiceWorkerRegistration()

Properties

Active

The active read-only property of the
ServiceWorkerRegistration interface returns a service worker whose
State is activating or activated.
This property is initially set to null.

[Value("active")]
public ServiceWorker? Active { get; }

Property Value

ServiceWorker

A ServiceWorker object's property, if it is currently in an
activating or activated state.

Remarks

An active worker controls a Client if the client's URL
falls within the scope of the registration (the scope option set when
Register(Union137, RegistrationOptions) is first called.)

NOTE

Once an active worker is activating, neither a
runtime script error nor a force termination of the active worker prevents the active
worker from getting activated.

-Using Service Workers
-Service workers basic code example
-Using web workers

See also on MDN

BackgroundFetch

NOTE
Experimental
The backgroundFetch read-only property of the
ServiceWorkerRegistration interface returns a reference to a
BackgroundFetchManager object, which can be used to initiate background fetch operations.
[Value("backgroundFetch")]
public BackgroundFetchManager BackgroundFetch { get; }

Property Value

BackgroundFetchManager

A BackgroundFetchManager object.

Remarks

Cookies

The cookies read-only property of the ServiceWorkerRegistration interface returns a reference to the CookieStoreManager interface, which enables a web app to subscribe to and unsubscribe from cookie change events in a service worker. This is an entry point for the Cookie Store API.

[Value("cookies")]
public CookieStoreManager Cookies { get; }

Property Value

CookieStoreManager

A CookieStoreManager object.

Remarks

Index

NOTE
Experimental
The index read-only property of the
ServiceWorkerRegistration interface returns a reference to the
'ContentIndex' interface, which allows for indexing of offline content.
[Value("index")]
public ContentIndex Index { get; }

Property Value

ContentIndex

A 'ContentIndex' object.

Remarks

Installing

The installing read-only property of the
ServiceWorkerRegistration interface returns a service worker whose
State is installing. This property is
initially set to null.

[Value("installing")]
public ServiceWorker? Installing { get; }

Property Value

ServiceWorker

A ServiceWorker object, if it is currently in an installing
state.

Remarks

NavigationPreload

The navigationPreload read-only property of the ServiceWorkerRegistration interface returns the NavigationPreloadManager associated with the current service worker registration.

[Value("navigationPreload")]
public NavigationPreloadManager NavigationPreload { get; }

Property Value

NavigationPreloadManager

An instance of NavigationPreloadManager.

Remarks

The returned object allows resources managed by a service worker to be preemptively downloaded in parallel with service worker boot up.

See also on MDN

Onupdatefound

[Value("onupdatefound")]
public EventHandlerNonNull Onupdatefound { get; set; }

Property Value

EventHandlerNonNull

PaymentManager

NOTE
Experimental
The paymentManager read-only property of the
ServiceWorkerRegistration interface returns a payment app's PaymentManager instance, which is used to manage various payment app functionality.
[Value("paymentManager")]
public PaymentManager PaymentManager { get; }

Property Value

PaymentManager

A PaymentManager object instance.

Remarks

PeriodicSync

NOTE
Experimental
The periodicSync read-only property of
the ServiceWorkerRegistration interface returns a reference to the
'PeriodicSyncManager' interface, which allows for registering of tasks to
run at specific intervals.
[Value("periodicSync")]
public PeriodicSyncManager PeriodicSync { get; }

Property Value

PeriodicSyncManager

A 'PeriodicSyncManager' object.

Remarks

PushManager

The pushManager read-only property of the
ServiceWorkerRegistration interface returns a reference to the
PushManager interface for managing push subscriptions; this includes
support for subscribing, getting an active subscription, and accessing push permission
status.

[Value("pushManager")]
public PushManager PushManager { get; }

Property Value

PushManager

A PushManager object.

Remarks

Scope

The scope read-only property of the ServiceWorkerRegistration interface returns a string representing a URL that defines a service worker's registration scope; that is, the range of URLs a service worker can control. This is set using the scope parameter specified in the call to 'ServiceWorkerContainer.Register' which registered the service worker.

[Value("scope")]
public string Scope { get; }

Property Value

string

Returns a string representing a URL that defines a service worker's registration scope.

Remarks

Sync

The sync read-only property of the
ServiceWorkerRegistration interface returns a reference to the
SyncManager interface, which manages background synchronization
processes.

[Value("sync")]
public SyncManager Sync { get; }

Property Value

SyncManager

A SyncManager object.

Remarks

UpdateViaCache

The updateViaCache read-only property of the ServiceWorkerRegistration interface returns the value of the setting used to determine the circumstances in which the browser will consult the HTTP cache when it tries to update the service worker or any scripts that are imported via ImportScripts(params Union95[]).

[Value("updateViaCache")]
public ServiceWorkerUpdateViaCache UpdateViaCache { get; }

Property Value

ServiceWorkerUpdateViaCache

Returns one of the following values:

Remarks

Waiting

The waiting read-only property of the
ServiceWorkerRegistration interface returns a service worker whose
State is installed. This property is initially
set to null.

[Value("waiting")]
public ServiceWorker? Waiting { get; }

Property Value

ServiceWorker

A ServiceWorker object, if it is currently in an installed
state.

Remarks

Methods

GetNotifications(GetNotificationOptions)

The getNotifications() method of
the ServiceWorkerRegistration interface returns a list of the
notifications in the order that they were created from the current origin via the
current service worker registration. Origins can have many active but
differently-scoped service worker registrations. Notifications created by one service
worker on the same origin will not be available to other active service workers on
that same origin.

[Value("getNotifications")]
public Task<List<Notification>> GetNotifications(GetNotificationOptions filter = null)

Parameters

filter GetNotificationOptions

Returns

Task<List<Notification>>

A {{jsxref("Promise")}} that resolves to a list of Notification objects.

Remarks

ShowNotification(string, NotificationOptions)

The showNotification() method of the
ServiceWorkerRegistration interface creates a notification on an active
service worker.

[Value("showNotification")]
public Task<GlobalObject.Undefined> ShowNotification(string title, NotificationOptions options = null)

Parameters

title string
options NotificationOptions

Returns

Task<GlobalObject.Undefined>

A 'Promise' that resolves to undefined.

Remarks

Unregister()

The unregister() method of the
ServiceWorkerRegistration interface unregisters the service worker
registration and returns a Promise. The promise will resolve to
false if no registration was found, otherwise it resolves to
true irrespective of whether unregistration happened or not (it may not
unregister if someone else just called Register(Union137, RegistrationOptions)
with the same scope.) The service worker will finish any ongoing operations before it is
unregistered.

[Value("unregister")]
public Task<bool> Unregister()

Returns

Task<bool>

Promise resolves with a boolean indicating whether the service worker has
unregistered or not.

Remarks

Update()

The update() method of the
ServiceWorkerRegistration interface attempts to update the service
worker. It fetches the worker&apos;s script URL, and if the new worker is not byte-by-byte
identical to the current worker, it installs the new worker. The fetch of the worker
bypasses any browser caches if the previous fetch occurred over 24 hours ago.

[Value("update")]
public Task<GlobalObject.Undefined> Update()

Returns

Task<GlobalObject.Undefined>

A {{jsxref("Promise")}} that resolves with a ServiceWorkerRegistration
object.

Remarks