{"record":{"id":"55ceaa939c61c8d7","repo":"BigPizzaV3/CodexPlusPlus","slug":"no-injectable-page-target-found","errorCode":null,"errorMessage":"No injectable page target found","messagePattern":"No injectable page target found","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/cdp.rs","lineNumber":252,"sourceCode":"}\n\npub fn pick_page_target(targets: &[CdpTarget]) -> anyhow::Result<CdpTarget> {\n    let mut first_page = None;\n    for target in targets\n        .iter()\n        .filter(|target| is_injectable_page_target(target))\n    {\n        first_page.get_or_insert(target);\n        if is_primary_codex_page_target(target) {\n            return Ok(target.clone());\n        }\n    }\n\n    if let Some(target) = first_page {\n        return Ok(target.clone());\n    }\n\n    bail!(\"No injectable page target found\")\n}\n\npub fn pick_injectable_codex_page_target(targets: &[CdpTarget]) -> anyhow::Result<CdpTarget> {\n    let priorities: [fn(&CdpTarget) -> bool; 4] = [\n        is_exact_codex_app_main_target,\n        is_primary_codex_app_target,\n        is_chatgpt_desktop_page_target,\n        is_supported_codex_page_target,\n    ];\n    for matches_priority in priorities {\n        if let Some(target) = targets\n            .iter()\n            .find(|target| is_injectable_page_target(target) && matches_priority(target))\n        {\n            return Ok(target.clone());\n        }\n    }\n    bail!(\"No injectable Codex page target found\")","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/cdp.rs#L234-L270","documentation":"Thrown by `pick_page_target` when, after preferring a Codex-matching page target, no injectable page-type CDP target with a webSocketDebuggerUrl exists in the target list. Only `type == \"page\"` targets with a non-empty webSocketDebuggerUrl are injectable.","triggerScenarios":"Calling `pick_page_target` with an empty target slice, a list containing only non-page targets (browser, service_worker, iframe, background_page), or page targets whose webSocketDebuggerUrl is empty/missing.","commonSituations":"Browser has no tabs open (all windows closed leaving only the browser process), querying during early startup before any page exists, or the browser launched with page targets disabled.","solutions":["Open a tab/window in the target browser before calling, or navigate an existing one to a real page","Re-fetch targets via `list_targets` — a previously empty list may now include pages","Check the targets you pass: filter for `type == \"page\"` with a non-empty `webSocketDebuggerUrl` to debug why nothing qualifies","If the browser is headless/minimized with zero pages, launch with an initial about:blank page"],"exampleFix":"// before\nlet targets = cdp::list_targets(9222).await?; // browser freshly started, no pages\nlet target = cdp::pick_page_target(&targets)?;\n// after\nlet targets = cdp::list_targets(9222).await?;\nif targets.iter().all(|t| t.target_type != \"page\") {\n    open_new_tab(9222).await?; // e.g. PUT /json/new\n}\nlet targets = cdp::list_targets(9222).await?;\nlet target = cdp::pick_page_target(&targets)?;","handlingStrategy":"fallback","validationCode":"fn has_injectable_page(targets: &[CdpTarget]) -> bool {\n    targets.iter().any(|t| t.target_type == \"page\" && !t.web_socket_debugger_url.is_empty())\n}","typeGuard":null,"tryCatchPattern":"let target = cdp::pick_page_target(&targets)\n    .or_else(|_| { open_new_tab(port)?; futures::executor::block_on(cdp::list_targets(port)) })\n    .and_then(|t| cdp::pick_page_target(&t))?;","preventionTips":["Ensure at least one tab is open before target selection","Refresh the target list after browser state changes","For headless runs, launch with an initial about:blank page"],"tags":["cdp","target-selection","empty"],"backgroundTag":"empty-result-set","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}