1// This a service worker file for receiving push notifitications. 2// See `Access registration token section` @ https://firebase.google.com/docs/cloud-messaging/js/client#retrieve-the-current-registration-token 3 4// Scripts for firebase and firebase messaging 5importScripts("https://www.gstatic.com/firebasejs/10.5.0/firebase-app-compat.js"); 6importScripts("https://www.gstatic.com/firebasejs/10.5.0/firebase-messaging-compat.js"); 7 8// Initialize the Firebase app in the service worker by passing the generated config 9const firebaseConfig = { 10 apiKey: "AIzaSyBNMgUKSI-YDPcdySTWhw47a-yhNccO3IA", 11 authDomain: "slikk-dev.firebaseapp.com", 12 projectId: "slikk-dev", 13 storageBucket: "slikk-dev.firebasestorage.app", 14 messagingSenderId: "620586910646", 15 appId: "1:620586910646:web:e9f198f2daf309b77fb717", 16 measurementId: "G-4JTP082W68", 17}; 18 19firebase.initializeApp(firebaseConfig); 20 21class CustomPushEvent extends Event { 22 constructor(data) { 23 super("push"); 24 25 Object.assign(this, data); 26 this.custom = true; 27 } 28} 29 30/* 31 * Overrides push notification data, to avoid having 'notification' key and firebase blocking 32 * the message handler from being called 33 */ 34self.addEventListener("push", (e) => { 35 // Skip if event is our own custom event 36 if (e.custom) return; 37 38 // Kep old event data to override 39 const oldData = e.data; 40 41 // Create a new event to dispatch, pull values from notification key and put it in data key, 42 // and then remove notification key 43 const newEvent = new CustomPushEvent({ 44 data: { 45 ehheh: oldData.json(), 46 json() { 47 const newData = oldData.json(); 48 newData.data = { 49 ...newData.data, 50 ...newData.notification, 51 }; 52 delete newData.notification; 53 return newData; 54 }, 55 }, 56 waitUntil: e.waitUntil.bind(e), 57 }); 58 59 // Stop event propagation 60 e.stopImmediatePropagation(); 61 62 // Dispatch the new wrapped event 63 dispatchEvent(newEvent); 64}); 65 66const messaging = firebase.messaging(); 67 68messaging.onBackgroundMessage((payload) => { 69 const { title, body, image, icon, ...restPayload } = payload.data; 70 const notificationOptions = { 71 body, 72 icon: image || "/icons/firebase-logo.png", // path to your "fallback" firebase notification logo 73 data: restPayload, 74 }; 75 return self.registration.showNotification(title, notificationOptions); 76}); 77 78self.addEventListener("notificationclick", (event) => { 79 if (event?.notification?.data && event?.notification?.data?.link) { 80 self.clients.openWindow(event.notification.data.link); 81 } 82 83 // close notification after click 84 event.notification.close(); 85});
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.