So you want to track the online status of a browser (not of a user, since it might not have any tab open other than, for example, the Chrome “New Tab” tab and since a different person can be using the browser), right?
Did you intend for it to be a service worker event, or a regular event (to which HTML documents can listen)?
If you can come up with a solid use case, that would help stir this discussion in the right direction. So far, you mentioned that you could “push a service worker” depending on whether the browser is exiting or not. Perhaps you meant push notifications?
If so, can you come up with a solid use case for sending push notifications only when the browser is running?