1 2/* eslint-disable no-undef */ 3// This script runs in the background of your browser. 4importScripts('https://www.gstatic.com/firebasejs/10.9.0/firebase-app-compat.js'); 5importScripts('https://www.gstatic.com/firebasejs/10.9.0/firebase-messaging-compat.js'); 6 7// IMPORTANT: Hardcode your Firebase config here. 8// Service workers run in a isolated background context and cannot access process.env or Next.js variables. 9// You can find these values in the Firebase Console > Project Settings. 10const firebaseConfig = { 11 apiKey: "REPLACE_WITH_YOUR_API_KEY", 12 authDomain: "REPLACE_WITH_YOUR_AUTH_DOMAIN", 13 projectId: "REPLACE_WITH_YOUR_PROJECT_ID", 14 storageBucket: "REPLACE_WITH_YOUR_STORAGE_BUCKET", 15 messagingSenderId: "REPLACE_WITH_YOUR_MESSAGING_SENDER_ID", 16 appId: "REPLACE_WITH_YOUR_APP_ID", 17}; 18 19firebase.initializeApp(firebaseConfig); 20 21const messaging = firebase.messaging(); 22 23// Handle messages received when the app is in the background or closed. 24messaging.onBackgroundMessage((payload) => { 25 console.log('[firebase-messaging-sw.js] Received background message ', payload); 26 27 const notificationTitle = payload.notification?.title || 'New Support Message'; 28 const notificationOptions = { 29 body: payload.notification?.body || 'You have a new message in the support portal.', 30 icon: 'https://firebasestorage.googleapis.com/v0/b/flowtrack-6eh9w.appspot.com/o/aprops_logo2.png?alt=media&token=3bceaf30-49b2-41d1-89b7-213c138730ab', 31 badge: 'https://firebasestorage.googleapis.com/v0/b/flowtrack-6eh9w.appspot.com/o/aprops_logo2.png?alt=media&token=3bceaf30-49b2-41d1-89b7-213c138730ab', 32 tag: payload.data?.projectId || 'support-chat', // Groups notifications by project 33 data: payload.data, // Custom data, like URLs 34 }; 35 36 return self.registration.showNotification(notificationTitle, notificationOptions); 37}); 38 39// Optional: Handle notification click to open the app 40self.onnotificationclick = function(event) { 41 event.notification.close(); 42 const urlToOpen = event.notification.data?.projectId 43 ? `/support/project/${event.notification.data.projectId}` 44 : '/support/dashboard'; 45 46 event.waitUntil( 47 clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windowClients) => { 48 for (var i = 0; i < windowClients.length; i++) { 49 var client = windowClients[i]; 50 if (client.url === urlToOpen && 'focus' in client) { 51 return client.focus(); 52 } 53 } 54 if (clients.openWindow) { 55 return clients.openWindow(urlToOpen); 56 } 57 }) 58 ); 59};
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.