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

FCM Messaging breaks in version 7.0.0 or after #2590

Closed
basvandenheuvel opened this issue Feb 3, 2020 · 23 comments · Fixed by #2638
Closed

FCM Messaging breaks in version 7.0.0 or after #2590

basvandenheuvel opened this issue Feb 3, 2020 · 23 comments · Fixed by #2638

Comments

@basvandenheuvel
Copy link

  • Operating System version: Windows 10
  • Browser version: Chrome 79
  • Firebase SDK version: 7.0.0+
  • Firebase Product: Messaging

Problem

Currently we are using Firebase SDK 6.5.0. Whenever we update to version 7.0.0 or later (we tried multiple versions including 7.0.0 and 7.8.0) Messaging stops working.
It looks like the background messaging keeps working when the website does not have focus. However when the website does have focus the FCM messaging does not work.

Ofcourse we followed the changelog and enabled the FCM Messaging API.

Relevant Code:

The following code is used in version 6.5.0 and works fine, but breaks in 7.0.0 or after:

// Imports
import * as firebase from 'firebase/app';
import 'firebase/messaging';
// Messaging
this.messaging = firebase.messaging();
// Subscribing to messages 
this.messaging.onMessage((result: any) => {
    console.log(result);
});
@rommelpe
Copy link

rommelpe commented Feb 3, 2020

Thanks for reporting the issue, @basvandenheuvel. I can't seem to replicate it.

  • Were you able to reproduce it using quickstart?
  • Have you noticed any significant logs from browser's DevTool?
  • Could you share a working repro that we could run locally?

@basvandenheuvel
Copy link
Author

Hi @rommelpe , thanks for your reply.

  1. I just tired the quickstart, also with the quickstart i do not get messages when the website has focus... i do get the messages in the background.

  2. Haven't seen any logs.

  3. I do not have anything for now...

@rommelpe
Copy link

rommelpe commented Feb 3, 2020

Sorry for the confusion, @basvandenheuvel. It's an intended behavior. If the page is open and focused, you will not see a notification and as a result, you'll receive a callback in onMessage in the page.

If the page is in the background (i.e. not focused) the background message handler will be called and will show a notification.

See here:

Firebase notifications behave differently depending on the foreground/background state of the receiving app. If you want foregrounded apps to receive notification messages or data messages, you’ll need to write code to handle the onMessageReceived callback. For an explanation of the difference between notification and data messages, see Message types.

@rommelpe rommelpe closed this as completed Feb 3, 2020
@basvandenheuvel
Copy link
Author

@rommelpe

I think i introduced the confusion.

It is indeed the onMessage callback that is not triggered when the website has focus. The same problem occurs when i connect our environment with the quickstart...

The process that should trigger in background does work...

@GoktuqCan
Copy link

GoktuqCan commented Feb 5, 2020

I'm facing the same problem after upgrading from 7.6.2 to 7.8.0.
Background working but onMessage not receiving anything.

@basvandenheuvel did you find any solution?

@rommelpe i think this issue needs to be reopened.

Just checked 7.7.0 has the same problem.

@basvandenheuvel
Copy link
Author

@GoktuqCan not yet....

It looks like for me any version of 7.x.x is broken.

I doubt it is my firebase environment since the changelog is straightforward and we followed it. However, why else would their quickstart onMessage not work if i connect it to our environment...

@GoktuqCan
Copy link

@basvandenheuvel try npm i [email protected] and of course change importScripts versions in
firebase-messaging-sw.js(if you have) service worker with same version. This version working for me.

@basvandenheuvel
Copy link
Author

@GoktuqCan @rommelpe

Just tried again to make the quickstart work for me, no luck with eitehr 7.6.2 or 7.8.0.

I added the firebase config of my environment, i host the index.html and see a token being generated for me. I go to the firebase console page of messaging and send a test message.

Focus -> Nothing happens, i don't even see the console.log inside my onMessage
No focus -> i do get a windows notification, works as expected

@GoktuqCan
Copy link

@basvandenheuvel Are you just editing package.json or using the npm i [email protected] command?
If you just downgrading from package.json then package-lock.json may not be changed.

