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 4const envData = { 5 NEXT_PUBLIC_FIREBASE_API_KEY: 'AIzaSyDTxsBzN8HE4S4qX_xo_Bue07o3cBTdoSA', 6 NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: 'blackbox-6a4e3.firebaseapp.com', 7 NEXT_PUBLIC_FIREBASE_PROJECT_ID: 'blackbox-6a4e3', 8 NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: 'blackbox-6a4e3.appspot.com', 9 NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID: '90115057799', 10 NEXT_PUBLIC_FIREBASE_APP_ID: '1:90115057799:web:3bd148181a0421988b3022', 11 NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID: 'G-3EYV3XKBGK' 12} 13 14// Firebase config 15const firebaseConfig = { 16 apiKey: envData.NEXT_PUBLIC_FIREBASE_API_KEY, 17 authDomain: envData.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN, 18 projectId: envData.NEXT_PUBLIC_FIREBASE_PROJECT_ID, 19 storageBucket: envData.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET, 20 messagingSenderId: envData.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID, 21 appId: envData.NEXT_PUBLIC_FIREBASE_APP_ID, 22 measurementId: envData.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID 23} 24 25firebase.initializeApp(firebaseConfig) 26 27const messaging = firebase.messaging() 28 29messaging.onBackgroundMessage(async payload => { 30 console.log( 31 '[firebase-messaging-sw.js] Received background message ', 32 payload 33 ) 34 35 const link = payload.fcmOptions?.link || payload.data?.link 36 // Set a default URL if the link is localhost or undefined 37 const defaultUrl = 'https://app.blackbox.ai'; 38 const notificationLink = link && !link.includes('localhost') ? link : defaultUrl; 39 40 const notificationTitle = payload.notification.title; 41 const notificationOptions = { 42 body: payload.notification.body, 43 icon: './logo.png', 44 data: { url: notificationLink } // Use the notificationLink variable 45 } 46 47 // Check if any of the clients (tabs/windows) are open and focused 48 const clientList = await clients.matchAll({ 49 type: 'window', 50 includeUncontrolled: true 51 }) 52 let isClientActive = false 53 54 for (const client of clientList) { 55 // Check if the client is both visible and focused 56 if (client.visibilityState === 'visible' && 'focus' in client) { 57 isClientActive = true 58 break 59 } 60 } 61 62 // Show notification only if no active client is found (i.e., user is not on the page) 63 if (!isClientActive) { 64 console.info('[firebase-messaging-sw.js] Notifications disabled - skipping showNotification.') 65 } 66}) 67 68 69self.addEventListener('notificationclick', event => { 70 console.log('[firebase-messaging-sw.js] Notification click received.') 71 72 event.notification.close() 73 74 const url = event.notification.data.url 75 76 event.waitUntil( 77 clients 78 .matchAll({ type: 'window', includeUncontrolled: true }) 79 .then(clientList => { 80 for (const client of clientList) { 81 if (client.url === url && 'focus' in client) { 82 return client.focus() 83 } 84 } 85 86 if (clients.openWindow) { 87 return clients.openWindow(url) 88 } 89 }) 90 ) 91})
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.