firebase-messaging-sw.js 821 B

123456789101112131415161718192021222324
  1. // this file must be placed in root
  2. importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-app.js');
  3. importScripts('https://www.gstatic.com/firebasejs/4.6.1/firebase-messaging.js');
  4. firebase.initializeApp({
  5. messagingSenderId: '813343642322',
  6. });
  7. self.addEventListener('push', function (event) {
  8. const payload = event.data.json();
  9. const title = payload.notification.title;
  10. const options = {
  11. body: payload.notification.body,
  12. icon: payload.notification.icon,
  13. data: payload.notification.click_action,
  14. };
  15. event.waitUntil(self.registration.showNotification(title, options));
  16. });
  17. self.addEventListener('notificationclick', function (event) {
  18. event.notification.close();
  19. event.waitUntil(clients.openWindow('/mobile/#' + (event.notification.data || '')));
  20. });