Clients.matchAll()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2018年4月.
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
— 如果设置为true
, 匹配操作将返回与当前服务工作者共享相同源的所有服务工作者客户端。否则,它仅返回由当前服务工作者控制的服务工作者客户端。默认值为false
.type
: 设置想要匹配的 clients 类型。可用值包括window
,worker
,sharedworker
, 和all
. 默认是all
.
返回值
resolve 为一个 Client
对象数组的 Promise
. 在 Chrome 46/Firefox 54 以及更高版本中,该方法以最近关注的顺序返回 clients , 根据规范更正。
示例
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> |
浏览器兼容性
Loading…