RightNow-AI/openfang · error · BrowserResponse
Type failed: {e}
Error message
Type failed: {e} What it means
The CDP-transport-level type failure: the run_js call in cmd_type returned Err, so the typing script never ran — the problem is the CDP connection/session, not the selector. The underlying CDP error is interpolated into the message.
Source
Thrown at crates/openfang-runtime/src/browser.rs:512
el.dispatchEvent(new Event('input', {{bubbles: true}}));
el.dispatchEvent(new Event('change', {{bubbles: true}}));
return JSON.stringify({{success: true, selector: sel, typed: txt.length + ' chars'}});
}})()"#
);
match self.cdp.run_js(&js).await {
Ok(val) => {
let parsed: serde_json::Value = val
.as_str()
.and_then(|s| serde_json::from_str(s).ok())
.unwrap_or(val);
if parsed["success"].as_bool() == Some(false) {
BrowserResponse::err(parsed["error"].as_str().unwrap_or("Type failed"))
} else {
BrowserResponse::ok(parsed)
}
}
Err(e) => BrowserResponse::err(format!("Type failed: {e}")),
}
}
async fn cmd_screenshot(&self) -> BrowserResponse {
match self
.cdp
.send(
"Page.captureScreenshot",
serde_json::json!({ "format": "png" }),
)
.await
{
Ok(result) => {
let b64 = result["data"].as_str().unwrap_or("");
let url = self
.cdp
.run_js("location.href")
.awaitView on GitHub (pinned to acf2587e46)
Solutions
- Read the interpolated {e} for the root cause (disconnected / context destroyed / timeout).
- Reconnect or restart the browser session, then retry the type command.
- Ensure no navigation runs concurrently with typing; sequence commands or wait for load first.
- Add retry-with-backoff around type for transient CDP failures.
Example fix
// before
let resp = browser.execute("type", &format!("{selector}|{text}")).await?;
// after
let resp = match browser.execute("type", &format!("{selector}|{text}")).await {
Ok(r) if r.success => r,
Ok(r) => return Err(anyhow!(r.error)),
Err(e) => {
browser.reconnect().await?;
browser.execute("type", &format!("{selector}|{text}")).await?
}
}; Defensive patterns
Strategy: retry
Validate before calling
// Check session liveness before typing:
if !browser.is_connected().await { browser.reconnect().await?; } Type guard
fn is_cdp_transport_err(e: &anyhow::Error) -> bool {
let s = e.to_string();
s.contains("connection") || s.contains("closed") || s.contains("context")
} Try / catch
// Rust
match browser.execute("type", &format!("{selector}|{text}")).await {
Ok(r) if r.success => Ok(r),
Ok(r) => Err(anyhow!(r.error)),
Err(e) if is_cdp_transport_err(&e) => {
browser.reconnect().await?;
browser.execute("type", &format!("{selector}|{text}")).await.map_err(Into::into)
}
Err(e) => Err(e.into()),
} Prevention
- Do not type while a navigation is in flight; await wait_for_load first.
- Supervise and auto-reconnect the browser session.
- Retry transient CDP evaluation failures with backoff.
- Log the inner error to separate transport failures from selector failures.
When it happens
Trigger: self.cdp.run_js(type_script) resolves to Err: browser disconnected, execution context destroyed (e.g. by a concurrent navigation), or CDP evaluation failed/timed out.
Common situations: Page redirected while typing script was being sent; headless browser crashed; CDP websocket dropped between commands.
Related errors
- Click failed: {e}
- Navigate failed: {e}
- Navigate succeeded but page info failed: {e}
- Screenshot failed: {e}
- ReadPage failed: {e}
AI-assisted analysis of RightNow-AI/openfang@acf2587e46 (2026-09-02).
Data as JSON: /api/errors/bd39aa0bb2aea95f.
Report an issue: GitHub.