WebSocket
The WebSocket class represents websocket connections in the page.
- web_socket.on("close")
- web_socket.on("framereceived")
- web_socket.on("framesent")
- web_socket.on("socketerror")
- web_socket.expect_event(event, **kwargs)
- web_socket.is_closed()
- web_socket.url
- web_socket.wait_for_event(event, **kwargs)
#
web_socket.on("close")- type: <WebSocket>
Fired when the websocket closes.
#
web_socket.on("framereceived")Fired when the websocket recieves a frame.
#
web_socket.on("framesent")Fired when the websocket sends a frame.
#
web_socket.on("socketerror")- type: <[String]>
Fired when the websocket has an error.
#
web_socket.expect_event(event, **kwargs)event
<str> Event name, same one would pass intowebSocket.on(event)
.predicate
<Callable> Receives the event data and resolves to truthy value when the waiting should resolve.timeout
<float> Maximum time to wait for in milliseconds. Defaults to30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the browser_context.set_default_timeout(timeout).- returns: <EventContextManager>
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.
#
web_socket.is_closed()- returns: <bool>
Indicates that the web socket has been closed.
#
web_socket.url- returns: <str>
Contains the URL of the WebSocket.
#
web_socket.wait_for_event(event, **kwargs)event
<str> Event name, same one typically passed into*.on(event)
.predicate
<Callable> Receives the event data and resolves to truthy value when the waiting should resolve.timeout
<float> Maximum time to wait for in milliseconds. Defaults to30000
(30 seconds). Pass0
to disable timeout. The default value can be changed by using the browser_context.set_default_timeout(timeout).- returns: <Any>
note
In most cases, you should use web_socket.expect_event(event, **kwargs).
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.