pub struct Connection { /* private fields */ }Expand description
One CDP connection.
Implementations§
Source§impl Connection
impl Connection
Sourcepub async fn connect_endpoint(
endpoint: &Endpoint,
token: Option<&str>,
profile: Option<&str>,
) -> Result<Self, Error>
pub async fn connect_endpoint( endpoint: &Endpoint, token: Option<&str>, profile: Option<&str>, ) -> Result<Self, Error>
Open a CDP connection from a parsed endpoint. profile, when set, is
sent as ?profile= so the host switches its active profile.
Sourcepub async fn connect(
endpoint_ws_url: &str,
token: Option<&str>,
) -> Result<Self, Error>
pub async fn connect( endpoint_ws_url: &str, token: Option<&str>, ) -> Result<Self, Error>
Open a CDP connection to ws://endpoint/cdp (or wss://),
attaching the optional bearer token via the ?token_secret= query
parameter (the _secret suffix lets AFDATA redaction scrub it).
Sourcepub fn subscribe(&self) -> Receiver<CdpEvent>
pub fn subscribe(&self) -> Receiver<CdpEvent>
Subscribe to events for the lifetime of this connection.
Sourcepub async fn send<P: Serialize>(
&self,
method: &str,
params: &P,
session_id: Option<&str>,
) -> Result<Value, Error>
pub async fn send<P: Serialize>( &self, method: &str, params: &P, session_id: Option<&str>, ) -> Result<Value, Error>
Send a CDP command and await the result. session_id is Some when
the call is scoped to a flattened session (after Target.attachToTarget).
Sourcepub async fn send_timeout<P: Serialize>(
&self,
method: &str,
params: &P,
session_id: Option<&str>,
timeout: Duration,
) -> Result<Value, Error>
pub async fn send_timeout<P: Serialize>( &self, method: &str, params: &P, session_id: Option<&str>, timeout: Duration, ) -> Result<Value, Error>
Send a CDP command and fail with cdp_timeout if the browser does not
answer within timeout. Unlike wrapping Self::send externally, this
removes the pending reply slot on timeout.
Sourcepub async fn wait_event<F>(
&self,
timeout: Duration,
predicate: F,
) -> Result<CdpEvent, Error>
pub async fn wait_event<F>( &self, timeout: Duration, predicate: F, ) -> Result<CdpEvent, Error>
Wait for a CDP event matching predicate (true = matches).
Returns cdp_timeout if timeout elapses first.