Despite all my research, I'm still unable to solve this issue. My task involves executing some functions when a user leaves my page. To achieve this, I utilized window.onbeforeunload to warn the user about leaving the page and window.onunload to initiate the tasks. However, I encountered a problem - the onunload function does not complete before the page is closed.
In an attempt to resolve this, I experimented with the following code:
window.onunload = function() {
//freezeScreen(5000);
console.log("destroy finished 1/8");
$.each(_tabClassObj, function(index) {
_tabClassObj[index].destroy();
});
console.log("destroy finished 2/8");
_tabClassObj = {};
console.log("destroy finished 3/8");
_terminalTabCounter = 0;
console.log("destroy finished 4/8");
window.onbeforeunload = null;
console.log("destroy finished 5/8");
window.onunload = null;
console.log("destroy finished 6/8");
}
My console log displays:
destroy finished 1/8
WebSocket is already in CLOSING or CLOSED state.
WebSocket is already in CLOSING or CLOSED state.
WebSocket is already in CLOSING or CLOSED state.
WebSocket is already in CLOSING or CLOSED state.
WebSocket is already in CLOSING or CLOSED state.
I tried delaying the browser UI closure using the freeze function, which delays shutdown by 5 seconds... yet the issue persists. I also attempted using setTimeout without success. Can you identify what's causing the problem? Any guidance would be appreciated.