I am currently utilizing FCM, and my goal is to update certain content on the page when a notification is received in the background. This involves sending a request to the website, even if the browser tab is not actively being viewed but the user is still on the site.
Can this functionality be achieved?
I have attempted to implement this in my service worker:
clients.matchAll().then(function (clients){
clients.forEach(function(client){
client.postMessage({
msg: "Hey I just got a message for you!",
data: 'do-this'
});
});
});
and also within my application:
navigator.serviceWorker.addEventListener('message', event => {
console.log(event);
});
Is it feasible for the service worker to communicate with the website in the background like this?