I have the following code based on google documentation :
var config = {
apiKey: "XX",
authDomain: "XX",
databaseURL: "XX",
storageBucket: "XX",
messagingSenderId: "XX"
};
firebase.initializeApp(config);
const messaging = firebase.messaging();
messaging.requestPermission()
.then(function() {
console.log('Notification permission granted.');
messaging.getToken()
.then(function(currentToken) {
if (currentToken) {
console.log(currentToken);
} else {
console.log('No Instance ID token available. Request permission to generate one.');
}
})
.catch(function(err) {
console.log('An error occurred while retrieving token. ', err);
});
})
.catch(function(err) {
console.log('Unable to get permission to notify. ', err);
});
Oddly enough, the thenfunction is messaging.getToken()never called. The console displays Notification permission granted., but after that it remains silent (i.e. I also do not get any errors).
Am I doing something wrong?
EDIT: It should be noted that I'm trying to implement this in a Chrome extension.
source
share