WebSocket
Added in: v1.8The 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
webSocket.isClosed()
Added in: v1.8Indicates that the web socket has been closed.
Returns
boolean
webSocket.url()
Added in: v1.8Contains the URL of the WebSocket.
Returns
string
webSocket.waitForFrameReceived()
Added in: v1.10Performs 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.
Arguments
predicatefunction(WebSocketFrame): boolean(optional) Added in: v1.9Receives the WebSocketFrame object and resolves to truthy value when the waiting should resolve.
timeoutfloat(optional) Added in: v1.9Maximum time to wait for in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thebrowserContext.setDefaultTimeout().
callbackRunnableAdded in: v1.9Callback that performs the action triggering the event.
Returns
WebSocketFrame
webSocket.waitForFrameSent()
Added in: v1.10Performs 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.
Arguments
predicatefunction(WebSocketFrame): boolean(optional) Added in: v1.9Receives the WebSocketFrame object and resolves to truthy value when the waiting should resolve.
timeoutfloat(optional) Added in: v1.9Maximum time to wait for in milliseconds. Defaults to
30000(30 seconds). Pass0to disable timeout. The default value can be changed by using thebrowserContext.setDefaultTimeout().
callbackRunnableAdded in: v1.9Callback that performs the action triggering the event.
Returns
WebSocketFrame
Events
webSocket.onClose()
Added in: v1.8Fired when the websocket closes.
Event data
WebSocket
webSocket.onFrameReceived()
Added in: v1.9Fired when the websocket receives a frame.
Event data
WebSocketFrame
webSocket.onFrameSent()
Added in: v1.9Fired when the websocket sends a frame.
Event data
WebSocketFrame
webSocket.onSocketError()
Added in: v1.9Fired when the websocket has an error.
Event data
string