The error event will only be fired before it also fires the close event, at least with the help of implementations that properly execute the specification, i.e. you will get error and close as a pair or just close .
The process for closing websocket consists of 3 steps , the second of which, if necessary, triggers the error event:
- If the user agent needed a WebSocket connection failure or if the WebSocket connection was closed after it was marked as full, fire a simple event called
error in the WebSocket object. [PVA]
Before the third step, close calls:
- Create a trusted event that uses the
CloseEvent interface with the event type close ...
And since both of these steps are one after another inside the same task in the queue, your event handlers should be called one after another, without any other events or tasks occurring between them.
source share