Hello,
I'm trying to send push message to a Chrome extension and am having difficulty.
- I have "gcm" and "notifications" permissions specified in my manifest
- Calls to requestPermissions() return successfully
- The call to getToken() never returns (neither "then" nor "catch" are invoked on the promise, curiously).
- If I add my extension ID manually to the "Allowed" notification list in Chrome settings, a token is successfully returned.
I have also tried removing "gcm" and "notifications" permissions from the manifest in the hopes that it will trigger a prompt to the user to approve notifications. However, no prompt ever appears. The identical code works when called against a website, so I don't think it is a code issue.... I'm certain it is because I am in an extension.
I have tested nearly every workaround/alternative that I can dream up, such as running a service worker from my website and having it pass messages to the extension. However, that call requires access to chrome.runtime, which is not available in the service worker.
Any suggestions/ideas? Below is my very-vanilla code and the console output. getToken() hangs, whether I run it from the popup or the background. Tx
var config = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "",
messagingSenderId: "..."
};
firebase.initializeApp(config);
var fbmessaging = firebase.messaging();
function getToken(){
trace('Getting new token');
var promise = fbmessaging.getToken();
trace('Have getToken() promise. Executing.');
promise.then(function(newToken) {
trace('New token received: ' +newToken);
})
.catch(function(err) {
trace('Unable to retrieve refreshed token ', err);
});
}
fbmessaging.requestPermission()
.then(function() {
trace('Notification permission granted.');
getToken();
}).catch(function(err) {
trace('Unable to get firebase messaging permission: ' +err);
});
fbmessaging.onTokenRefresh(function(arg) {
trace("OnTokenRefresh called. " +arg);
getToken();
});
Notification permission granted.
Getting new token
Have getToken() promise. Executing.