/* Give the service worker access to Firebase Messaging. Note that you can only use Firebase Messaging here, other Firebase libraries are not available in the service worker. */ importScripts('https://www.gstatic.com/firebasejs/7.14.0/firebase-app.js') importScripts('https://www.gstatic.com/firebasejs/7.14.0/firebase-messaging.js') /* Initialize the Firebase app in the service worker by passing in the messagingSenderId. */ firebase.initializeApp({ apiKey: "AIzaSyBnlNcfik7Y5l8weUc_Udl5a4z9uGhuUzU", authDomain: "quizac-14fa2.firebaseapp.com", databaseURL: "https://quizac-14fa2.firebaseio.com", projectId: "quizac-14fa2", storageBucket: "quizac-14fa2.appspot.com", messagingSenderId: "605961954630", appId: "1:605961954630:web:503119dd223a628b947147" }) /* Retrieve an instance of Firebase Messaging so that it can handle background messages. */ const messaging = firebase.messaging() messaging.setBackgroundMessageHandler(function (payload) { console.log('[firebase-messaging-sw.js] Received background message ', payload); const notification = JSON.parse(payload.data.notification); // Customize notification here const notificationTitle = notification.title; const notificationOptions = { body: notification.body, icon: './img/logo.png' }; self.addEventListener('notificationclick', function(event) { console.log(event); let url = event.notification.click_action; event.notification.close(); event.waitUntil(self.clients.openWindow(url)); }); return self.registration.showNotification(notificationTitle, notificationOptions); });