Unable to receive token in FCM web setup

787 views
Skip to first unread message

gautam jain

unread,
Dec 12, 2016, 11:29:25 AM12/12/16
to Firebase Google Group
I was following the official guide to getting started with push notifications in the web browser. I didn't work very well for me.
In the console I get the token as 'null' even after granting the permissions for the notification.
How should I resolve this?

<!DOCTYPE html>
<html>
  <head>
    <title>FCM token</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
  </head>
  <body>

<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.3/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSygfhdfghdfgdudartfhjvxctfujcgxdf",
    authDomain: "xcvg.firebaseapp.com",
    databaseURL: "https://xcvg.firebaseio.com",
    storageBucket: "xcvg.appspot.com",
    messagingSenderId: "467764584564"
  };
  firebase.initializeApp(config);
const messaging = firebase.messaging();
    messaging.requestPermission()
            .then(function(){
                console.log("GRANTED");
                return messaging.getToken();
            })
            .then(function(token){
                console.log(token);
            })
            .catch(function(err){
                console.log('Error Occurred.')
            })
</script>  

  </body>
</html>

Matt Gaunt

unread,
Dec 12, 2016, 2:04:20 PM12/12/16
to Firebase Google Group
That's a very weird scenario to be in, I'm assuming that there are no errors in the console?

One thing to call out with your example, you only need 'firebase.js' OR 'firebase-app' and 'firebase-messaging.js', not all three. 'firebase.js' is a large javascript file that contains *everything* in the firebase SDK. firebase-app and firebase-messaging is the minimum needed if you just wanted firebase messaging.

Few questions for you:

1. Is you demo hosted anywhere I can view it?
2. What browser and browser version are you using?
Reply all
Reply to author
Forward
0 new messages