Clients.matchAll()
Clients 接口的 matchAll() 方法返回 service worker Client 对象列表的 Promise . 包含 options 参数以返回域与关联的 service worker 的域相同所有 service worker 的 clients. 如果未包含 options,该方法仅返回由 service worker 控制的 service worker clients.
语法
js
ServiceWorkerClients.matchAll(options).then(function(clients) {
// do something with your clients list
});
参数
options 可选-
一个 options 对象,允许您为匹配操作设置选项。可用选项包括:
includeUncontrolled:Boolean(en-US) — 如果设置为true, 匹配操作将返回与当前服务工作者共享相同源的所有服务工作者客户端。否则,它仅返回由当前服务工作者控制的服务工作者客户端。默认值为false.type: 设置想要匹配的 clients 类型。可用值包括window,worker,sharedworker, 和all. 默认是all.
返回值
示例
js
clients.matchAll(options).then(function(clientList) {
for (var i = 0 ; i < clients.length ; i++) {
if (clientList[i].url === 'index.html') {
clients.openWindow(clientList[i]);
// or do something else involving the matching client
}
}
});
规范
| Specification |
|---|
| Service Workers # clients-matchall |
浏览器兼容性
BCD tables only load in the browser