playwright/docs/src/api/class-websocket.md

56 lines
1.6 KiB
Markdown
Raw Normal View History

# class: WebSocket
The [WebSocket] class represents websocket connections in the page.
## event: WebSocket.close
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
- returns: <[any]>
Returns the event data value.
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.
### 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.
- `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.