service worker self code example
Example: service worker self.clients
addEventListener('notificationclick', event => {
event.waitUntil(async function() {
const allClients = await clients.matchAll({
includeUncontrolled: true
});
let chatClient;
for (const client of allClients) {
const url = new URL(client.url);
if (url.pathname == '/chat/') {
client.focus();
chatClient = client;
break;
}
}
if (!chatClient) {
chatClient = await clients.openWindow('/chat/');
}
chatClient.postMessage("New chat messages!");
}());
});