We can't rely on global variables in a service worker, as the global state is wiped out each time the service worker is terminated (and eventually restarted).
How does one know when the service worker has been terminated? How does one know when it is restarted? There doesn't seem to be any lifecycle event that we can hook into.
What I'm looking for is something like self.addEventListener('terminate', async () => { and/or self.addEventListener('restart', async () => {.
Am I missing something? 🤨