{"record":{"id":"bd39aa0bb2aea95f","repo":"RightNow-AI/openfang","slug":"type-failed-e","errorCode":null,"errorMessage":"Type failed: {e}","messagePattern":"Type failed: (.+?)","errorType":"error_code","errorClass":"BrowserResponse","httpStatus":null,"severity":"error","filePath":"crates/openfang-runtime/src/browser.rs","lineNumber":512,"sourceCode":"    el.dispatchEvent(new Event('input', {{bubbles: true}}));\n    el.dispatchEvent(new Event('change', {{bubbles: true}}));\n    return JSON.stringify({{success: true, selector: sel, typed: txt.length + ' chars'}});\n}})()\"#\n        );\n\n        match self.cdp.run_js(&js).await {\n            Ok(val) => {\n                let parsed: serde_json::Value = val\n                    .as_str()\n                    .and_then(|s| serde_json::from_str(s).ok())\n                    .unwrap_or(val);\n                if parsed[\"success\"].as_bool() == Some(false) {\n                    BrowserResponse::err(parsed[\"error\"].as_str().unwrap_or(\"Type failed\"))\n                } else {\n                    BrowserResponse::ok(parsed)\n                }\n            }\n            Err(e) => BrowserResponse::err(format!(\"Type failed: {e}\")),\n        }\n    }\n\n    async fn cmd_screenshot(&self) -> BrowserResponse {\n        match self\n            .cdp\n            .send(\n                \"Page.captureScreenshot\",\n                serde_json::json!({ \"format\": \"png\" }),\n            )\n            .await\n        {\n            Ok(result) => {\n                let b64 = result[\"data\"].as_str().unwrap_or(\"\");\n                let url = self\n                    .cdp\n                    .run_js(\"location.href\")\n                    .await","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/RightNow-AI/openfang/blob/acf2587e46be174c10200489c9a2d23a39a98aeb/crates/openfang-runtime/src/browser.rs#L494-L530","documentation":"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.","triggerScenarios":"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.","commonSituations":"Page redirected while typing script was being sent; headless browser crashed; CDP websocket dropped between commands.","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."],"exampleFix":"// before\nlet resp = browser.execute(\"type\", &format!(\"{selector}|{text}\")).await?;\n// after\nlet resp = match browser.execute(\"type\", &format!(\"{selector}|{text}\")).await {\n    Ok(r) if r.success => r,\n    Ok(r) => return Err(anyhow!(r.error)),\n    Err(e) => {\n        browser.reconnect().await?;\n        browser.execute(\"type\", &format!(\"{selector}|{text}\")).await?\n    }\n};","handlingStrategy":"retry","validationCode":"// Check session liveness before typing:\nif !browser.is_connected().await { browser.reconnect().await?; }","typeGuard":"fn is_cdp_transport_err(e: &anyhow::Error) -> bool {\n    let s = e.to_string();\n    s.contains(\"connection\") || s.contains(\"closed\") || s.contains(\"context\")\n}","tryCatchPattern":"// Rust\nmatch browser.execute(\"type\", &format!(\"{selector}|{text}\")).await {\n    Ok(r) if r.success => Ok(r),\n    Ok(r) => Err(anyhow!(r.error)),\n    Err(e) if is_cdp_transport_err(&e) => {\n        browser.reconnect().await?;\n        browser.execute(\"type\", &format!(\"{selector}|{text}\")).await.map_err(Into::into)\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["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."],"tags":["cdp","typing","transport-error"],"backgroundTag":"cdp-command-failed","analyzedSha":"acf2587e46be174c10200489c9a2d23a39a98aeb","analyzedAt":"2026-09-02T22:42:28.464Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}