Clients: matchAll() method
Note: This feature is only available in Service Workers.
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's origin. If options
are not included, the method returns only the service worker clients controlled by the
service worker.
Syntax
matchAll()
matchAll(options)
Parameters
options
Optional-
An options object allowing you to set options for the matching operation. Available options are:
includeUncontrolled
-
A boolean value — if set to
true
, the matching operation will return all service worker clients who share the same origin as the current service worker. Otherwise, it returns only the service worker clients controlled by the current service worker. The default isfalse
. type
-
Sets the type of clients you want matched. Available values are
"window"
,"worker"
,"sharedworker"
, and"all"
. The default is"window"
.
Return value
Examples
clients.matchAll(options).then((clientList) => {
for (const client of clientList) {
if (client.url === "index.html") {
clients.openWindow(client);
// or do something else involving the matching client
}
}
});
Specifications
Specification |
---|
Service Workers # clients-matchall |
Browser compatibility
BCD tables only load in the browser