@rommelpe
Copy link

rommelpe commented Feb 6, 2020

Thanks for getting back and continuing on working the issue, @basvandenheuvel @GoktuqCan. I was able to reproduce it using quickstart. It looks like the issue was introduced in v7.7.0.

@hsubox76 onMessage has stopped receiving responses from v7.7.0. Can you confirm if it's a bug on our SDK, intended behavior or might be related to our implementation?

@rommelpe rommelpe reopened this Feb 6, 2020
@hsubox76
Copy link
Contributor

hsubox76 commented Feb 6, 2020

There was a large refactor of the messaging codebase between 7.6.2 and 7.7.0. One of the changes may have impacted this. I'll try to dig into it. PR for my reference: #2484

@mmermerkaya
Copy link
Contributor

Please make sure that your service worker is actually updated. You can force this by clearing site data in Chrome. Go to DevTools -> Application tab -> "Clear storage" from the menu on the left -> Clear site data.

onMessage works in my test app on 7.8.1 after doing what I described.

@rommelpe
Copy link

Thanks, @mmermerkaya. I was able to get rid of the issue after updating sw to latest version. Were you able to try it out on your end @basvandenheuvel @GoktuqCan?

Closing this issue. Should you have any other questions/clarifications, leave a comment and we're happy to look into it.

@GoktuqCan
Copy link

@rommelpe sorry but problem still remains.

@rommelpe
Copy link

@GoktuqCan Here's a sample response on my end after updating firebase-messaging-sw.js to v7.8.1. Were you able to reproduce it using quickstart?

image

You may want to check third party extension(s) on your browser that might be blocking the response. If nothing works after upgrading & clearing the browser's storage, the last resort would be reinstalling your browser.

@GoktuqCan
Copy link

GoktuqCan commented Feb 13, 2020

@rommelpe i added a new user to chrome. New user is clean browser and it works for that one.
But what should users those already using application do now?
We cannot say everyone to clear browser storage. That doesn't work for current users that we have anyway.
You can reproduce using npm i [email protected](this one works) get token after that update to npm i [email protected](now working) get token. Try onMessage for both.
Note: Also updating firebase-messaging-sw.js too.

@Feiyang1
Copy link
Member

@GoktuqCan your users should get the updated service worker eventually. Browsers check for updates automatically after navigations and functional events such as push and sync.

@GoktuqCan
Copy link

@Feiyang1 Problem is not about receiving, it is about updating from previous version. Even if i hard reload page and clear cache, updating from 7.6.2 to 7.8.1 not working. If user starts to using application from 7.8.1 has no problem.

@Feiyang1
Copy link
Member

@GoktuqCan I believe your issue is that the installed sw which references 7.6.2 failed to update to the newer version that references 7.8.1.
I found that the timing by which browser updates sw is somewhat unpredictable, and it still confuses me.
I made a PR that manually updates sw when there is an update, so it will hopefully solve your problem. #2638

Once it is merged, can you try installing the canary build to verify if it fixes your issue? Thanks!

@Feiyang1 Feiyang1 reopened this Feb 15, 2020
@GoktuqCan
Copy link

@Feiyang1 yes i can check.

@Feiyang1
Copy link
Member

Feiyang1 commented Feb 19, 2020

@GoktuqCan The fix is in canary build. Can you please do npm i firebase@canary and see if your issue goes away?

@GoktuqCan
Copy link

@Feiyang1 canary version seems working now. In service worker canary version throw exception Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'https://www.gstatic.com/firebasejs/7.8.2-canary.261bbd54/firebase-app.js' failed to load.. So i used 7.8.2 instead.

Working versions are:
in package.json: "firebase": "^7.8.2-canary.261bbd54"
in firebase-messaging-sw.js:

importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/7.8.2/firebase-messaging.js');

Thanks for the help i guess fix will come with 7.8.3?

@Feiyang1
Copy link
Member

Awesome! thanks for confirming.
Yep, it will be in 7.8.3. the script error is expected, because we don't publish canary builds to CDN.

@firebase firebase locked and limited conversation to collaborators Mar 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants