import firebase from './firebase';
import 'firebase/messaging';
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler( ( payload ) => {
console.log( '[firebase-sw.js] Received background message ', payload );
// Customize notification here
let notificationTitle = 'Background Message Title';
let notificationOptions = {
body: 'Background Message body.',
};
// THIS CODE NEXT LINE DOESN'T HAVE ANY EFFECT!
return self.registration.showNotification( notificationTitle, notificationOptions );
} );
import firebase from './firebase';
import 'firebase/messaging';
const messaging = firebase.messaging();
messaging.usePublicVapidKey( 'BByfoHTu_xmuusRLf12mqTfdcqd33nLOl9KEP75p-vw42KmKQMkaJ6r11QRTS77eF0je8lKEbTw4Y0ZXFISeUB8' );
// FOREGROUND listener
messaging.onMessage( ( message ) => {
console.log( message );
debugger;
} );
// REGISTER SERVICE WORKER
navigator.serviceWorker.register( chrome.extension.getURL( '/firebase-sw.js' ) )
.then( ( registration ) => {
messaging.useServiceWorker( registration );
messaging.getToken().then( ( token ) => {
console.log( token );
} );
} )
.catch( ( error ) => console.log( 'error registering service worker: ', error ) );
self.registration.showNotification( notificationTitle, notificationOptions );