Clients.matchAll() - Web APIs 编辑
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
self.clients.matchAll(options).then(function(clients) { // do something with your clients list });
Parameters
options
Optional- An options object allowing you to set options for the matching operation. Available options are:
includeUncontrolled
: ABoolean
— if set totrue
, 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
A Promise
that resolves to an array of Client
objects. In Chrome 46/Firefox 54 and later, this method returns clients in most recently focused order, correct as per spec.
Examples
clients.matchAll(options).then(function(clientList) {
for (var i = 0 ; i < clientList.length ; i++) {
if (clientList[i].url === 'index.html') {
clients.openWindow(clientList[i]);
// or do something else involving the matching client
}
}
});
Specifications
Specification | Status | Comment |
---|---|---|
Service Workers The definition of 'Clients: matchall' in that specification. | Working Draft | Initial definition |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论