BigPizzaV3/CodexPlusPlus · error · anyhow::Error
failed to query CDP browser identity on loopback addresses
Error message
failed to query CDP browser identity on loopback addresses: {} What it means
Thrown by `browser_identity` when fetching the CDP browser identity (via `/json/version` plus WebSocket validation) fails on every loopback address candidate. Like `list_targets`, it joins all per-URL errors so the root cause of each failed attempt is visible.
Solutions
- Verify the browser is up and `curl http://127.0.0.1:<port>/json/version` returns valid JSON with a webSocketDebuggerUrl on 127.0.0.1/<port>
- Check the per-URL errors in the message to distinguish connectivity failures from URL validation failures
- Ensure the browser was started with `--remote-debugging-port=<same port>` (port mismatch triggers the URL validator)
- Retry with backoff if the browser was just started
Example fix
// before let identity = cdp::browser_identity(9223).await?; // chrome on 9222 // after let identity = cdp::browser_identity(9222).await?;
Defensive patterns
Strategy: retry
Validate before calling
async fn identity_ready(port: u16) -> bool {
let Ok(body) = reqwest::get(format!("http://127.0.0.1:{port}/json/version")).await else { return false };
let Ok(json): Result<serde_json::Value, _> = body.json().await else { return false };
json["webSocketDebuggerUrl"].as_str().map_or(false, |u| u.starts_with("ws://127.0.0.1"))
} Try / catch
match cdp::browser_identity(port).await {
Ok(id) => id,
Err(e) if is_startup_race(&e) => {
tokio::time::sleep(Duration::from_millis(500)).await;
cdp::browser_identity(port).await?
}
Err(e) => return Err(e),
} Prevention
- Ensure /json/version returns a ws://127.0.0.1:<port> URL
- Confirm no proxy rewrites loopback URLs to hostnames
- Start the browser on the exact configured port
When it happens
Trigger: Calling `browser_identity(debug_port)` when the debug port is unreachable, `/json/version` returns an unexpected body, the returned webSocketDebuggerUrl fails `validate_cdp_websocket_url` (non-ws scheme, non-loopback host, or mismatched port) on all candidates.
Common situations: Browser not running or still initializing, remote debugging exposed on a non-loopback interface only, a mismatch between the configured debug port and the port the browser actually uses, or a proxy mangling the JSON.
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
- failed to query CDP targets on loopback addresses
- CDP WebSocket host must be loopback
- ad list unavailable
- API 请求超时( 秒),本批未提交
- 创建失败
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/5f503bf5de0e86e4.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/cdp.rs:178
.send()
.await
.context("failed to query CDP browser identity")?
.error_for_status()
.context("CDP browser identity query failed")?
.json::<CdpBrowserIdentity>()
.await
.context("failed to deserialize CDP browser identity")?;
validate_cdp_websocket_url(&identity.web_socket_debugger_url, debug_port)?;
identity.browser_id()?;
anyhow::Ok(identity)
}
.await;
match result {
Ok(identity) => return Ok(identity),
Err(error) => errors.push(format!("{url}: {error:#}")),
}
}
bail!(
"failed to query CDP browser identity on loopback addresses: {}",
errors.join("; ")
)
}
async fn query_targets_url(
client: &reqwest::Client,
url: &str,
debug_port: u16,
) -> anyhow::Result<Vec<CdpTarget>> {
let response = client
.get(url)
.send()
.await
.context("failed to query CDP targets")?
.error_for_status()
.context("CDP target query failed")?;
View on GitHub (pinned to b1ed92e5e4)