I\'d like to use the firebase cloud messaging service in my GWT webapplication, but I\'m stuck with some problems. The application should be able to register the firebase se
Not only a empty file, is a good idea to add the content like:
importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.14.2/firebase-messaging.js');
/*Update this config*/
var config = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.setBackgroundMessageHandler(function(payload) {
console.log('[firebase-messaging-sw.js] Received background message ', payload);
// Customize notification here
const notificationTitle = payload.data.title;
const notificationOptions = {
body: payload.data.body,
icon: 'http://localhost/gcm-push/img/icon.png',
image: 'http://localhost/gcm-push/img/d.png'
};
return self.registration.showNotification(notificationTitle,
notificationOptions);
});
// [END background_handler]
The Firebase SDK attempts to register the service worker at a specific location.
The location is + /firebase-messaging-sw.js. There are two options:
1.) Make + /firebase-messaging-sw.js work in the browser (i.e. make sure it returns a valid response) and then try using the SDK again (it should work if the browser can access the file).
2.) Use the useServiceworker(<service worker registration>)
method to pass in a custom service worker. This will still require you to have a valid service worker URL.
Just create an empty file in root folder firebase-messaging-sw.js
Check your angular cli file ... add
"firebase-messaging-sw.js", "manifest.json"
"assets": [ "assets", "app/main/content/components/angular-material", "favicon.ico", "firebase-messaging-sw.js", "manifest.json" ],