matchAll() 方法在 Clients interface returns a Promise for a list of service worker Client objects. Include the 选项 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.

句法

self.clients.matchAll(options).then(function(clients) {
  // do something with your clients list
});
					

参数

选项 可选
An options object allowing you to set options for the matching operation. Available options are:
  • includeUncontrolled : A 布尔 — 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 is false .
  • type : Sets the type of clients you want matched. Available values are "window" , "worker" , "sharedworker" ,和 "all" 。默认为 "all" .

返回值

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.

范例

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
    }
  }
});
					

规范

规范 状态 注释
服务工作者
The definition of 'Clients: matchall' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
matchAll Chrome 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Edge ≤79 注意事项
≤79 注意事项
Client objects returned in most recent focus order.
Firefox 44 注意事项
44 注意事项
Extended Support Releases (ESR) before Firefox 78 ESR do not support service workers and the Push API.
54 注意事项
Client objects returned in most recent focus order.
IE 不支持 No Opera 32 Safari 不支持 No WebView Android 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Chrome Android 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Firefox Android 44
44
54 注意事项
Client objects returned in most recent focus order.
Opera Android 32 Safari iOS 不支持 No Samsung Internet Android 4.0 注意事项
4.0 注意事项
Client objects returned in most recent focus order.
includeUncontrolled option Chrome 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Edge ≤79 注意事项
≤79 注意事项
Client objects returned in most recent focus order.
Firefox 45 注意事项
45 注意事项
includeUncontrolled 支持。
IE 不支持 No Opera 38 Safari 不支持 No WebView Android 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Chrome Android 47 注意事项
47 注意事项
Client objects returned in most recent focus order.
Firefox Android 45 注意事项
45 注意事项
includeUncontrolled 支持。
Opera Android 41 Safari iOS 不支持 No Samsung Internet Android 5.0 注意事项
5.0 注意事项
Client objects returned in most recent focus order.

图例

完整支持

完整支持

不支持

不支持

实验。期望将来行为有所改变。

实验。期望将来行为有所改变。

见实现注意事项。

元数据

  • 最后修改:
  1. 服务工作者 API
  2. Clients
  3. 方法
    1. claim()
    2. get()
    3. matchAll()
    4. openWindow()
  4. Related pages for Service Workers API
    1. 缓存
    2. CacheStorage
    3. Client
    4. ExtendableEvent
    5. FetchEvent
    6. InstallEvent
    7. Navigator.serviceWorker
    8. NotificationEvent
    9. PeriodicSyncEvent
    10. PeriodicSyncManager
    11. PeriodicSyncRegistration
    12. ServiceWorker
    13. ServiceWorkerContainer
    14. ServiceWorkerGlobalScope
    15. ServiceWorkerRegistration
    16. SyncEvent
    17. SyncManager
    18. SyncRegistration
    19. WindowClient

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1