1importScripts("https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"); 2importScripts( 3 "https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js", 4); 5 6const firebaseConfig = { 7 apiKey: "<%= process.env.FCM_API_KEY %>", 8 authDomain: "<%= process.env.FCM_AUTH_DOMAIN %>", 9 databaseURL: "<%= process.env.FCM_DATA_BASE_URL %>", 10 projectId: "<%= process.env.FCM_PROJECT_ID %>", 11 storageBucket: "<%= process.env.FCM_STORAGE_BUCKET %>", 12 messagingSenderId: "<%= process.env.FCM_MESSAGING_SENDER_ID %>", 13 appId: "<%= process.env.FCM_APP_ID %>", 14 measurementId: "<%= process.env.FCM_MEASUREMENT_ID %>", 15}; 16 17const params = new URL(self.location); 18const device = params.searchParams.get("device"); 19 20const getClientList = () => 21 self.clients.claim().then(() => 22 self.clients.matchAll({ 23 includeUncontrolled: true, 24 type: 'window', 25 }), 26 ); 27 28 29// Device ID sent by client 30let firstPlatform = null; 31 32// Listen to messages from client 33self.addEventListener('message', (event) => { 34 if (event.data && event.data.idPlatform) { 35 firstPlatform = event.data.idPlatform; 36 } 37}); 38 39if (firebase.apps.length === 0) { 40 firebase.initializeApp(firebaseConfig); 41} 42 43if (firebase.messaging.isSupported()) { 44 const messaging = firebase.messaging(); 45 messaging.onBackgroundMessage((payload) => { 46 47 if (device === 'true' || device === true) return null; 48 49 const { message, deeplink, type } = payload.data || {}; 50 51 if (firstPlatform !== 'new-profile') return null; 52 53 const notificationTitle = 'Female Daily'; 54 const hasQuestionMark = /\?/.test(deeplink); 55 const notificationOptions = { 56 body: message, 57 icon: 'https://s3.ap-southeast-1.amazonaws.com/assets.femaledaily.com/web-assets/logo/fdn_logo_192.png', 58 data: { 59 url: `${deeplink}${hasQuestionMark ? `&` : `?`}utm_source=web&utm_medium=web_push&utm_campaign=${type}`, 60 }, 61 requireInteraction: true, 62 silent: false, 63 }; 64 return self.registration.showNotification( 65 notificationTitle, 66 notificationOptions 67 ); 68 }); 69 70 self.addEventListener( 71 "notificationclick", 72 async (event) => { 73 event.notification.close(); 74 event.waitUntil( 75 getClientList().then((clientList) => { 76 for (const client of clientList) { 77 if (client.url === event.notification.data.url) { 78 return client.focus(); 79 } 80 } 81 if (clients.openWindow) { 82 return clients.openWindow(event.notification.data.url); 83 } 84 }), 85 ); 86 }, 87 false, 88 ); 89}
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.