notification_show_sw.js (331B)
1 onmessage = async ev => { 2 if (ev.data !== "show") { 3 return; 4 } 5 const shown = await self.registration.showNotification("title").then( 6 () => true, 7 () => false 8 ); 9 const clients = await self.clients.matchAll({ includeUncontrolled: true }); 10 for (let client of clients) { 11 client.postMessage({ shown }); 12 } 13 };