2021-01-07 11:46:05 -08:00
# class: WebSocket
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
The [WebSocket] class represents websocket connections in the page.
## event: WebSocket.close
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-02-25 22:22:47 -08:00
- argument: < [WebSocket]>
2021-01-07 11:46:05 -08:00
Fired when the websocket closes.
2021-02-04 19:34:09 +01:00
## event: WebSocket.frameReceived
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-25 22:22:47 -08:00
- argument: < [Object]>
2021-01-07 11:46:05 -08:00
- `payload` < [string]|[Buffer]> frame payload
2021-03-26 18:47:16 +01:00
Fired when the websocket receives a frame.
2021-01-07 11:46:05 -08:00
2021-02-09 12:11:48 -08:00
## event: WebSocket.frameReceived
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-09 12:11:48 -08:00
* langs: csharp, java
2021-02-25 22:22:47 -08:00
- argument: < [WebSocketFrame]>
2021-02-09 12:11:48 -08:00
2021-02-04 19:34:09 +01:00
## event: WebSocket.frameSent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-25 22:22:47 -08:00
- argument: < [Object]>
2021-01-07 11:46:05 -08:00
- `payload` < [string]|[Buffer]> frame payload
Fired when the websocket sends a frame.
2021-02-09 12:11:48 -08:00
## event: WebSocket.frameSent
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-09 12:11:48 -08:00
* langs: csharp, java
2021-02-25 22:22:47 -08:00
- argument: < [WebSocketFrame]>
2021-02-09 12:11:48 -08:00
2021-02-04 19:34:09 +01:00
## event: WebSocket.socketError
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-25 22:22:47 -08:00
- argument: < [String]>
2021-01-07 11:46:05 -08:00
Fired when the websocket has an error.
## method: WebSocket.isClosed
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- returns: < [boolean]>
Indicates that the web socket has been closed.
## method: WebSocket.url
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- returns: < [string]>
Contains the URL of the WebSocket.
## async method: WebSocket.waitForEvent
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-05-19 15:49:44 -07:00
* langs: js, python
2021-01-15 16:01:41 -08:00
- alias-python: expect_event
2021-01-07 11:46:05 -08:00
- returns: < [any]>
Waits for event to fire and passes its value into the predicate function. Returns when the predicate returns truthy
2021-01-15 16:01:41 -08:00
value. Will throw an error if the webSocket is closed before the event is fired. Returns the event data value.
2021-01-07 11:46:05 -08:00
2023-02-09 18:24:32 -08:00
## async method: WebSocket.waitForEvent
* since: v1.8
* langs: python
- returns: < [EventContextManager]>
2021-01-07 11:46:05 -08:00
### param: WebSocket.waitForEvent.event
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-07 11:46:05 -08:00
- `event` < [string]>
Event name, same one would pass into `webSocket.on(event)` .
### param: WebSocket.waitForEvent.optionsOrPredicate
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-01-08 15:00:14 -08:00
* langs: js
2022-04-06 19:02:10 -07:00
- `optionsOrPredicate` ?< [function]|[Object]>
2021-01-12 12:14:27 -08:00
- `predicate` < [function]> receives the event data and resolves to truthy value when the waiting should resolve.
2022-04-06 19:02:10 -07:00
- `timeout` ?< [float]> maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the [`method: BrowserContext.setDefaultTimeout` ].
2021-01-07 11:46:05 -08:00
Either a predicate that receives an event or an options object. Optional.
2021-02-04 21:15:14 -08:00
2023-02-09 18:24:32 -08:00
### option: WebSocket.waitForEvent.predicate = %%-wait-for-event-predicate-%%
* since: v1.8
### option: WebSocket.waitForEvent.timeout = %%-wait-for-event-timeout-%%
* since: v1.8
2021-03-08 18:33:23 +01:00
## async method: WebSocket.waitForFrameReceived
2022-07-05 16:24:50 -08:00
* since: v1.10
2021-05-19 15:49:44 -07:00
* langs: java
2021-02-04 21:15:14 -08:00
- returns: < [WebSocketFrame]>
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.
### option: WebSocket.waitForFrameReceived.predicate
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-12 09:19:41 -08:00
- `predicate` < [function]\([WebSocketFrame]\):[boolean]>
2021-02-04 21:15:14 -08:00
Receives the [WebSocketFrame] object and resolves to truthy value when the waiting should resolve.
### option: WebSocket.waitForFrameReceived.timeout = %%-wait-for-event-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-04 21:15:14 -08:00
2023-02-16 11:48:38 -08:00
### param: WebSocket.waitForFrameReceived.callback = %%-java-wait-for-event-callback-%%
* since: v1.9
2021-03-08 18:33:23 +01:00
## async method: WebSocket.waitForFrameSent
2022-07-05 16:24:50 -08:00
* since: v1.10
2021-05-19 15:49:44 -07:00
* langs: java
2021-02-04 21:15:14 -08:00
- returns: < [WebSocketFrame]>
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.
### option: WebSocket.waitForFrameSent.predicate
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-02-12 09:19:41 -08:00
- `predicate` < [function]\([WebSocketFrame]\):[boolean]>
2021-02-04 21:15:14 -08:00
Receives the [WebSocketFrame] object and resolves to truthy value when the waiting should resolve.
### option: WebSocket.waitForFrameSent.timeout = %%-wait-for-event-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.9
2021-05-19 15:49:44 -07:00
2023-02-16 11:48:38 -08:00
### param: WebSocket.waitForFrameSent.callback = %%-java-wait-for-event-callback-%%
* since: v1.9
2021-05-19 15:49:44 -07:00
## async method: WebSocket.waitForEvent2
2022-07-05 16:24:50 -08:00
* since: v1.8
2021-05-19 15:49:44 -07:00
* langs: python
- alias-python: wait_for_event
- returns: < [any]>
:::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.
### param: WebSocket.waitForEvent2.event = %%-wait-for-event-event-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2022-11-21 09:30:32 -08:00
2021-05-19 15:49:44 -07:00
### option: WebSocket.waitForEvent2.predicate = %%-wait-for-event-predicate-%%
2022-07-05 16:24:50 -08:00
* since: v1.8
2022-11-21 09:30:32 -08:00
2021-05-19 15:49:44 -07:00
### option: WebSocket.waitForEvent2.timeout = %%-wait-for-event-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.8