Is there any windows apps/google chrome flags/google chrome extension/javascript methods
or any other thing that would allow to bring a chrome window from b
I solved it by adding this in the service worker file:
self.addEventListener('push', function (e) {
if (e.data) {
var payloadData = e.data.json();
self.clients.matchAll({includeUncontrolled: true}).then(function (clients) {
clients[0].postMessage(payloadData); // you can do foreach but I only needed one client to open one window
});
}
});
And this in the main.js file:
function openNotificationWindow(url) {
var myWindow = window.open(url); // Opens a new window
myWindow.focus();
myWindow.location.reload(true);
}
navigator.serviceWorker.addEventListener('message', function (event) {
if (typeof event.data.data !== 'undefined') {
openNotificationWindow(url);
}
});
Now everytime I send a notification either with the window in foreground or in the background the push
event fires in the serviceworker and then is using postMessage()
to comunicate with the some main.js file where you have access to the window
DOM component.