Reputation:
I have configured firebase cloud messaging api with my angularjs app.But as shown in Firebase Documentation.For Receiving message firebase-messaging-sw.js needs to be created and scripts to be imported. But on importing scripts in firebase-messaging-sw.js,
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js'); importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
how to import these scripts into firebase-messaging-sw.js because these are imported in index.html file.
Error: importScripts is not defined. Please tell how to import such file and this solution works only for chrome or for all browsers.
Upvotes: 1
Views: 1731
Reputation:
I figured it out.. As only these two scripts can be imported because only these two are defined in service-worker file. Try to use service-worker,if default code doesn't workout like this:
navigator.serviceWorker.register('/firebase-messaging-sw.js')
.then(function (registration)
{
var serviceWorker;
if (registration.installing) {
serviceWorker = registration.installing;
} else if (registration.waiting) {
serviceWorker = registration.waiting;
} else if (registration.active) {
serviceWorker = registration.active;
}
}).catch(function (err) {
console.log('ServiceWorker registration failed: ', err);
});
Also,in the Tutorial provided by google in Google official Doc ,Use Server Key instead of api key otherwise error will surely come.
Upvotes: 0