firebase-js-sdk
firebase-js-sdk copied to clipboard
[Messaging] "This site has been updated in the background"
[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.
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.
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,
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)?
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,
Thanks for sharing more details. Let me know if the behavior persists or if you no longer see the error message.
I'll be closing this for now. If the issue persists, feel free to comment and reopen this issue.