A while back, we tried to figure this out by having the browser send a "window closed" event, but we found this extremely unreliable. This was a system that only worked on latest versions of a few modern browsers and even then those events did not send 100% of the time.
In clinical drug trials, depression therapy studies, etc., you have participants that you check in with every 3-6 months because it's unrealistic and super expensive to monitor everybody every day. So if someone relapses, dies, experiences a heart attack, or whatever event of interest is, you only know that it happened sometime between a time point t1 and a time point t2. You end up with "censored" data, which is the foundation of survival analysis and its application in epidemiology.
Realizing that an opened tab is basically a participant and we want to know when the tab's "death" occurred, we created a system (TSS2) wherein the browser would "check in" by sending these "hey, I'm still alive!" events at various time points. If the user closes the tab before the next scheduled check-in, we now have an interval that we can apply survival analysis to.