BigPizzaV3/CodexPlusPlus · error · anyhow::Error

failed to query CDP targets on loopback addresses

Error message

failed to query CDP targets on loopback addresses: {}

What it means

Thrown by `list_targets` after it has tried querying the CDP `/json` target list on every loopback address candidate (IPv4 and IPv6) and all attempts failed. It aggregates each URL's underlying error into a single message so the caller can see why every loopback candidate was rejected.

Solutions

  1. Confirm the browser runs with `--remote-debugging-port=<port>` and that the port matches the one passed to `list_targets`
  2. Read the per-URL errors embedded in the message — connection-refused vs HTTP errors point to different causes (browser down vs wrong protocol)
  3. Check `curl http://127.0.0.1:<port>/json/list` manually to see what the endpoint returns
  4. Retry after a short delay if the browser was just launched

Example fix

// before
let targets = cdp::list_targets(9222).await?; // browser not launched yet
// after
let child = launch_chrome(["--remote-debugging-port=9222"])?;
wait_for_endpoint_available(9222, Duration::from_secs(10)).await?;
let targets = cdp::list_targets(9222).await?;
Defensive patterns

Strategy: retry

Validate before calling

async fn cdp_ready(port: u16) -> bool {
    reqwest::get(format!("http://127.0.0.1:{port}/json/version")).await
        .map(|r| r.status().is_success()).unwrap_or(false)
}

Try / catch

match cdp::list_targets(port).await {
    Ok(t) => t,
    Err(e) if e.to_string().contains("connection refused") => retry_with_backoff(3, || cdp::list_targets(port)).await?,
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling `list_targets(debug_port)` when no browser is listening on the port, the browser only binds an address not in the candidate list, HTTP requests fail or return non-list payloads, or the port is occupied by a non-CDP service.

Common situations: Chromium not started with `--remote-debugging-port`, wrong debug_port passed, browser still starting up, firewall/proxy interference, or a service other than Chrome listening on the port.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/480ec31773aefae9. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/cdp.rs:139

    let client = reqwest::Client::builder()
        .no_proxy()
        .timeout(CDP_HTTP_TIMEOUT)
        .build()
        .context("failed to build CDP HTTP client")?;

    let urls = [
        format!("http://127.0.0.1:{debug_port}/json"),
        format!("http://[::1]:{debug_port}/json"),
    ];
    let mut errors = Vec::new();
    for url in urls {
        match query_targets_url(&client, &url, debug_port).await {
            Ok(targets) => return Ok(targets),
            Err(error) => errors.push(format!("{url}: {error:#}")),
        }
    }

    bail!(
        "failed to query CDP targets on loopback addresses: {}",
        errors.join("; ")
    )
}

pub async fn browser_identity(debug_port: u16) -> anyhow::Result<CdpBrowserIdentity> {
    let client = reqwest::Client::builder()
        .no_proxy()
        .timeout(CDP_HTTP_TIMEOUT)
        .build()
        .context("failed to build CDP HTTP client")?;
    let urls = [
        format!("http://127.0.0.1:{debug_port}/json/version"),
        format!("http://[::1]:{debug_port}/json/version"),
    ];
    let mut errors = Vec::new();
    for url in urls {
        let result = async {

View on GitHub (pinned to b1ed92e5e4)