Skip to content

Commit 36c694e

Browse files
authored
auto-resume on tab/browser close (#7)
1 parent 5fe98a5 commit 36c694e

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

index_tmpl.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,26 @@
124124
{{- if .IsBreaking }}
125125
<button class="btn" title="resume from a break" onclick="javascript:resume();">
126126
Resume from Breakpoint
127-
</button>
127+
</button>
128+
<script>
129+
(function() {
130+
let sent = false;
131+
132+
function sendBreak() {
133+
if (sent) return;
134+
sent = true;
135+
const blob = new Blob([JSON.stringify({action: 'resume'})], {type: 'application/json'});
136+
navigator.sendBeacon(window.location.href, blob);
137+
}
138+
139+
document.addEventListener('visibilitychange', () => {
140+
if (document.visibilityState === 'hidden') sendBreak();
141+
});
142+
143+
window.addEventListener('beforeunload', sendBreak);
144+
window.addEventListener('pagehide', sendBreak);
145+
})();
146+
</script>
128147
{{- end }}
129148
</p>
130149

0 commit comments

Comments
 (0)