{"record":{"id":"033520b2d5e788f1","repo":"can1357/oh-my-pi","slug":"target-id-unavailable-from-cdp-target-info-033520","errorCode":null,"errorMessage":"Target id unavailable from CDP target info","messagePattern":"Target id unavailable from CDP target info","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/browser/tab-worker.ts","lineNumber":697,"sourceCode":"\tconst err = new Ctor(payload.message);\n\tif (payload.name) err.name = payload.name;\n\tif (payload.stack) err.stack = payload.stack;\n\treturn err;\n}\n\nfunction privateTargetId(target: Target): string | undefined {\n\tconst raw = target as unknown as { _targetId?: unknown };\n\treturn typeof raw._targetId === \"string\" ? raw._targetId : undefined;\n}\n\nasync function targetIdForTarget(target: Target): Promise<string> {\n\tconst fastTargetId = privateTargetId(target);\n\tif (fastTargetId) return fastTargetId;\n\tconst session = await target.createCDPSession();\n\ttry {\n\t\tconst info = (await session.send(\"Target.getTargetInfo\")) as { targetInfo?: { targetId?: string } };\n\t\tif (info.targetInfo?.targetId) return info.targetInfo.targetId;\n\t\tthrow new ToolError(\"Target id unavailable from CDP target info\");\n\t} finally {\n\t\tawait session.detach().catch(() => undefined);\n\t}\n}\n\nasync function targetIdForPage(page: Page): Promise<string> {\n\treturn await targetIdForTarget(page.target());\n}\n\nasync function createTrackedHeadlessPage(browser: Browser, reportTarget: (targetId: string) => void): Promise<Page> {\n\tconst session = await browser.target().createCDPSession();\n\tlet targetId: string;\n\ttry {\n\t\t({ targetId } = await session.send(\"Target.createTarget\", { url: \"about:blank\" }));\n\t\treportTarget(targetId);\n\t} finally {\n\t\tawait session.detach().catch(() => undefined);\n\t}","sourceCodeStart":679,"sourceCodeEnd":715,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/browser/tab-worker.ts#L679-L715","documentation":"Same failure family as the tab-supervisor variant: when resolving a Target's id, the fast path (`privateTargetId`) misses, so a temporary CDP session issues `Target.getTargetInfo`. If the response lacks `targetInfo.targetId`, this ToolError is thrown and the session is detached in `finally`.","triggerScenarios":"`targetIdForTarget` / `targetIdForPage` / `#findAttachedTarget` invoked on a target that is detaching or closing — the CDP round-trip succeeds structurally but carries no target id.","commonSituations":"Tab closed concurrently with bookkeeping; service-worker or extension-background targets enumerated by mistake; puppeteer upgrade removing the `_targetId` fast path so every lookup hits the fragile CDP fallback.","solutions":["Skip non-page targets before resolving ids (`target.type() === \"page\"` check).","Treat the error as 'target is gone': drop the tab from tracking and re-enumerate `browser.targets()`.","Upgrade/pin puppeteer so the private `_targetId` fast path is available again.","Retry the lookup after a short delay if the target is expected to settle."],"exampleFix":"// before\nconst id = targetIdForPage(page); // throws if CDP info is empty\n// after\ntry {\n  const id = targetIdForPage(page);\n} catch {\n  await supervisor.forgetTab(page); // target vanished; re-list tabs instead of failing\n}","handlingStrategy":"fallback","validationCode":"const candidates = browser.targets().filter(t => t.type() === \"page\");\nif (candidates.length === 0) throw new Error(\"no page targets attached\");","typeGuard":null,"tryCatchPattern":"try {\n  const id = await targetIdForPage(page);\n} catch {\n  const id = (await browser.pages()).find(p => p === page) ? undefined : null;\n  // fall back to re-listing pages and matching by URL\n}","preventionTips":["Skip non-page targets before id resolution","Treat id-resolution failures as 'target gone' and re-enumerate","Pin puppeteer to a version where Target._targetId exists"],"tags":["cdp","puppeteer","target-id","browser-tab"],"backgroundTag":"cdp-target-info-unavailable","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}