Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase.messaging.getToken() edgecase when push notification is set back to default (ask) #2364

Open
thomasmburke opened this issue Nov 15, 2019 · 26 comments
Milestone

Comments

@thomasmburke
Copy link

@thomasmburke thomasmburke commented Nov 15, 2019

[REQUIRED] Describe your environment

  • Operating System version: macOS Mojave Version 10.14.6
  • Browser version: Google Chrome Version 78.0.3904.97
  • Firebase SDK version: 7.0.0
  • Firebase Product: Firebase Cloud Messaging

[REQUIRED] Describe the problem

The issue I have identified was introduced in version 7.0.0 of the firebase-js-sdk. I do not run into this issue in versions previous to 7.0.0. The issue occurs when a use grants notification permissions, gets a FCM token, then updates the notification permissions in the browser back to Ask (default), reloads the page, grants notification permissions again in Chrome, and get an error when trying to getToken at this point. Note: subsequent calls to getToken don't face this issue.

Steps to reproduce:

The problem occurs after taking the following steps:

  • Call Notification.requestPermission() and user grants permissions

  • Call firebase.messaging.getToken()

  • Set notification permission in browser back to Ask (default)
    image

  • Call Notification.requestPermission() and user grants permissions

  • call firebase.messaging.getToken()

  • get DELETE https://fcmregistrations.googleapis.com/v1/projects/{project_id}/regis.../{FCM_token} 500 error and this specific error from FCM: "FirebaseError: Messaging: A problem occured while unsubscribing the user from FCM: FirebaseError: Messaging: A problem occured while unsubscribing the user from FCM: Internal error encountered. (messaging/token-unsubscribe-failed). (messaging/token-unsubscribe-failed)."

  • call messaging.getToken() again

  • get new token, no error this time.

Others have encountered this issue as well on Google Groups:
https://groups.google.com/a/google.com/forum/#!msg/firebase-developer-cuf/dGU1SnJ1cz0/GMa_WvWGBwAJ

Relevant Code:

The firebase javascript messaging quickstart encounters this issue:
https://github.com/firebase/quickstart-js/tree/master/messaging

Specifically, I think the update needs to be made here:
firebase-js-sdk/packages/messaging/src/controllers/base-controller.ts
Lines: 136-137

@google-oss-bot

This comment has been minimized.

Copy link

@google-oss-bot google-oss-bot commented Nov 15, 2019

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@bjgrosse

This comment has been minimized.

Copy link

@bjgrosse bjgrosse commented Nov 17, 2019

I also ran into this error just as the OP described.

@mindiii006

This comment has been minimized.

Copy link

@mindiii006 mindiii006 commented Nov 18, 2019

I am also getting this issue.

@rommelpe

This comment has been minimized.

Copy link

@rommelpe rommelpe commented Nov 18, 2019

Thank for the report. I was able to reproduce this using the quick start guide and filed an internal report (b/144697421).

error-messaging

I'm just wondering if you y'all happen to consistently facing this issue. There are times that I can only reproduce it on the initial load or upon requesting permission several times. Are there any particular patterns you notice that significantly contributes to the issue (aside from what mentioned)?

@thomasmburke

This comment has been minimized.

Copy link
Author

@thomasmburke thomasmburke commented Nov 18, 2019

Hi rommelpe,

This issue only arises after the a reset of notifications permissions and reload of page and then works properly with an additional reloaded pages. Aside from what I mentioned there are no other patterns that contribute to the issue identified.

Thanks, and let me know if there are any other questions.

@Nox04

This comment has been minimized.

Copy link

@Nox04 Nox04 commented Nov 18, 2019

I'm getting the same issue when I remove the push notifications permission and reload.

@gestewa

This comment has been minimized.

Copy link

@gestewa gestewa commented Nov 18, 2019

I am also getting this issue.

@thayannevls

This comment has been minimized.

Copy link

@thayannevls thayannevls commented Nov 19, 2019

I'm getting the same error :(

@mmermerkaya

This comment has been minimized.

Copy link
Member

@mmermerkaya mmermerkaya commented Nov 21, 2019

Thanks for the report. I can consistently reproduce the behavior and I'm investigating the issue.

I'd like to ask everyone to please refrain from posting "This is happening to me too" comments and instead use the add reaction feature on the OP to add a thumbs up to issues that you consider important.

@TrackMyToken

This comment has been minimized.

Copy link

@TrackMyToken TrackMyToken commented Nov 30, 2019

Any update on this issue?

@mmermerkaya

This comment has been minimized.

Copy link
Member

@mmermerkaya mmermerkaya commented Dec 3, 2019

Hello, sorry for the lack of updates. Looks like the problem is in our backend, but there wasn't much progress as we've had a code freeze last week (because of black friday). I should be able to give you a better update or even a fix later this week.

@NaghamHalabi

This comment has been minimized.

Copy link

@NaghamHalabi NaghamHalabi commented Dec 6, 2019

Can we have the latest updates regarding this issue?

@mmermerkaya

This comment has been minimized.

Copy link
Member

