Puppeteer: CDPSession creation failed.
Target.attachToTarget returned a session that Puppeteer cannot find in its registry.
Target.attachToTarget returned a session that Puppeteer cannot find in its registry.
Error message
CDPSession creation failed.
How this error happens
A CDP attach response returned a session that Puppeteer could not find in its connection registry. This can accompany session teardown or inconsistent browser/protocol event ordering.
The snippets use an open CDP-capable page named page. The first sequence illustrates a session lifecycle problem, not a guaranteed reproduction of an internal map failure.
const session = await page.createCDPSession();
await page.close();
await session.send(
"Runtime.evaluate",
{
expression: "1 + 1",
}
);
How to fix
Keep the page alive while using its session and clean up in order. Run the correction on a new open page.
const session = await page.createCDPSession();
try {
const result = await session.send(
"Runtime.evaluate",
{
expression: "1 + 1",
}
);
console.log(result.result.value);
} finally {
await session.detach();
await page.close();
}
Things to keep in mind
The closure example can produce a session-closed error before reaching this particular registry check. If the exact error occurs without teardown, isolate custom transports, plugins and manual target-attachment commands. Do not supply guessed session IDs.