Skip to main content

WebSocket

The WebSocket class represents WebSocket connections within a page. It provides the ability to inspect and manipulate the data being transmitted and received.

If you want to intercept or modify WebSocket frames, consider using WebSocketRoute.


方法 (Methods)

isClosed

Added before v1.9 webSocket.isClosed

Indicates that the web socket has been closed.

使用方式

WebSocket.isClosed();

傳回值


url

Added before v1.9 webSocket.url

Contains the URL of the WebSocket.

使用方式

WebSocket.url();

傳回值


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.

使用方式

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

參數

  • options WebSocket.WaitForFrameReceivedOptions (optional)

  • callback Runnable Added in: v1.9#

    Callback that performs the action triggering the event.

傳回值


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.

使用方式

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

參數

  • options WebSocket.WaitForFrameSentOptions (optional)

  • callback Runnable Added in: v1.9#

    Callback that performs the action triggering the event.

傳回值


事件 (Events)

onClose(handler)

Added before v1.9 webSocket.onClose(handler)

Fired when the websocket closes.

使用方式

WebSocket.onClose(handler)

事件資料


onFrameReceived(handler)

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

Fired when the websocket receives a frame.

使用方式

WebSocket.onFrameReceived(handler)

事件資料


onFrameSent(handler)

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

Fired when the websocket sends a frame.

使用方式

WebSocket.onFrameSent(handler)

事件資料


onSocketError(handler)

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

Fired when the websocket has an error.

使用方式

WebSocket.onSocketError(handler)

事件資料