@mmermerkaya mmermerkaya commented Dec 10, 2019

Hey everyone, our backend team is still investigating this. Since it's taking longer than my initial estimate, I just submitted a PR to temporarily suppress this error.

@spawnrider

This comment has been minimized.

Copy link

@spawnrider spawnrider commented Dec 11, 2019

Also reproduced this issue and need a fix
Using Firebase version 7.5.2

@kdluu

This comment has been minimized.

Copy link

@kdluu kdluu commented Dec 11, 2019

This is happening to me too

@hsubox76 hsubox76 added this to the 7.6.0 milestone Dec 12, 2019
@hsubox76

This comment has been minimized.

Copy link
Contributor

@hsubox76 hsubox76 commented Dec 12, 2019

The temporary change to suppress the error, mentioned by @mmermerkaya above, is in 7.6.0 which has just been released.

@CodeByBryan

This comment has been minimized.

Copy link

@CodeByBryan CodeByBryan commented Dec 14, 2019

Using 7.6.0 and am still having the same issue!

@mmermerkaya

This comment has been minimized.

Copy link
Member

@mmermerkaya mmermerkaya commented Dec 16, 2019

If you're only seeing the error in the console, that's normal. My PR is still logging the error in the console, but it should not stop the getToken call from completing successfully.

@CodeByBryan

This comment has been minimized.

Copy link

@CodeByBryan CodeByBryan commented Dec 18, 2019

I am receiving a token value when https://firebaseinstallations.googleapis.com/v1/projects/.../authTokens:generate is called, but get a "500" error when calling getToken()

@GoktuqCan

This comment has been minimized.

Copy link

@GoktuqCan GoktuqCan commented Dec 19, 2019

I get this error when using "127.0.0.1" instead of localhost.
BUT if i use "localhost" even the getToken() is not working. Showing CORS policy error.

  • On localhost error is(cannot getToken())
OPTIONS https://firebaseinstallations.googleapis.com/v1/projects/{project_id}/installations/{some_token}/authTokens:generate 403

Access to fetch at 'https://firebaseinstallations.googleapis.com/v1/projects/{project_id}/installations/{some_token}/authTokens:generate' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
  • On 127.0.0.1 error(getting token but shows this error) is:
DELETE https://fcmregistrations.googleapis.com/v1/projects/{project_id}/regis.../{FCM_token} 500

FirebaseError: Messaging: A problem occured while unsubscribing the user from FCM: Internal error encountered. (messaging/token-unsubscribe-failed). (messaging/token-unsubscribe-failed).
@mmermerkaya

This comment has been minimized.

Copy link
Member

@mmermerkaya mmermerkaya commented Dec 19, 2019

The CORS error looks like an unrelated issue. Can you create a new bug report for that?

@Ridermansb

This comment has been minimized.

Copy link

@Ridermansb Ridermansb commented Dec 22, 2019

@mmermerkaya did you created new issue for CORS problem?
I'm having the same issue.

@ctavan

This comment has been minimized.

Copy link

@ctavan ctavan commented Dec 22, 2019

@Ridermansb @mmermerkaya @GoktuqCan @CodeByBryan could you check if #2467 matches the issue that you are observing?

@CodeByBryan

This comment has been minimized.

Copy link

@CodeByBryan CodeByBryan commented Dec 23, 2019

I am having the issue in a Chrome Extension. when getToken() is called I recieve:

DELETE https://fcmregistrations.googleapis.com/v1/projects/{project_id}/regis.../{FCM_token} 500
FirebaseError: Messaging: A problem occured while unsubscribing the user from FCM: Internal error encountered. (messaging/token-unsubscribe-failed).
(messaging/token-unsubscribe-failed).<

I am not getting any CORS errors

@niklat22

This comment has been minimized.

Copy link

@niklat22 niklat22 commented Dec 24, 2019

Same error for user resubscribe:

FirebaseError: Messaging: A problem occured while unsubscribing the user from FCM: Internal error encountered. (messaging/token-unsubscribe-failed). (messaging/token-unsubscribe-failed).
at Ik. (https://www.gstatic.com/firebasejs/7.6.0/firebase.js:1:811146)
at https://www.gstatic.com/firebasejs/7.6.0/firebase.js:1:52093
at Object.next (https://www.gstatic.com/firebasejs/7.6.0/firebase.js:1:52198)
at n (https://www.gstatic.com/firebasejs/7.6.0/firebase.js:1:50968)

@Depender-Sethi

This comment has been minimized.

Copy link

@Depender-Sethi Depender-Sethi commented Jan 4, 2020

Waiting for the fix, for the time being I'm using a way around by checking the error code and calling the function again because this error is thrown only the first time.

const turnOnNotification = async () => {
    const uid = firebase.auth().currentUser.uid;
    const messaging = fb.messaging();
    try {
      await messaging.requestPermission();
      const token = await messaging.getToken();
      // send to server
    } catch (err) {
      if (err.code === "messaging/token-unsubscribe-failed")
        turnOnNotification();
    } 
  };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.