Puppeteer: Session already detached. Most likely the {value} has been closed.
detach is called on a CDP session already detached or whose target closed.
detach is called on a CDP session already detached or whose target closed.
Error message
Session already detached. Most likely the {value} has been closed.
{value} is replaced by the value shown in your error message.
How this error happens
Detaching a session is a one-time cleanup operation. A second detach tries to remove a session that is already gone.
The snippets use an open Puppeteer page named page.
const session = await page.createCDPSession();
await session.detach();
await session.detach();
How to fix
Put session cleanup in one owner and call detach once.
const session = await page.createCDPSession();
try {
await session.send(
"Runtime.enable"
);
} finally {
await session.detach();
}
Things to keep in mind
If the target closes on its own, cleanup can also encounter a detached session. Treat expected target closure separately from an unexpected command failure.