3

Is there a reliable way for service workers to detect if the tab that registered it has closed? The use case I'm concerned about is trying to get the service worker to run specific code after a tab is closed?

The way I'm doing this currently is by sending healthcheck messages to the service worker, and once these messages stop, we can assume that the tab has been closed. However, this is not completely reliable because browsers throttle tabs that are not in focus, which leads to healthcheck messages being sent inconsistently.

Anyone have any other ideas?

Kevin Shi
  • 31
  • 2
  • 1
    Possible duplicate of [What happens to an HTML5 web worker thread when the tab is closed while it's running?](https://stackoverflow.com/questions/8875310/what-happens-to-an-html5-web-worker-thread-when-the-tab-is-closed-while-its-run) – Nathan Feb 06 '19 at 20:03
  • This goes into more detail: https://stackoverflow.com/a/20105455/10559113 – Nathan Feb 06 '19 at 20:06
  • Are you relying on your service worker's life span? – McMurphy Feb 07 '19 at 01:48

0 Answers0