OLD | NEW |
(Empty) | |
| 1 skipWaiting(); |
| 2 |
| 3 addEventListener('fetch', event => { |
| 4 const url = new URL(event.request.url); |
| 5 |
| 6 if (url.origin != location.origin) return; |
| 7 |
| 8 if (url.pathname.endsWith('/dummy.txt')) { |
| 9 event.respondWith(new Response('intercepted')); |
| 10 return; |
| 11 } |
| 12 |
| 13 if (url.pathname.endsWith('/dummy.txt-inner-fetch')) { |
| 14 event.respondWith(fetch('dummy.txt')); |
| 15 return; |
| 16 } |
| 17 |
| 18 if (url.pathname.endsWith('/dummy.txt-inner-cache')) { |
| 19 event.respondWith( |
| 20 caches.open('test-inner-cache').then(cache => |
| 21 cache.add('dummy.txt').then(() => cache.match('dummy.txt')) |
| 22 ) |
| 23 ); |
| 24 return; |
| 25 } |
| 26 |
| 27 if (url.pathname.endsWith('/show-notification')) { |
| 28 // Copy the currect search string onto the icon url |
| 29 const iconURL = new URL('notification_icon.py', location); |
| 30 iconURL.search = url.search; |
| 31 |
| 32 event.respondWith( |
| 33 registration.showNotification('test', { |
| 34 icon: iconURL |
| 35 }).then(() => registration.getNotifications()).then(notifications => { |
| 36 for (const n of notifications) n.close(); |
| 37 return new Response('done'); |
| 38 }) |
| 39 ); |
| 40 return; |
| 41 } |
| 42 |
| 43 if (url.pathname.endsWith('/notification_icon.py')) { |
| 44 new BroadcastChannel('icon-request').postMessage('yay'); |
| 45 event.respondWith(new Response('done')); |
| 46 return; |
| 47 } |
| 48 }); |
OLD | NEW |