| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/docs/Web/API/Clients | [Back] [Original] |
Get to know MDN better
This feature is well established and works across many devices and browser versions. Its 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 within a service worker.self.clients
Clients.get()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.
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 () => {
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!");
})(),
);
});
| Specification |
|---|
| Service Workers Nightly # clients-interface |
This page was last modified on May 23, 2025 by MDN contributors.
ClientsYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |