click-action-sw.js (540B)
1 self.addEventListener("install", function () { 2 console.log("install"); 3 self.skipWaiting(); 4 }); 5 6 self.addEventListener("activate", function (e) { 7 console.log("activate"); 8 e.waitUntil(self.clients.claim()); 9 }); 10 11 async function postAll(data) { 12 const clients = await self.clients.matchAll({ includeUncontrolled: true }); 13 for (const client of clients) { 14 client.postMessage(data); 15 } 16 } 17 18 self.onnotificationclick = function (event) { 19 console.log("onnotificationclick"); 20 postAll(event.action); 21 event.notification.close(); 22 };