Popular question How do I uninstall a Service Worker? has a fine answer for unregistering a service worker using JavaScript. How can I get the service worker to clear any named caches when it unregisters?
From MDN unregister, The service worker will finish any ongoing operations before it is unregistered. So, it sounds like it should be possible to listen for an uninstall event, but no such event exists as far as I can tell. For giggles, I tried adding self.addEventListener('uninstall', ...) to the service worker, but as expected, it did not fire on unregister. I also tried listening for any message that might be sent on unregister... no dice.
I also considered watching the service worker state, but none of installing, installed, activating, activated, and redundant appear relevant. Not to mention, it doesn't look like message passing to the service worker is possible, so I'm not sure what I'd do with an uninstalling state from outside the service worker anyways.
Reaching for straws, while I see references to an uninstalling flag, I haven't seen it exposed anywhere. Suggestions?