(Created on )

Puppeteer: Cannot wait for device prompt through detached session!

Waiting for a device prompt uses a detached session.


Waiting for a device prompt uses a detached session.

Error message

Cannot wait for device prompt through detached session!

How this error happens

A device chooser depends on a live page session. Closing the page before waiting the prompt removes that session.

Use an open Chrome/CDP page named page whose #connect-device control requests a supported device prompt. Run the fix on a fresh page.

await page.close();

await page.waitForDevicePrompt();

How to fix

Complete or cancel the chooser while the page is alive, then close the page.

const waiting = page.waitForDevicePrompt();

await page.click(
    "#connect-device"
);

const prompt = await waiting;

await prompt.cancel();

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.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →