As per this video instruction https://www.youtube.com/watch?v=BsCBCudx58g, I have integrated the code it looks below.
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "IIzaSyA3MZtKiK6E6y7q9w26J-YMi9Leeao5Zs0",
authDomain: "a...99.firebaseapp.com",
databaseURL: "https://a...99.firebaseio.com",
storageBucket: "a...99.appspot.com",
messagingSenderId: "915965251026"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
alert('Notification permission granted.');
return messaging.getToken();
}).then(function(token){
alert(token);
})
.catch(function(err) {
alert('Unable to get permission to notify.', err);
});
</script>
manifest.json file
{
"short_name": "AirHorner",
"name": "Kinlan's AirHorner of Infamy",
"start_url": "index.html?launcher=true"
}
Also I have created a dummy "firebase-messaging-sw.js" file
What error I faced
When I execute it, Notification permission granted alert was executed, and suddenly display Unable to get permission to notify message and in the err argument I got the following error
browserErrorMessage : "Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script." code : "messaging/failed-serviceworker-registration" message : "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)." stack : "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 https://www.gstatic.com/firebasejs/3.6.5/firebase.js:552:225"
In message.getToken() return the following value
_proto__ : Promise [[PromiseStatus]] : "pending" [[PromiseValue]] : undefined