I have a PWA website that can send and receive push notifications when somebody makes a call on the site.
I am using Firebase Messaging for push notifications, here is some code:
notification:
{
title:"Video call!",
body:"Video call from:"+m,
click_action: "https://......netlify.app/?x="+m
},
data:
{
title:"Video call!",
email:m,
contact_link:"https://......netlify.app/?x="+m
I append some important parameters in the URL. The result: When the site is in focus, I receive the notification in the background the onMessage function of Firebase which I can handle. It works. When the site is closed, the click_action opens the site with the parameters, and it's also working. The only thing that does not work is when the site is inactive (another tab is in focus in the browser). The notification comes in, I click on the push-notification, the site becomes focused, but nothing changes, the site does not even reload. The URL parameters stay the same as before, they do not change to the one in the link.
So what can I do to make the inactive website change to the same site but with the parameters in the link?
My service worker does not do much, but here it is, in case it's needed for a solution:
firebase.initializeApp({
....
});
const messaging=firebase.messaging();
messaging.setBackgroundMessageHandler(function (payload) {
console.log(payload);
});
Solved it by using onBackgroundMessage() in the service worker, which is exactly for situations like this.