service worker self clients

Solutions on MaxInterview for service worker self clients by the best coders in the world

showing results for - "service worker self clients"
Miriam
26 May 2018
1addEventListener('notificationclick', event => {
2  event.waitUntil(async function() {
3    const allClients = await clients.matchAll({
4      includeUncontrolled: true
5    });
6
7    let chatClient;
8
9    // Let's see if we already have a chat window open:
10    for (const client of allClients) {
11      const url = new URL(client.url);
12
13      if (url.pathname == '/chat/') {
14        // Excellent, let's use it!
15        client.focus();
16        chatClient = client;
17        break;
18      }
19    }
20
21    // If we didn't find an existing chat window,
22    // open a new one:
23    if (!chatClient) {
24      chatClient = await clients.openWindow('/chat/');
25    }
26
27    // Message the client:
28    chatClient.postMessage("New chat messages!");
29  }());
30});
31