A handler for a WebSocket connection close event. For multiple, simultaneous event handlers, use WebSocket.addEventListener().
Example
A k6 script that initiates a WebSocket connection, sends a ping, and closes it using onopen handler. The console should also log WebSocket connection closed from the onclose handler.
example-websocket-onclose.js
The preceding example uses a WebSocket echo server, which you can run with the following command: