/* 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: "AIzaSyAFYh3w5mej2JvV7KH7k1r0YhcvxjhJuaM", authDomain: "quizac-staging.firebaseapp.com", databaseURL: "https://quizac-staging.firebaseio.com", projectId: "quizac-staging", storageBucket: "quizac-staging.appspot.com", messagingSenderId: "194753472989", appId: "1:194753472989:web:e29962bff74ef94514ee34" }) /* 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); });