1/* GenzoX Service Worker â VAPID Web Push (Iter50) + foreground notifications + click routing. 2 * 3 * iOS Safari 16.4+ supports notifications ONLY when the site is added to Home Screen 4 * (standalone mode) AND notifications are dispatched via ServiceWorkerRegistration.showNotification(). 5 * Server-initiated VAPID push (this `push` handler) works the same way on iOS PWA installs. 6 */ 7 8self.addEventListener('install', () => { 9 self.skipWaiting(); 10}); 11 12self.addEventListener('activate', (event) => { 13 event.waitUntil(self.clients.claim()); 14}); 15 16// Server-initiated VAPID push messages land here. Parse the JSON payload sent by the backend 17// (send_push_to_user) and surface it via showNotification. 18self.addEventListener('push', (event) => { 19 let data = { title: 'GenzoX', body: 'You have a new message', url: '/chat' }; 20 if (event.data) { 21 try { data = { ...data, ...event.data.json() }; } 22 catch (_) { 23 try { data.body = event.data.text() || data.body; } catch (_e) {} 24 } 25 } 26 const title = data.title || 'GenzoX'; 27 const options = { 28 body: data.body || 'You have a new message', 29 icon: '/favicon-192.png', 30 badge: '/favicon-128.png', 31 tag: data.tag || 'genzox-push', 32 data: { url: data.url || '/chat' }, 33 requireInteraction: false, 34 }; 35 event.waitUntil(self.registration.showNotification(title, options)); 36}); 37 38// Handle clicks on showNotification() events â focus tab and navigate to chat thread. 39self.addEventListener('notificationclick', (event) => { 40 event.notification.close(); 41 const targetUrl = (event.notification.data && event.notification.data.url) || '/chat'; 42 event.waitUntil( 43 self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => { 44 for (const client of clientList) { 45 if (client.url && 'focus' in client) { 46 client.focus(); 47 if ('navigate' in client) { 48 try { client.navigate(targetUrl); } catch (_) {} 49 } 50 return; 51 } 52 } 53 if (self.clients.openWindow) { 54 return self.clients.openWindow(targetUrl); 55 } 56 }) 57 ); 58});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.