2

I am developing a chrome extension. I want to send FCM messages to extension via Firebase from external server by specific token, but I can't receive this token.

I try to receive token in background script by call the following code:

async function registerFirebaseApp(): Promise<void> {
    if (!navigator && !('serviceWorker' in navigator)) {
        return;
    }

    try {
        firebase.initializeApp({
            apiKey: "AIzaSyAMhLAPjiAjUUdoxXLaJtgHlEC9WB8wWZY",
            authDomain: "berrywallet-spreader.firebaseapp.com",
            databaseURL: "https://berrywallet-spreader.firebaseio.com",
            projectId: "berrywallet-spreader",
            storageBucket: "berrywallet-spreader.appspot.com",
            messagingSenderId: "508872957744",
        });
        console.log('1');


        const messaging = firebase.messaging();
        console.log('2');

        // This promise never resolves. No result. No error.
        const currentToken: string = await messaging.getToken();
        console.log('3');

        console.log('Push token!', currentToken);
    } catch (error) {
        console.error(error);
    }
}

Then I have console log

1
2

... it's all.

I expect to catch at least an exception, but not.


File with code which tring to get token in repository: Background/application.ts

Firebase message SW: firebase-messaging-sw.js

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • I don't know Firebase so here's just a general hint: see if there are network requests in the background script's devtools network panel. Maybe it'll give you something to go on. – wOxxOm Sep 20 '18 at 10:16
  • 1
    I was also facing the same issue. Please update the chrome to version 69. Here is the link to my question where I posted the answer - [Firebase Cloud Messaging's getToken() pending in Chrome Extension](https://stackoverflow.com/questions/52817689/firebase-cloud-messagings-gettoken-pending-in-chrome-extension). I got the solution from the [Firebase Google Group](https://groups.google.com/forum/#!topic/firebase-talk/wA8KEJAJMt4). – Pallavi Goyal Oct 16 '18 at 08:38

0 Answers0