This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The Clients interface provides access to Client objects. Access it via self.clients within a service worker.

Methods

Clients.get()
Returns a Promise for a Client matching a given id.
Clients.matchAll()
Returns a Promise for an array of Client objects. An options argument allows you to control the types of clients returned. 
Clients.openWindow()
Opens a new browser window for a given url and returns a Promise for the new WindowClient.
Clients.claim()
Allows an active service worker to set itself as the controller for all clients within its scope

Examples

The following example shows an existing chat window or creates a new one when the user clicks a notification.

addEventListener('notificationclick', event => {
  event.waitUntil(async function() {
    const allClients = await clients.matchAll({
      includeUncontrolled: true
    });

    let chatClient;

    // Let's see if we already have a chat window open:
    for (const client of allClients) {
      const url = new URL(client.url);

      if (url.pathname == '/chat/') {
        // Excellent, let's use it!
        client.focus();
        chatClient = client;
        break;
      }
    }

    // If we didn't find an existing chat window,
    // open a new one:
    if (!chatClient) {
      chatClient = await clients.openWindow('/chat/');
    }

    // Message the client:
    chatClient.postMessage("New chat messages!");
  }());
});

Specifications

Specification Status Comment
Service Workers
The definition of 'Clients' in that specification.
Working Draft Initial definition

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support40 ?441 No27 No
claim42 ?441 No29 No
get51 ?451 No38 No
matchAll472 ?

441

542

No32 No
openWindow

40

423

434

515

?451 No38 No
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support4040 ?4427 No4.0
claim4242 ?4429 No4.0
get No51 ?4538 No5.0
matchAll472472 ?

44

542

32 No4.0
openWindow

40

423

434

515

40

423

434

515

?4538 No

4.0

5.05

1. Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).

2. Client objects returned in most recent focus order.

3. Can only open URLs on the same origin.

4. Can open any URL.

5. URLs may open inside an existing browsing context provided by a standalone web app

See also

Document Tags and Contributors

Last updated by: fscholz,