Send message from a service worker
Communication between service workers and the clients browser window can be achieved by simply doing: self.clients.matchAll().then((clients) => { clients.forEach((client) => client.postMessage({ msg: "Hello from SW" })) }) The variable self is a reserved keyword in a service worker context. It references the global scope of the current worker execution scope and has some useful properties. It is like the window object of a JavaScript browser context. In the above snippet, all the clients that run the service worker are loaded, then the .postMessage is called to send message directly to the original javascript runtime of the service worker. ...