Skip to main content

WebSocket

The WebSocket class represents websocket connections in the page.


Methods

isClosed

Added in: v1.8 webSocket.isClosed

Indicates that the web socket has been closed.

Usage

WebSocket.isClosed();

Returns


url

Added in: v1.8 webSocket.url

Contains the URL of the WebSocket.

Usage

WebSocket.url();

Returns


waitForFrameReceived

Added in: v1.10 webSocket.waitForFrameReceived

Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is received.

Usage

WebSocket.waitForFrameReceived(callback);
WebSocket.waitForFrameReceived(callback, options);

Arguments

  • options WebSocket.WaitForFrameReceivedOptions (optional)

  • callback Runnable Added in: v1.9#

    Callback that performs the action triggering the event.

Returns


waitForFrameSent

Added in: v1.10 webSocket.waitForFrameSent

Performs action and waits for a frame to be sent. If predicate is provided, it passes WebSocketFrame value into the predicate function and waits for predicate(webSocketFrame) to return a truthy value. Will throw an error if the WebSocket or Page is closed before the frame is sent.

Usage

WebSocket.waitForFrameSent(callback);
WebSocket.waitForFrameSent(callback, options);

Arguments

  • options WebSocket.WaitForFrameSentOptions (optional)

  • callback Runnable Added in: v1.9#

    Callback that performs the action triggering the event.

Returns


Events

onClose(handler)

Added in: v1.8 webSocket.onClose(handler)

Fired when the websocket closes.

Usage

WebSocket.onClose(handler)

Event data


onFrameReceived(handler)

Added in: v1.9 webSocket.onFrameReceived(handler)

Fired when the websocket receives a frame.

Usage

WebSocket.onFrameReceived(handler)

Event data


onFrameSent(handler)

Added in: v1.9 webSocket.onFrameSent(handler)

Fired when the websocket sends a frame.

Usage

WebSocket.onFrameSent(handler)

Event data


onSocketError(handler)

Added in: v1.9 webSocket.onSocketError(handler)

Fired when the websocket has an error.

Usage

WebSocket.onSocketError(handler)

Event data