pub struct CdpConnection { /* private fields */ }Expand description
A CDP connection to a browser.
Implementations§
Source§impl CdpConnection
impl CdpConnection
Sourcepub async fn connect_with_options(
ws_url: &str,
options: &CdpConnectionOptions,
) -> Result<Self, CdpError>
pub async fn connect_with_options( ws_url: &str, options: &CdpConnectionOptions, ) -> Result<Self, CdpError>
Connect to a CDP WebSocket endpoint with custom options.
§Errors
Returns an error if the WebSocket connection fails.
Sourcepub async fn connect_via_http(endpoint_url: &str) -> Result<Self, CdpError>
pub async fn connect_via_http(endpoint_url: &str) -> Result<Self, CdpError>
Connect to a browser via HTTP endpoint URL.
This method discovers the WebSocket URL from an HTTP endpoint like
http://localhost:9222 by fetching /json/version.
§Example
use viewpoint_cdp::{CdpConnection, connection::CdpConnectionOptions};
use std::time::Duration;
// Simple connection
let conn = CdpConnection::connect_via_http("http://localhost:9222").await?;
// With custom options
let options = CdpConnectionOptions::new()
.timeout(Duration::from_secs(10))
.header("Authorization", "Bearer token");
let conn = CdpConnection::connect_via_http_with_options(
"http://localhost:9222",
options,
).await?;§Errors
Returns an error if:
- The HTTP endpoint is unreachable
- The endpoint doesn’t expose CDP
- The WebSocket connection fails
Sourcepub async fn connect_via_http_with_options(
endpoint_url: &str,
options: CdpConnectionOptions,
) -> Result<Self, CdpError>
pub async fn connect_via_http_with_options( endpoint_url: &str, options: CdpConnectionOptions, ) -> Result<Self, CdpError>
Connect to a browser via HTTP endpoint URL with custom options.
§Errors
Returns an error if discovery or connection fails.
Sourcepub async fn send_command<P, R>(
&self,
method: &str,
params: Option<P>,
session_id: Option<&str>,
) -> Result<R, CdpError>where
P: Serialize,
R: DeserializeOwned,
pub async fn send_command<P, R>(
&self,
method: &str,
params: Option<P>,
session_id: Option<&str>,
) -> Result<R, CdpError>where
P: Serialize,
R: DeserializeOwned,
Send a CDP command and wait for the response.
§Errors
Returns an error if:
- The command cannot be sent
- The response times out
- The browser returns a protocol error
Sourcepub async fn send_command_with_timeout<P, R>(
&self,
method: &str,
params: Option<P>,
session_id: Option<&str>,
timeout_duration: Duration,
) -> Result<R, CdpError>where
P: Serialize,
R: DeserializeOwned,
pub async fn send_command_with_timeout<P, R>(
&self,
method: &str,
params: Option<P>,
session_id: Option<&str>,
timeout_duration: Duration,
) -> Result<R, CdpError>where
P: Serialize,
R: DeserializeOwned,
Send a CDP command with a custom timeout.
§Errors
Returns an error if:
- The command cannot be sent
- The response times out
- The browser returns a protocol error
Sourcepub fn subscribe_events(&self) -> Receiver<CdpEvent>
pub fn subscribe_events(&self) -> Receiver<CdpEvent>
Subscribe to CDP events.
Returns a receiver that will receive all CDP events from the browser.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for CdpConnection
impl !RefUnwindSafe for CdpConnection
impl Send for CdpConnection
impl Sync for CdpConnection
impl Unpin for CdpConnection
impl !UnwindSafe for CdpConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more