(Created on )

Puppeteer: Target must exist

An internal CDP session has no associated target.


An internal CDP session has no associated target.

Error message

Target must exist

How this error happens

An internal CDP session had no associated target when a target-dependent operation used it. 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.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →