diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index a836e64..243d523 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -830,7 +830,11 @@ $style = @' }, 10_000); }); - + // when the browser window is closed (X), notify the server to quit + window.addEventListener('beforeunload', () => { + // keepalive: true ensures the request is sent even as the page unloads + fetch('/quit', { method: 'GET', keepalive: true }); + });