Skip to content

Instantly share code, notes, and snippets.

@Eder87rh
Last active April 13, 2019 16:20
Show Gist options
  • Select an option

  • Save Eder87rh/a090f6e3888688357fc08b4e6f2c0e43 to your computer and use it in GitHub Desktop.

Select an option

Save Eder87rh/a090f6e3888688357fc08b4e6f2c0e43 to your computer and use it in GitHub Desktop.
5 - cropchien - firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/5.6.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.6.0/firebase-messaging.js');
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerRoute(
new RegExp('https://firebasestorage.googleapis.com/v0/b/cropchien.appspot.com/.*'),
workbox.strategies.staleWhileRevalidate()
);
firebase.initializeApp({
'messagingSenderId': 'PASTE_YOUR_SENDER_ID_HERE'
});
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = 'Background Message Title';
const notificationOptions = {
body: 'Background Message body.',
icon: '/firebase-logo.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment