quickstart-js: Unable to get token

var config = {
    // Some code here
  };
  firebase.initializeApp(config);

  const messaging = firebase.messaging();
  messaging.requestPermission()
  .then(function(){
  	console.log('I am in here');
    
    messaging.getToken()
  .then(function(currentToken) {
    console.log(currentToken);
  })
  .catch(function(err) {
    console.log('An error occurred while retrieving token. ', err);
    showToken('Error retrieving Instance ID token. ', err);
    setTokenSentToServer(false);
  });

  }).catch(function(err){
    console.log('Error');
  });

My console prints out “I am in here” but it doesn’t print out the token. I have firebase-messaging-sw.js in the same folder that this code is in. Does anyone know what the problem is?

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 34

Most upvoted comments

I’m too unable to get Token in Chrome, but got in firefox. did u guys find any solution.?

There is a bug in Chrome at the moment where it’s not subscribing people to push due to a corrupt GCM database: https://bugs.chromium.org/p/chromium/issues/detail?id=623062#c37

Chances are you getting hit by this.

notoken

Aww mannn. 😦

image

eror?

downloaded chrome beta 55 and checked , Got token.

dOoX27NFmXM:APA91bH4bssOfvl3KhAoGkpCnLwx3nJrOsTI2Gvr_wvBLTLKPP7hCv4S05qkoJnG9O_fwaTJa4yVKLv5_8QQxcySRS3V0iBnoRUPCuc8rc3LZFYnkq80s6hx5pQBL_ViuM0vufSduDJd i got a token

unable to getToken!!! is some server down now?! I am getting crazy!

@gauntface help am trying edit error "Messaging: We are unable to register the default service worker. Failed to register a ServiceWorker: The script has an unsupported MIME type ('text/html'). (messaging/failed-serviceworker-registration)." ‘message’ how to fix ? thanks you

@LutfiTekin did you got the token with http setup?

I just downloaded Firefox and I see the token. yestoken

Why is not working on my Chrome? I’m running the latest version of it.

I don’t know but my setup use to be HTTP and i never got token with it. Then i switched to HTTPS (using cloudflare) and it is working now.

I’m using localhost. Does it not work on localhost?

var config = {
    // Some code here
  };
  firebase.initializeApp(config);

  const messaging = firebase.messaging();
  messaging.requestPermission()
  .then(function(){
    console.log('I am in here');

    return messaging.getToken()
  .then(function(currentToken) {
    console.log(currentToken);
  })
  .catch(function(err) {
    console.log('An error occurred while retrieving token. ', err);
    showToken('Error retrieving Instance ID token. ', err);
    setTokenSentToServer(false);
  });

  }).catch(function(err){
    console.log('Error');
  });

I’ve included the return term but it still doesn’t display the token.