Skip to content

Commit

Permalink
Merge pull request #21 from leotaku/fix-chrome-lock
Browse files Browse the repository at this point in the history
Abort long poll on page unload
  • Loading branch information
leotaku authored Jan 6, 2025
2 parents 91aaa0e + 66e7874 commit 0a3b2d8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion assets/polling.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script type="module">
const controller = new AbortController();
var unloaded = false;

addEventListener('beforeunload', (event) => {{
unloaded = true;
controller.abort();
}});

const retry = (url) => {{
Expand All @@ -16,7 +18,7 @@
}};

const main = () =>
fetch("{long_poll}", {{ cache: "no-store" }})
fetch("{long_poll}", {{ cache: "no-store", signal: controller.signal }})
.then((rsp) => rsp.text())
.catch(() => null)
.then(() => console.log("[tower-livereload] disconnected..."))
Expand Down

0 comments on commit 0a3b2d8

Please sign in to comment.