INNER CODE UNIT · Rust
send
keon/browser-control · src/cdp.rs:76
pub async fn send(
&mut self,
method: &str,
params: Value,
session: Option<String>,
) -> Result<Value> {
self.id += 1;
let mut req = json!({"id":self.id,"method":method,"params":params});
if let Some(s) = session {
req["sessionId"] = json!(s)
}
self.ws.send(Message::Text(req.to_string().into())).await?;
loop {
let msg = tokio::time::timeout(cdp_timeout(), self.ws.next())
.await
.with_context(|| format!("cdp timeout waiting for {method}"))?
.context("cdp websocket closed")??;
let Message::Text(txt) = msg else { continue };