{"record":{"id":"da5fa383ca6bf9f3","repo":"puppeteer/puppeteer","slug":"missing-target-for-devtools-page-id-devtoolst","errorCode":null,"errorMessage":"Missing target for DevTools page (id = ${devtoolsTargetId})","messagePattern":"Missing target for DevTools page \\(id = (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/puppeteer-core/src/cdp/Browser.ts","lineNumber":479,"sourceCode":"    return page;\n  }\n\n  async _createDevToolsPage(pageTargetId: string): Promise<Page> {\n    const openDevToolsResponse = await this.#connection.send(\n      'Target.openDevTools',\n      {\n        targetId: pageTargetId,\n      },\n    );\n    return await this._getDevToolsTargetPage(openDevToolsResponse.targetId);\n  }\n\n  async _getDevToolsTargetPage(devtoolsTargetId: string): Promise<Page> {\n    const target = (await this.waitForTarget(t => {\n      return (t as CdpTarget)._targetId === devtoolsTargetId;\n    })) as CdpTarget;\n    if (!target) {\n      throw new Error(\n        `Missing target for DevTools page (id = ${devtoolsTargetId})`,\n      );\n    }\n    const initialized =\n      (await target._initializedDeferred.valueOrThrow()) ===\n      InitializationStatus.SUCCESS;\n    if (!initialized) {\n      throw new Error(\n        `Failed to create target for DevTools page (id = ${devtoolsTargetId})`,\n      );\n    }\n    const page = await target.page();\n    if (!page) {\n      throw new Error(\n        `Failed to create a DevTools Page for target (id = ${devtoolsTargetId})`,\n      );\n    }\n    return page;","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/puppeteer/puppeteer/blob/d484e21c17f6023826fefdcdeeb553e04a7aaed8/packages/puppeteer-core/src/cdp/Browser.ts#L461-L497","documentation":"Thrown by Browser._getDevToolsTargetPage when waitForTarget returns no CdpTarget matching the requested DevTools target id. This is an internal invariant check: the DevTools target id returned by Target.getDevToolsTarget should appear in the target tree, but no live, matching target was found. It signals that the DevTools target vanished or was never exposed by the target manager within the wait window.","triggerScenarios":"Calling page.target().createCDPSession / devtools flows that rely on _getDevToolsTargetPage; explicitly invoking Target.getDevToolsTarget and then waitForTarget with the returned id; DevTools target gets destroyed between the getDevToolsTarget call and the waitForTarget resolution; the target manager's filter rejects the DevTools target (targetFilterCallback), so it is never exposed.","commonSituations":"Custom targetFilterCallback that filters out non-page targets and also drops the DevTools target; browser closing or target being torn down mid-call; headless shell builds that do not expose a DevTools target; race after a crash or detachment where the id becomes stale.","solutions":["Ensure the targetFilterCallback passed at browser launch returns true for the DevTools target type, or use the default filter.","Retry the call after the browser/target has fully settled, or wait for the page target to be stable before requesting its DevTools target.","Confirm the underlying Chrome build supports Target.getDevToolsTarget (some embedders/headless shells do not).","If reproducing during teardown, guard the caller with a browser/region isAlive check before issuing the request."],"exampleFix":"// before\nconst page = await browser._getDevToolsTargetPage(devtoolsTargetId);\n\n// after: avoid the helper, or wait for stability first\nawait pageTarget.initialized();\nconst page = await browser._getDevToolsTargetPage(devtoolsTargetId);","handlingStrategy":"try-catch","validationCode":"// Confirm the page target is alive and initialized before requesting its DevTools target\nif (page.isClosed()) {\n  throw new Error('page closed; cannot open DevTools target');\n}\nawait page.target().initialized();","typeGuard":"function hasDevToolsTargetId(resp: unknown): resp is { targetId: string } {\n  return typeof resp === 'object' && resp !== null && typeof (resp as any).targetId === 'string';\n}","tryCatchPattern":"try {\n  const devtoolsPage = await browser._getDevToolsTargetPage(devtoolsTargetId);\n} catch (e) {\n  if (/Missing target for DevTools page/.test((e as Error).message)) {\n    // target vanished; re-request the DevTools target id or give up\n  } else throw e;\n}","preventionTips":["Keep the originating page target alive for the whole DevTools page request.","Do not use a targetFilterCallback that drops DevTools targets.","Request the DevTools target id lazily, right before use, to minimize stale-id races."],"tags":["devtools","cdp-target","internal-invariant","race-condition"],"backgroundTag":null,"analyzedSha":"d484e21c17f6023826fefdcdeeb553e04a7aaed8","analyzedAt":"2026-08-12T06:33:19.665Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}