Puppeteer: Missing target on swap
A target-swap event refers to a session without an associated target.
A target-swap event refers to a session without an associated target.
Error message
Missing target on swap
How this error happens
Page activation swapped in a session without its associated primary target. This is an internal target-activation invariant.
The snippets use an open Chrome/CDP page named page. Run the sequences separately.
await Promise.all([
page.goto("about:blank?next"),
page.close(),
]);
How to fix
Do not tear down the page while navigation or activation is still in progress. Let navigation finish before cleanup.
await page.goto(
"about:blank?next"
);
const title = await page.title();
console.log(title);
await page.close();
Things to keep in mind
This race illustrates competing page lifecycles; a normal navigation does not reliably force a target swap or this exact invariant. If the error persists without cleanup races, reproduce the activation path and isolate plugins or custom auto-attach handling.