1 2 importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js'); 3 importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js'); 4 5 6 const firebaseConfig = [] 7 8 9// Initialize Firebase 10firebase.initializeApp(firebaseConfig); 11 12// Retrieve an instance of Firebase Messaging so that it can handle background messages 13const messaging = firebase.messaging(); 14 15messaging.onBackgroundMessage(async (payload) => { 16 console.log('[firebase-messaging-sw.js] Received background message ', payload); 17 18 // Prevent showing notifications if the page is already open and focused 19 const allClients = await clients.matchAll({ type: 'window', includeUncontrolled: true }); 20 for (const client of allClients) { 21 if (client.focused) { 22 console.log('Page is active, skipping background notification.'); 23 return; 24 } 25 } 26 27 const notificationTitle = payload.data.title || "New Message"; 28 const notificationOptions = { 29 body: payload.data.price || "You have a new message!", 30 icon: payload.data.icon || 'default-icon.png', 31 image: payload.data.image || undefined, 32 data: { 33 intUrl: payload.data?.intUrl, 34 extUrl: payload.data?.extUrl, 35 }, 36 }; 37 38 return self.registration.showNotification(notificationTitle, notificationOptions); 39}); 40 41 42 43self.addEventListener('notificationclick', (event) => { 44 console.log("ð Notification Clicked:", event.notification); 45 46 const data = event.notification?.data || {}; 47 let url = "https://www.c2apps.clubwww1.com" 48 49 if (data.intUrl && data.intUrl !== "noUrl") { 50 url = data.intUrl; 51 } else if (data.extUrl && data.extUrl !== "noUrl") { 52 url = data.extUrl; 53 } 54 55 event.notification.close(); // Close the notification 56 57 event.waitUntil( 58 clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientList) => { 59 for (const client of clientList) { 60 if (client.url === url && "focus" in client) { 61 return client.focus(); 62 } 63 } 64 if (clients.openWindow) { 65 return clients.openWindow(url); 66 } 67 }) 68 ); 69}); 70 71 72 73
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.