1// eslint-disable-next-line no-undef 2importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); 3// eslint-disable-next-line no-undef 4importScripts( 5 'https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js' 6); 7// eslint-disable-next-line no-undef 8importScripts('swEnv.js'); 9 10const firebaseConfig = { 11 apiKey: swEnv.NEXT_PUBLIC_FIREBASE_API_KEY, 12 authDomain: swEnv.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN, 13 projectId: swEnv.NEXT_PUBLIC_FIREBASE_PROJECT_ID, 14 storageBucket: swEnv.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET, 15 messagingSenderId: swEnv.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID, 16 appId: swEnv.NEXT_PUBLIC_FIREBASE_APP_ID, 17 measurementId: swEnv.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID, 18}; 19// eslint-disable-next-line no-undef 20firebase.initializeApp(firebaseConfig); 21// eslint-disable-next-line no-undef 22const messaging = firebase.messaging(); 23 24// remove old notifications on service worker start 25self.addEventListener('install', event => { 26 event.waitUntil( 27 self.registration.getNotifications().then(notifications => { 28 // Define criteria for "dangling" notifications 29 const cutoffTime = Date.now() - 60 * 60 * 1000; // Notifications older than 1 hours 30 notifications.forEach(notification => { 31 if (notification.data && notification.data.timestamp < cutoffTime) { 32 notification.close(); // Close notifications older than 24 hours 33 } 34 }); 35 }) 36 ); 37}); 38 39messaging.onBackgroundMessage(payload => { 40 const data = payload.data || {}; 41 const title = 42 (payload.notification && payload.notification.title) || data.title; 43 const body = (payload.notification && payload.notification.body) || data.body; 44 45 // Nothing to show â bail out instead of crashing on a missing notification block 46 if (!title) return; 47 48 self.registration.showNotification(title, { 49 body, 50 icon: './logo/favicon.svg', 51 // Timestamp lets the install-time cleanup above close stale notifications 52 data: { timestamp: Date.now() }, 53 }); 54});
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.