pub struct WebSocket { /* private fields */ }Expand description
Represents a WebSocket connection initiated by a page.
WebSocket objects are created by the Playwright server when the page
opens a WebSocket connection. Use crate::protocol::Page::on_websocket to receive
WebSocket objects.
Implementations§
Source§impl WebSocket
impl WebSocket
Sourcepub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new WebSocket object.
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the URL of the WebSocket connection.
See: https://playwright.dev/docs/api/class-websocket#web-socket-url
Sourcepub fn is_closed(&self) -> bool
pub fn is_closed(&self) -> bool
Returns true if the WebSocket is closed.
The value becomes true when the "close" event fires (i.e. when the
underlying TCP connection is torn down). It remains false from
construction until that point.
See: https://playwright.dev/docs/api/class-websocket#web-socket-is-closed
Sourcepub async fn on_frame_sent<F>(&self, handler: F) -> Result<()>
pub async fn on_frame_sent<F>(&self, handler: F) -> Result<()>
Registers a handler that fires when a frame is sent from the page to the server.
The handler receives the frame payload as a String. For binary frames the
value is the base-64-encoded representation.
§Errors
Returns an error only if the handler cannot be registered (in practice this never fails).
See: https://playwright.dev/docs/api/class-websocket#web-socket-event-frame-sent
Sourcepub async fn on_frame_received<F>(&self, handler: F) -> Result<()>
pub async fn on_frame_received<F>(&self, handler: F) -> Result<()>
Registers a handler that fires when a frame is received from the server.
The handler receives the frame payload as a String. For binary frames the
value is the base-64-encoded representation.
§Errors
Returns an error only if the handler cannot be registered (in practice this never fails).
See: https://playwright.dev/docs/api/class-websocket#web-socket-event-frame-received
Sourcepub async fn on_error<F>(&self, handler: F) -> Result<()>
pub async fn on_error<F>(&self, handler: F) -> Result<()>
Registers a handler that fires when the WebSocket encounters an error.
The handler receives the error message as a String.
See: https://playwright.dev/docs/api/class-websocket#web-socket-event-socket-error
Sourcepub async fn on_close<F>(&self, handler: F) -> Result<()>
pub async fn on_close<F>(&self, handler: F) -> Result<()>
Registers a handler that fires when the WebSocket is closed.
See: https://playwright.dev/docs/api/class-websocket#web-socket-event-close
Sourcepub async fn expect_close(
&self,
timeout: Option<f64>,
) -> Result<EventWaiter<()>>
pub async fn expect_close( &self, timeout: Option<f64>, ) -> Result<EventWaiter<()>>
Creates a one-shot waiter that resolves when the WebSocket is closed.
The waiter must be created before the action that closes the WebSocket to avoid a race condition.
§Arguments
timeout— Timeout in milliseconds. Defaults to 30 000 ms ifNone.
§Errors
Returns Error::Timeout if the WebSocket
is not closed within the timeout.
See: https://playwright.dev/docs/api/class-websocket#web-socket-wait-for-event
Sourcepub async fn expect_frame_received(
&self,
timeout: Option<f64>,
) -> Result<EventWaiter<String>>
pub async fn expect_frame_received( &self, timeout: Option<f64>, ) -> Result<EventWaiter<String>>
Creates a one-shot waiter that resolves when the next frame is received from the server.
The waiter must be created before the action that causes a frame to be received to avoid a race condition.
§Arguments
timeout— Timeout in milliseconds. Defaults to 30 000 ms ifNone.
§Errors
Returns Error::Timeout if no frame is
received within the timeout.
See: https://playwright.dev/docs/api/class-websocket#web-socket-wait-for-event
Sourcepub async fn expect_frame_sent(
&self,
timeout: Option<f64>,
) -> Result<EventWaiter<String>>
pub async fn expect_frame_sent( &self, timeout: Option<f64>, ) -> Result<EventWaiter<String>>
Creates a one-shot waiter that resolves when the next frame is sent from the page.
The waiter must be created before the action that sends the frame to avoid a race condition.
§Arguments
timeout— Timeout in milliseconds. Defaults to 30 000 ms ifNone.
§Errors
Returns Error::Timeout if no frame is
sent within the timeout.
See: https://playwright.dev/docs/api/class-websocket#web-socket-wait-for-event