Cannot select device through detached session!
How to fix the Puppeteer error: Cannot select device through detached session!
Error
Cannot select device through detached session!
What it means
Puppeteer raised this from its Puppeteer runtime code. In practice, it usually means your script reached a browser, page, frame, element, or option state that the API cannot use safely.
How to fix it
- Make sure the page, browser context, and CDP session are still open before issuing the command.
- Avoid racing cleanup code with pending Puppeteer operations; await the operation before closing the page or browser.
Minimal guard
try {
// Run the Puppeteer operation that triggers this error.
} catch (error) {
if (error instanceof Error && error.message.includes("Cannot select device through detached se")) {
// Apply the fix above, then retry or fail with a clearer message.
}
throw error;
}