firebase-messaging-sw.js 995 B

123456789101112131415161718192021
  1. importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-app-compat.js');
  2. importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-messaging-compat.js');
  3. importScripts('config.js');
  4. firebase.initializeApp(firebaseConfig);
  5. const messaging = firebase.messaging();
  6. // If you would like to customize notifications that are received in the
  7. // background (Web app is closed or not in browser focus) then you should
  8. // implement this optional method.
  9. // Keep in mind that FCM will still show notification messages automatically
  10. // and you should use data messages for custom notifications.
  11. // For more info see:
  12. // https://firebase.google.com/docs/cloud-messaging/concept-options
  13. messaging.onBackgroundMessage(function(payload) {
  14. console.log('[firebase-messaging-sw.js] Received background message ', payload);
  15. // Customize notification here
  16. const notificationTitle = 'We received a message';
  17. self.registration.showNotification(notificationTitle,payload.notification);
  18. });