I am using FCM web app notification for send notification to browser. **I Got The following errors :
- 1.A bad HTTP response code (404) was received when fetching the script. ------ firebase-messaging-sw.js
- 2..Failed to load resource: net::ERR_INVALID_RESPONSE
- 3.Error -> messaging/failed-serviceworker-registration
- 4.Error Message -> FirebaseError: Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script. (messaging/failed-serviceworker-registration).↵ at http://ift.tt/2ivJgjF↵ at **
My code below.
<script src="http://ift.tt/2h4CcKt"></script>
<script src="http://ift.tt/2iutXHH"></script>
<script src="http://ift.tt/2h4CdOx"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "APIKEYXXXXXXXXXXXXXXXXXXXXX",
authDomain: "fir-cloudmessaging-d3607.firebaseapp.com",
databaseURL: "http://ift.tt/2iv4ON2",
projectId: "fir-cloudmessaging-d3607",
storageBucket: "fir-cloudmessaging-d3607.appspot.com",
messagingSenderId: "SENDERID123456789"
};
firebase.initializeApp(config);
</script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('firebase-messaging-sw.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
console.log('Notification permission granted.');
// TODO(developer): Retrieve an Instance ID token for use with FCM.
// ...
console.log(messaging.getToken());
// return messaging.getToken();
})
.then(function(token){
console.log(token);
})
.catch(function(err) {
console.log('Unable to get permission to notify.', err);
});
</script>
Aucun commentaire:
Enregistrer un commentaire