firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

[Messaging] "This site has been updated in the background"

Open gigaga opened this issue 3 years ago • 3 comments

[REQUIRED] Describe your environment

  • Operating System version: Android 10
  • Browser version: Chrome
  • Firebase SDK version: 8.2.0 (9.9.1 in modular)
  • Firebase Product: messaging

[REQUIRED] Describe the problem

When I try to send message to my PWA when Chrome is not focused, I receive my message as expected but some seconds before, I receive another message "this site has been updated in the background".

My code is :

firebase-messaging-sw.js

// Scripts for firebase and firebase messaging
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js");

firebase.initializeApp(firebaseConfig);

messaging.onBackgroundMessage(function (payload) {
  console.log("Received background message ", payload);
  self.registration.update();
  // Customize notification here
  if (!payload.notification && payload.data.title) {
    const notificationTitle = payload.data.title;

    // We have to convert message from firebase messaging to Web notification
    // All what is not body so, we have to added it into data.data
    self.registration.showNotification(notificationTitle, webOptions);
  }
});

What I don't understand is that from only the following content into (with only firebase declaration scripts), I receive this "this site has been updated in the background" message too :(...

// Scripts for firebase and firebase messaging
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-app.js");
importScripts("https://www.gstatic.com/firebasejs/8.2.0/firebase-messaging.js");

Also, from an empty firebase-messaging-sw.js, nothing is displayed.

gigaga avatar Jul 27 '22 12:07 gigaga

Hi @gigaga, thanks for reaching out. I tried replicating, but I wasn't able to reproduce the same behavior. Are you using 2 service workers? It is possible that the firebase one is being overwritten by your other service worker.

jbalidiong avatar Aug 03 '22 14:08 jbalidiong

hi @jbalidiong , Yes, I've another service worker. How can I have a correct behavior in this case ? From the following content of firebase-messaging-sw.js, I have the notification "this site has been updated in the background" :

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

Is it because my other service worker does not manage the message ? And why, from an empty firebase-messaging-sw.js, no notification is displayed (as expected) ?

Regards,

gigaga avatar Aug 03 '22 15:08 gigaga

Hi @gigaga, apologies if it took time to answer your inquiries as I've consulted this with our engineers. Usually, the error message: "This site has been updated in the background" normally shows when the app failed to call showNotification() in the sw. However, I noticed that you have called the showNotification() in your sw. If you put a console.log in the callback you pass to onBackgroundMessage, does it get displayed? I also noticed that you are using very old Firebase scripts in the service worker. Can you update them to the same version as your client code (for minimal change use the compat version)?

jbalidiong avatar Aug 09 '22 11:08 jbalidiong

Hi @jbalidiong,

In fact I already tried to add console.log in my onBackgroundMessage method, and in this case, just one message is logged (for 2 notifications, the right and the "the site has been updated...").

I tried by using Firebase messaging v9.9.1 (in modular) too and I added the same issue.

However, for few days, I no longer have this notification (I did nothing). I don't know if it is definitively fixed... I am going to test again.

Regards,

gigaga avatar Aug 10 '22 22:08 gigaga

Thanks for sharing more details. Let me know if the behavior persists or if you no longer see the error message.

jbalidiong avatar Aug 11 '22 09:08 jbalidiong

I'll be closing this for now. If the issue persists, feel free to comment and reopen this issue.

jbalidiong avatar Aug 30 '22 08:08 jbalidiong