MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / send_raw

Method send_raw

src/cdp.rs:492–541  ·  view source on GitHub ↗
(
        &mut self,
        method: &str,
        params: Value,
        session_id: Option<&str>,
    )

Source from the content-addressed store, hash-verified

490 }
491
492 async fn send_raw(
493 &mut self,
494 method: &str,
495 params: Value,
496 session_id: Option<&str>,
497 ) -> Result<Value> {
498 let id = self.send_raw_no_wait(session_id, method, params).await?;
499
500 loop {
501 let resp_text = self.read_text().await?;
502 let resp: Value = serde_json::from_str(&resp_text)?;
503
504 // Proactively handle or fail if a dialog is opened during execution
505 if resp.get("method").and_then(|v| v.as_str()) == Some("Page.javascriptDialogOpening")
506 && method != "Page.handleJavaScriptDialog"
507 {
508 let dialog_type = resp
509 .get("params")
510 .and_then(|p| p.get("type"))
511 .and_then(|t| t.as_str())
512 .unwrap_or("unknown");
513 let msg = resp
514 .get("params")
515 .and_then(|p| p.get("message"))
516 .and_then(|m| m.as_str())
517 .unwrap_or("");
518
519 if let Some(action) = self.dialog_action.clone() {
520 self.handle_dialog_helper(session_id, action).await?;
521 continue;
522 } else {
523 bail!("A javascript dialog is open ({dialog_type}: {msg}). Use `evaluate` with --dialog-action to dismiss it.");
524 }
525 }
526
527 if resp.get("id").and_then(|v| v.as_u64()) == Some(id) {
528 if let Some(error) = resp.get("error") {
529 bail!(
530 "CDP error in {method}: {}",
531 serde_json::to_string_pretty(error)?
532 );
533 }
534 return Ok(resp.get("result").cloned().unwrap_or(Value::Null));
535 } else if resp.get("method").is_some() {
536 // Store events for later consumption
537 self.push_event(resp);
538 }
539 // Skip other unrelated responses
540 }
541 }
542
543 fn handle_dialog_helper<'a>(
544 &'a mut self,

Callers 2

sendMethod · 0.80
send_to_targetMethod · 0.80

Calls 4

send_raw_no_waitMethod · 0.80
read_textMethod · 0.80
handle_dialog_helperMethod · 0.80
push_eventMethod · 0.80

Tested by

no test coverage detected