I'm prompting the user that their connection will be interrupted if they leave the page, however socketcluster will optimistically trigger disconnect before the user has made their selection at the confirmation prompt. The offending code is:
var unloadHandler = function () {
self.disconnect();
};
if (global.attachEvent) {
global.attachEvent('onunload', unloadHandler);
} else if (global.addEventListener) {
global.addEventListener('beforeunload', unloadHandler, false);
}
All beforeunload events occur as near to "at the same time" as possible, so the user is not able to cancel unloading of the page before disconnection occurs.
I have toyed with using e.stopImmediatePropagation() in my beforeunload event handler, but this is only effective if my script loaded before socketcluster. Then it seems non-trivial to ensure trailing beforeunload events fire afterward.
Perhaps socketcluster could try more aggressively to attach to the unload event, rather than the more commonly utilised beforeunload event.
I'm prompting the user that their connection will be interrupted if they leave the page, however socketcluster will optimistically trigger
disconnect
before the user has made their selection at the confirmation prompt. The offending code is:All
beforeunload
events occur as near to "at the same time" as possible, so the user is not able to cancel unloading of the page before disconnection occurs.I have toyed with using
e.stopImmediatePropagation()
in mybeforeunload
event handler, but this is only effective if my script loaded before socketcluster. Then it seems non-trivial to ensure trailingbeforeunload
events fire afterward.Perhaps socketcluster could try more aggressively to attach to the
unload
event, rather than the more commonly utilisedbeforeunload
event.