这篇翻译不完整。请帮忙从英语翻译这篇文章

这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

Clients 接口提供对 Client 对象的访问. 通过在  service worker 中使用 self.clients 访问它.

方法

Clients.get()
返回一个匹配给定 id 的 Client 的 Promise .
Clients.matchAll()
返回一个 Client 对象数组的 Promise . options参数允许您控制返回的clients类型. 
Clients.openWindow()
打开给定URL的新浏览器窗口,并返回新 WindowClient a 的 Promise .
Clients.claim()
允许一个激活的 service worker 将自己设置为其scope 内所有 clients 的 controller

示例

下面示例显示一个已有的聊天窗口,或者当用户点击通知时创建新的窗口.

addEventListener('notificationclick', event => {
  event.waitUntil(async function() {
    const allClients = await clients.matchAll({
      includeUncontrolled: true
    });

    let chatClient;

    // Let's see if we already have a chat window open:
    for (const client of allClients) {
      const url = new URL(client.url);

      if (url.pathname == '/chat/') {
        // Excellent, let's use it!
        client.focus();
        chatClient = client;
        break;
      }
    }

    // If we didn't find an existing chat window,
    // open a new one:
    if (!chatClient) {
      chatClient = await clients.openWindow('/chat/');
    }

    // Message the client:
    chatClient.postMessage("New chat messages!");
  }());
});

规范

Specification Status Comment
Service Workers
Clients
Working Draft Initial definition

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic support
Experimental
Chrome Full support 40Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 27Safari No support NoWebView Android Full support 40Chrome Android Full support 40Edge Mobile ? Firefox Android Full support 44Opera Android Full support 27Safari iOS No support NoSamsung Internet Android Full support 4.0
claim
Experimental
Chrome Full support 42Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 29Safari No support NoWebView Android Full support 42Chrome Android Full support 42Edge Mobile ? Firefox Android Full support 44Opera Android Full support 29Safari iOS No support NoSamsung Internet Android Full support 4.0
get
Experimental
Chrome Full support 51Edge ? Firefox Full support 45
Notes
Full support 45
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 38Safari No support NoWebView Android No support NoChrome Android Full support 51Edge Mobile ? Firefox Android Full support 45Opera Android Full support 38Safari iOS No support NoSamsung Internet Android Full support 5.0
matchAll
Experimental
Chrome Full support 47
Notes
Full support 47
Notes
Notes Client objects returned in most recent focus order.
Edge ? Firefox Full support 44
Notes
Full support 44
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
Full support 54
Notes
Notes Client objects returned in most recent focus order.
IE No support NoOpera Full support 32Safari No support NoWebView Android Full support 47
Notes
Full support 47
Notes
Notes Client objects returned in most recent focus order.
Chrome Android Full support 47
Notes
Full support 47
Notes
Notes Client objects returned in most recent focus order.
Edge Mobile ? Firefox Android Full support 44
Full support 44
Full support 54
Notes
Notes Client objects returned in most recent focus order.
Opera Android Full support 32Safari iOS No support NoSamsung Internet Android Full support 4.0
openWindow
Experimental
Chrome Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Edge ? Firefox Full support 45
Notes
Full support 45
Notes
Notes Service workers (and Push) have been disabled in the Firefox 45 & 52 Extended Support Releases (ESR).
IE No support NoOpera Full support 38Safari No support NoWebView Android Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Chrome Android Full support 40
Full support 40
Full support 42
Notes
Notes Can only open URLs on the same origin.
Full support 43
Notes
Notes Can open any URL.
Full support 51
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app
Edge Mobile ? Firefox Android Full support 45Opera Android Full support 38Safari iOS No support NoSamsung Internet Android Full support 4.0
Full support 4.0
Full support 5.0
Notes
Notes URLs may open inside an existing browsing context provided by a standalone web app

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
See implementation notes.
See implementation notes.

See also

文档标签和贡献者

此页面的贡献者: flyingsouthwind
最后编辑者: flyingsouthwind,