Sending Firebase Push Messages to Chrome Extension

1,305 views
Skip to first unread message

Byron Bailey

unread,
Jul 11, 2018, 12:39:10 AM7/11/18
to Firebase Google Group
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.

Byron Bailey

unread,
Jul 20, 2018, 6:25:15 PM7/20/18
to Firebase Google Group
Any thoughts or feedback from anyone?  I've tried stackoverflow, no responses.  I've tried reaching out to firebase support email, and was told to post here.  This is a showstopper for me that would force me to abandon firebase completely, which would be a sizeable change at this point.  Thank you!

Byron Bailey

unread,
Jul 24, 2018, 7:30:55 PM7/24/18
to Firebase Google Group
Last call, any ideas please?  Should I post this somewhere else?  Have I broken some rule that makes no one want to reply?

Ian Barber

unread,
Jul 24, 2018, 7:41:26 PM7/24/18
to Firebase Google Group
Hi Byron!

Sorry, we have been trying to find out internally. No definitive answer yet, sorry. There aren't many folks on the FCM team who have touched chrome extensions unfortunately!

Ian

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fecf21b7-f528-4d35-a8ab-b19dcf0e4557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Byron Bailey

unread,
Jul 26, 2018, 10:07:54 AM7/26/18
to Firebase Google Group
Ian, I sincerely appreciate the response.  I will attempt to find an answer from the Extensions group as well since this may have more to do with them and how they handle push subscription permissions.  Thx


On Wednesday, July 11, 2018 at 6:39:10 AM UTC+2, Byron Bailey wrote:

Byron Bailey

unread,
Jul 26, 2018, 10:07:59 AM7/26/18
to fireba...@googlegroups.com
Would it help if I sent an sample extension that demonstrates the problem?

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fecf21b7-f528-4d35-a8ab-b19dcf0e4557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Ian Barber

unread,
Jul 26, 2018, 5:21:59 PM7/26/18
to Firebase Google Group
Hi Byron! 

Actually have some answer: it seems there is an issue in Chrome which prevents FCM from working in extensions right now. This is fixed in version 69, and we'll be adding an example of how to add FCM to an extension when that version ships.

As far as I know there isn't a good workaround right now, but hopefully it'll be working again soon!

Ian

To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fecf21b7-f528-4d35-a8ab-b19dcf0e4557%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

Byron Bailey

unread,
Jul 31, 2018, 10:36:31 AM7/31/18
to Firebase Google Group
I was too busy celebrating and forgot to respond.  Thank you, Ian!!
Reply all
Reply to author
Forward
0 new messages