Description
Describe the bug
Clients close the transport on 'beforeunload', even if the closing process was prevented.
To Reproduce
See my fiddle fork: https://.com/athouary/socket.io-fiddle
Once on the page, randomly click on a blank space to make sure that the browser has detected a user interaction. Then try to close the tab. You should be asked if you really want to exit the page. Wait a few seconds, click cancel and see the error in the console: Uncaught Error: Transport not open
.
Engine.IO server version: 5.0.0
Expected behavior
If the user decides to stay on the page instead of closing it, the socket transport should not be closed. I would suggest to close it on the 'unload' event instead of the 'beforeunload' one.
Platform:
I reproed the problem on Chrome 89 and Firefox 86, with a MacOS device. I'm quite sure it does not really matter as long as preventing the page from closing is possible.