2021-01-07 11:46:05 -08:00
# class: WebSocket
The [WebSocket] class represents websocket connections in the page.
## event: WebSocket.close
2021-01-22 09:58:31 -08:00
- type: < [WebSocket]>
2021-01-07 11:46:05 -08:00
Fired when the websocket closes.
## event: WebSocket.framereceived
- type: < [Object]>
- `payload` < [string]|[Buffer]> frame payload
Fired when the websocket recieves a frame.
## event: WebSocket.framesent
- type: < [Object]>
- `payload` < [string]|[Buffer]> frame payload
Fired when the websocket sends a frame.
## event: WebSocket.socketerror
- type: < [String]>
Fired when the websocket has an error.
## method: WebSocket.isClosed
- returns: < [boolean]>
Indicates that the web socket has been closed.
## method: WebSocket.url
- returns: < [string]>
Contains the URL of the WebSocket.
## async method: WebSocket.waitForEvent
2021-01-30 22:15:56 -08:00
* langs:
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
### param: WebSocket.waitForEvent.event
- `event` < [string]>
Event name, same one would pass into `webSocket.on(event)` .
### param: WebSocket.waitForEvent.optionsOrPredicate
2021-01-08 15:00:14 -08:00
* langs: js
2021-01-12 12:14:27 -08:00
- `optionsOrPredicate` < [function]|[Object]>
- `predicate` < [function]> receives the event data and resolves to truthy value when the waiting should resolve.
2021-01-07 11:46:05 -08: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` ].
Either a predicate that receives an event or an options object. Optional.