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.waitForEvent()
Added in: v1.8 asyncWaits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.
Arguments
Event name, same one would pass into
webSocket.on(event).optionsOrPredicatefunction() | Object(optional)Either a predicate that receives an event or an options object. Optional.
predicatefunction()Receives the event data and resolves to truthy value when the waiting should resolve.
timeoutfloat(optional)Maximum time to wait for in milliseconds. Defaults to
0- no timeout. The default value can be changed viaactionTimeoutoption in the config, or by using thebrowserContext.setDefaultTimeout()orpage.setDefaultTimeout()methods.
predicatefunction()(optional)Receives the event data and resolves to truthy value when the waiting should resolve.
signalAbortSignal(optional) Added in: v1.62Allows to cancel the waiting using an
AbortSignal. If the signal is aborted, the waiting will be aborted and the operation will throw an error. Note that providing a signal does not disable the default timeout, which can be changed usingbrowserContext.setDefaultTimeout(); passtimeout: 0to disable the timeout entirely.
Returns
Promise<any>
Events
webSocket.on('close')
Added in: v1.8Fired when the websocket closes.
Event data
WebSocket
webSocket.on('frameReceived')
Added in: v1.9Fired when the websocket receives a frame.
Event data
Object
webSocket.on('frameSent')
Added in: v1.9Fired when the websocket sends a frame.
Event data
Object
webSocket.on('socketError')
Added in: v1.9Fired when the websocket has an error.
Event data
string