shownotification-sw.js (903B)
1 self.onmessage = event => { 2 // Checking for a particular value, so more tests can be added in future. 3 if (event.data !== 'test-shownotification') return; 4 5 // Random number, so we can identify the notification we create. 6 const random = Math.random().toString(); 7 const start = Date.now(); 8 9 event.waitUntil( 10 self.registration.showNotification('test', { 11 tag: random, 12 // ?pipe=trickle(d2) delays the icon request by two seconds 13 icon: 'icon.png?pipe=trickle(d2)' 14 }).then(() => { 15 const resolveDuration = Date.now() - start; 16 17 return self.registration.getNotifications().then(notifications => { 18 event.source.postMessage({ 19 type: 'notification-data', 20 resolveDuration, 21 // Check if our notification is in notifications 22 notificationReturned: notifications.some(n => n.tag == random) 23 }); 24 }); 25 }) 26 ); 27 };