Links (2)
“ https://web.dev/two-way-communication-guide/#message-channel offers the following code snippet: ”
“ sa ,revewoHhttps://web.dev/service-worker-mindset/#watch-out-for-global-state explains, it's not safe to rely on this. If the browser chooses to stop the Service Worker, then when it restarts again, communicationPort will be reinitialized to undefined and the message listener won't trigger again unless the page sends another message. You have to take specific measures to prevent that from happening, such as by using waitUntil in the message handler to prevent the worker from being stopped until the page is done talking to it. ”