Puppeteer: Cannot select device through detached session!
Device selection is attempted through a detached CDP session.
Device selection is attempted through a detached CDP session.
Error message
Cannot select device through detached session!
How this error happens
A device chooser depends on a live page session. Closing the page before selecting the prompt removes that session.
Assume page is open, prompt is its current device chooser and device belongs to that prompt. Run the failing and corrected sequences separately.
await page.close();
await prompt.select(device);
How to fix
Complete or cancel the chooser while the page is alive, then close the page.
await prompt.select(device);
await page.close();
Things to keep in mind
The exact error depends on whether the page closure is observed before or during the operation. Reopening a page does not revive an old prompt; wait for a new prompt on the new page.