// this file must be placed in root importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-messaging.js'); firebase.initializeApp({ messagingSenderId: '813343642322', }); const messaging = firebase.messaging(); self.addEventListener('push', function (event) { const payload = event.data.json() || {}; const payloadNotification = payload.notification || {}; const payloadData = payload.data || {}; const options = { body: payloadNotification.body || payloadData.body, icon: payloadNotification.icon || payloadData.icon || '/img/icons/android-chrome-167x167.png', badge : '/img/icons/icon-messages-96x96.png', image : payloadNotification.image || payloadData.image , vibrate : [300, 100, 400], data: payloadNotification.click_action || payloadData.click_action || payloadNotification.clickAction || payloadData.clickAction }; event.waitUntil(self.registration.showNotification(payloadNotification.title, options)); }); self.addEventListener('notificationclick', function (event) { event.notification.close(); event.waitUntil(clients.openWindow('/mobile/#' + (event.notification.data || '/home'))); });