Table of Contents

Class Clients

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The Clients interface provides access to Client objects. Access it via {{domxref("ServiceWorkerGlobalScope", "self")}}.clients within a service worker.

[Value("Clients")]
public class Clients
Inheritance
Clients
Inherited Members

Remarks

Constructors

Clients()

public Clients()

Methods

Claim()

The claim() method of the Clients interface allows an active service worker to set itself as the Controller for all clients within its Scope.
This triggers a controllerchange event on ServiceWorkerContainer in any clients that become controlled by this service worker.

[Value("claim")]
public Task<GlobalObject.Undefined> Claim()

Returns

Task<GlobalObject.Undefined>

A Promise that resolves to undefined.

Remarks

When a service worker is initially registered, pages won&apos;t use it until they next
load. The claim() method causes those pages to be controlled immediately.
Be aware that this results in your service worker controlling pages that loaded
regularly over the network, or possibly via a different service worker.

-Using Service Workers
-The service worker lifecycle
-SkipWaiting() - skip the service worker's waiting phase

See also on MDN

Get(string)

The get() method of the
Clients interface gets a service worker client matching a given
id and returns it in a Promise.

[Value("get")]
public Task<Client> Get(string id)

Parameters

id string

Returns

Task<Client>

A {{jsxref("Promise")}} that resolves to a Client object or
undefined.

Remarks

MatchAll(ClientQueryOptions)

The matchAll() method of the Clients
interface returns a Promise for a list of service worker
Client objects. Include the options parameter to return all service worker
clients whose origin is the same as the associated service worker&apos;s origin. If options
are not included, the method returns only the service worker clients controlled by the
service worker.

[Value("matchAll")]
public Task<Client[]> MatchAll(ClientQueryOptions options = null)

Parameters

options ClientQueryOptions

Returns

Task<Client[]>

A {{jsxref("Promise")}} that resolves to an array of Client objects. In
Chrome 46/Firefox 54 and later, this method returns clients in most recently focused
order, correct as per spec.

Remarks

OpenWindow(string)

The openWindow() method of the Clients
interface creates a new top level browsing context and loads a given URL. If the calling
script doesn&apos;t have permission to show popups, openWindow() will throw an
InvalidAccessError.

[Value("openWindow")]
public Task<WindowClient?> OpenWindow(string url)

Parameters

url string

Returns

Task<WindowClient>

A {{jsxref("Promise")}} that resolves to a WindowClient object if the
URL is from the same origin as the service worker or a null otherwise.

Remarks

In Firefox, the method is allowed to show popups only when called as the result of a
notification click event.

In Chrome for Android, the method may instead open the URL in an existing browsing
context provided by a standalone web app previously added to the user&apos;s home screen. As of recently, this also works on
Chrome for Windows.

See also on MDN