1importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); 2importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js'); 3 4firebase.initializeApp({ 5 apiKey: "AIzaSyBuKBGpuWJwYsfuRn1p6jusG9R086i7NsU", 6 authDomain: "cio-bulletin.firebaseapp.com", 7 projectId: "cio-bulletin", 8 storageBucket: "cio-bulletin.firebasestorage.app", 9 messagingSenderId: "920440598708", 10 appId: "1:920440598708:web:2769ccd59e4f41584a27e1" 11}); 12 13const messaging = firebase.messaging(); 14 15// Handle background Firebase notifications 16messaging.setBackgroundMessageHandler(function(payload) { 17 console.log('[SW] Background message received:', payload); 18 19 const title = payload.notification?.title || 'New Notification'; 20 const options = { 21 body: payload.notification?.body || '', 22 icon: payload.data?.icon || '/assets/images/cb-notimes.png', 23 image: payload.data?.image || '', 24 data: { 25 url: payload.data?.url || '/' 26 }, 27 actions: [ 28 { 29 action: 'open', 30 title: 'Read Now' 31 } 32 ], 33 // requireInteraction: true 34 }; 35 36 return self.registration.showNotification(title, options); 37}); 38 39// Handle raw push events 40self.addEventListener('push', function(event) { 41 let title = 'Recent Updates'; 42 let options = { 43 body: 'New Article Published', 44 icon: '/assets/images/cb-notimes.png', 45 data: { url: '/' } 46 }; 47 48 if (event.data) { 49 try { 50 const data = event.data.json(); 51 if (data.notification) { 52 title = data.notification.title || title; 53 options.body = data.notification.body || options.body; 54 } 55 if (data.data) { 56 options.image = data.data.image || ''; 57 options.data = { url: data.data.url || '/' }; 58 } 59 } catch(e) { 60 options.body = event.data.text(); 61 } 62 } 63 64 options.actions = [ 65 { action: 'open', title: 'Read Now' } 66 ]; 67 // options.requireInteraction = true; 68 69 event.waitUntil( 70 self.registration.showNotification(title, options) 71 ); 72}); 73 74// Click on notification body â open article 75self.addEventListener('notificationclick', function(event) { 76 event.notification.close(); 77 78 const url = event.notification.data?.url || '/'; 79 80 // 'open' button OR clicking notification body both open the URL 81 event.waitUntil( 82 clients.matchAll({ type: 'window', includeUncontrolled: true }) 83 .then((clientList) => { 84 // If tab already open, focus it 85 for (const client of clientList) { 86 if (client.url === url && 'focus' in client) { 87 return client.focus(); 88 } 89 } 90 // Otherwise open new tab 91 return clients.openWindow(url); 92 }) 93 ); 94});
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.