'Does the service worker have an "exit" event?
In the process of operation, the service worker contains a certain amount of data that must be saved before the service worker is completed, as well as it is necessary for monitoring.
How do I find out when the service worker is finished?
Solution 1:[1]
There is no "exit" event that gets fired before a service worker thread is terminated. Service workers are expected to be ephemeral, starting up when there's a relevant event and then shutting down shortly after that event has been handled.
The events that can wake up a service worker tend to implement the ExtendableEvent interface, and you can perform asynchronous work inside of an event handler as long as that work is wrapped in a promise which you pass to event.waitUntil(). Each browser has its own time limits on how much time can be spent inside of waitUntil() before the service worker thread is unconditionally terminated.
Generally speaking, if you have work you need to perform inside of a service worker, and you want some way of indicating that the work has successfully completed, you're going to want to either use postMessage() to send a message to one or more open client pages, or write "completion" data to somewhere that's observable from client pages, like IndexedDB or the Cache Storage API.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeff Posnick |
