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
document.body.onunload = () => {
window.addEventListener('beforeunload', () => {
if (user.connected)
fetch('/disconnect', {
method: 'POST',
@ -11,7 +11,7 @@ document.body.onunload = () => {
id: user.id
})
}).then(res => {});
};
});
fetch('/connect').then(res => {
if (res.status === 200) {
user.connected = true;