firebase / codelab-friendlychat-web

The source for the Firebase codelab for building a cross-platform chat app
https://firebase.google.com
Apache License 2.0
1.74k stars 1.77k forks source link

Step 11 Fail - Error text: Unable to get messaging device token: Object (anonymous) @ main.js:180 #355

Closed clfaulkner closed 5 years ago

clfaulkner commented 5 years ago

Error message: Unable to get messaging device token: Object (anonymous) @ main.js:180

Here is the code I pasted:

// Saves the messaging device token to the Realtime Database.
function saveMessagingDeviceToken() {
  firebase.messaging().getToken().then(function(currentToken) {
    if (currentToken) {
      console.log('Got FCM device token:', currentToken);
      // Save the device token to the Realtime Database.
      firebase.database().ref('/fcmTokens').child(currentToken)
          .set(firebase.auth().currentUser.uid);
    } else {
      // Need to request permissions to show notifications.
      requestNotificationsPermissions();
    }
  }).catch(function(error){
    console.error('Unable to get messaging device token:', error);
  });
}

Please let me know if there is any other info you need.

nicolasgarnier commented 5 years ago

Could you postethe content of the error object that is being logged?

clfaulkner commented 5 years ago

I don't remember if I said thank you, so ... Thank You. 😊

On Mon, Jan 14, 2019 at 12:37 PM Nicolas Garnier notifications@github.com wrote:

Were you doing the browser on Chrome? Some other browsers do not support Firebase messaging because they do not support firebase push notifications. You must add the following code to check this:

try { this.messaging = firebase.messaging(); } catch(e) { if (e.code === 'messaging/unsupported-browser') { console.warn('This Browser does not suport FCM. Notifications won\'t be available.', e); } else { throw e; } }

I'll add this to the codelab now.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/firebase/friendlychat-web/issues/355#issuecomment-454152586, or mute the thread https://github.com/notifications/unsubscribe-auth/AjEu8eIgXizFSGR4tt4jP3XJLkIWqqlxks5vDOqkgaJpZM4YzfPi .