pub struct WebSocketRoute { /* private fields */ }Expand description
Represents an intercepted WebSocket connection.
WebSocketRoute is passed to handlers registered via
crate::protocol::Page::route_web_socket or crate::protocol::BrowserContext::route_web_socket.
The handler must call connect_to_server
to forward the connection to the real server, or close
to terminate it.
Implementations§
Source§impl WebSocketRoute
impl WebSocketRoute
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 WebSocketRoute object.
Sourcepub fn url(&self) -> &str
pub fn url(&self) -> &str
Returns the URL of the intercepted WebSocket connection.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-url
Sourcepub async fn connect_to_server(&self) -> Result<()>
pub async fn connect_to_server(&self) -> Result<()>
Connects this WebSocket to the actual server.
After calling this method, all messages sent by the page are forwarded to the server, and all messages sent by the server are forwarded to the page.
§Errors
Returns an error if the RPC call fails.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-connect-to-server
Sourcepub async fn close(
&self,
options: Option<WebSocketRouteCloseOptions>,
) -> Result<()>
pub async fn close( &self, options: Option<WebSocketRouteCloseOptions>, ) -> Result<()>
Closes the WebSocket connection.
§Arguments
options— Optional close code and reason.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-close
Sourcepub async fn send(&self, message: &str) -> Result<()>
pub async fn send(&self, message: &str) -> Result<()>
Sends a text message to the page.
§Arguments
message— The text message to send.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-send
Sourcepub async fn on_message<F>(&self, handler: F) -> Result<()>
pub async fn on_message<F>(&self, handler: F) -> Result<()>
Registers a handler for messages sent from the page.
§Arguments
handler— Async closure that receives the message payload as aString.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-on-message
Sourcepub async fn on_close<F>(&self, handler: F) -> Result<()>
pub async fn on_close<F>(&self, handler: F) -> Result<()>
Registers a handler for when the WebSocket is closed by the page.
See: https://playwright.dev/docs/api/class-websocketroute#web-socket-route-on-close
Trait Implementations§
Source§impl Clone for WebSocketRoute
impl Clone for WebSocketRoute
Source§fn clone(&self) -> WebSocketRoute
fn clone(&self) -> WebSocketRoute
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more