push-sw.js (465B)
1 async function postAll(data) { 2 const clients = await self.clients.matchAll({ includeUncontrolled: true }); 3 for (const client of clients) { 4 client.postMessage(data); 5 } 6 } 7 8 onpush = ev => postAll({ 9 type: ev.type, 10 data: ev.data.text(), 11 }); 12 13 onpushsubscriptionchange = ev => { 14 postAll({ 15 type: ev.type, 16 constructor: ev.constructor.name, 17 oldSubscription: ev.oldSubscription?.toJSON(), 18 newSubscription: ev.newSubscription?.toJSON(), 19 }); 20 }