docs/src/api/class-websocket.md
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].
Fired when the websocket closes.
payload <[string]|[Buffer]> frame payloadFired when the websocket receives a frame.
payload <[string]|[Buffer]> frame payloadFired when the websocket sends a frame.
Fired when the websocket has an error.
Indicates that the web socket has been closed.
Contains the URL of the WebSocket.
Waits 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.
event <[string]>Event name, same one would pass into webSocket.on(event).
optionsOrPredicate ?<[function]|[Object]>
predicate <[function]> Receives the event data and resolves to truthy value when the waiting should resolve.timeout ?<[float]> Maximum time to wait for in milliseconds. Defaults to 0 - no timeout. The default value can be changed via actionTimeout option in the config, or by using the [method: BrowserContext.setDefaultTimeout] or [method: Page.setDefaultTimeout] methods.Either a predicate that receives an event or an options object. Optional.
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.
predicate <[function]([WebSocketFrame]):[boolean]>Receives the [WebSocketFrame] object and resolves to truthy value when the waiting should resolve.
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.
predicate <[function]([WebSocketFrame]):[boolean]>Receives the [WebSocketFrame] object and resolves to truthy value when the waiting should resolve.
:::note
In most cases, you should use [method: WebSocket.waitForEvent].
:::
Waits for given event to fire. If predicate is provided, it passes
event's value into the predicate function and waits for predicate(event) to return a truthy value.
Will throw an error if the socket is closed before the event is fired.