Clients

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2018.

Note: This feature is only available in Service Workers.

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

Instance 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.

js
addEventListener("notificationclick", (event) => {
  event.waitUntil(
    (async () => {
      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:
      chatClient ??= await clients.openWindow("/chat/");

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

Specifications

Specification
Service Workers Nightly
# clients-interface

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Clients
Chrome – Full support
Chrome 40 (Release date: 2015-01-21)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 27 (Release date: 2015-01-27)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 40 (Release date: 2015-01-21)
footnote Full support
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 27 (Release date: 2015-01-29)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 40 (Release date: 2015-01-21)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
claim
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 29 (Release date: 2015-04-28)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote Full support
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 29 (Release date: 2015-04-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote Full support
WebView Android – Full support
WebView Android 42 (Release date: 2015-04-15)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
get
Chrome – Full support
Chrome 51 (Release date: 2016-05-25)
footnote Full support
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 51 (Release date: 2016-06-08)
footnote Full support
Firefox for Android – Full support
Firefox for Android 45 (Release date: 2016-03-08)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 5 (Release date: 2016-12-15)
footnote Full support
WebView Android – Full support
WebView Android 51 (Release date: 2016-06-08)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
matchAll
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote
footnote Client objects returned in most recent focus order.
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote
footnote Client objects returned in most recent focus order.
Firefox – Partial support
Firefox 44 – 53 (Release date: 2016-01-26)
footnote Partial support
footnote Before Firefox 54, Client objects were not returned in the most recent focus order as required by the specification.
Firefox – Full support
Firefox 54 (Release date: 2017-06-13)
footnote Full support
Opera – Full support
Opera 29 (Release date: 2015-04-28)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote
footnote Client objects returned in most recent focus order.
Firefox for Android – Partial support
Firefox for Android 44 – 53 (Release date: 2016-01-26)
footnote Partial support
footnote Before Firefox for Android 54, Client objects were not returned in the most recent focus order as required by the specification.
Firefox for Android – Full support
Firefox for Android 54 (Release date: 2017-06-13)
footnote Full support
Opera Android – Full support
Opera Android 29 (Release date: 2015-04-28)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote
footnote Client objects returned in most recent focus order.
WebView Android – Full support
WebView Android 42 (Release date: 2015-04-15)
footnote
footnote Client objects returned in most recent focus order.
WebView on iOS – No support
WebView on iOS
footnote No support
options.includeUncontrolled parameter
Chrome – Full support
Chrome 42 (Release date: 2015-04-14)
footnote
footnote Client objects returned in most recent focus order.
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote
footnote Client objects returned in most recent focus order.
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 42 (Release date: 2015-04-15)
footnote
footnote Client objects returned in most recent focus order.
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote
footnote Client objects returned in most recent focus order.
WebView Android – Full support
WebView Android 42 (Release date: 2015-04-15)
footnote
footnote Client objects returned in most recent focus order.
WebView on iOS – No support
WebView on iOS
footnote No support
openWindow
Chrome – Full support
Chrome 40 (Release date: 2015-01-21)
footnote
footnote Before Chrome 43, this method could only open URLs on the same origin.
footnote Since Chrome 51, URLs may open inside an existing browsing context provided by a standalone web app.
Edge – Full support
Edge 17 (Release date: 2018-04-30)
footnote Full support
Firefox – Full support
Firefox 44 (Release date: 2016-01-26)
footnote Full support
Opera – Full support
Opera 38 (Release date: 2016-06-08)
footnote Full support
Safari – Full support
Safari 11.1 (Release date: 2018-04-12)
footnote Full support
Chrome Android – Full support
Chrome Android 40 (Release date: 2015-01-21)
footnote
footnote Before Chrome Android 43, this method could only open URLs on the same origin.
footnote Since Chrome Android 51, URLs may open inside an existing browsing context provided by a standalone web app.
Firefox for Android – Full support
Firefox for Android 44 (Release date: 2016-01-26)
footnote Full support
Opera Android – Full support
Opera Android 41 (Release date: 2016-10-25)
footnote Full support
Safari on iOS – Full support
Safari on iOS 11.3 (Release date: 2018-03-29)
footnote Full support
Samsung Internet – Full support
Samsung Internet 4 (Release date: 2016-03-11)
footnote
footnote Before Samsung Internet 4.0, this method could only open URLs on the same origin.
footnote Since Samsung Internet 5.0, URLs may open inside an existing browsing context provided by a standalone web app.
WebView Android – Full support
WebView Android 40 (Release date: 2015-01-21)
footnote
footnote Before WebView Android 43, this method could only open URLs on the same origin.
footnote Since WebView Android 51, URLs may open inside an existing browsing context provided by a standalone web app.
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.

See also