moved to before-unload event

This commit is contained in:
Baipyrus 2023-01-18 15:05:59 +01:00
parent 93cc4c14ae
commit a098da6f09

View File

@ -1,5 +1,5 @@
// Handle server connection // Handle server connection
document.body.onunload = () => { window.addEventListener('beforeunload', () => {
if (user.connected) if (user.connected)
fetch('/disconnect', { fetch('/disconnect', {
method: 'POST', method: 'POST',
@ -11,7 +11,7 @@ document.body.onunload = () => {
id: user.id id: user.id
}) })
}).then(res => {}); }).then(res => {});
}; });
fetch('/connect').then(res => { fetch('/connect').then(res => {
if (res.status === 200) { if (res.status === 200) {
user.connected = true; user.connected = true;