(Created on )

Puppeteer: Cannot cancel DeviceRequestPrompt which is already handled!

The device prompt has already been handled before cancel.


The device prompt has already been handled before cancel.

Error message

Cannot cancel DeviceRequestPrompt which is already handled!

How this error happens

A device request prompt can be selected or cancelled only once. Reusing a completed prompt repeats its resolution.

The failing snippet assumes prompt is a live DeviceRequestPrompt from your application’s device chooser. Replace “Test device” with the device you intend to use.

const device = await prompt.waitForDevice(
    (device) => device.name.includes("Test device")
);

await prompt.select(
    device
);

await prompt.cancel();

How to fix

Handle a fresh prompt once. Get a device object from that exact prompt rather than reusing one from an earlier prompt.

const [prompt] = await Promise.all([
    page.waitForDevicePrompt(),
    page.click("#connect-device"),
]);

const device = await prompt.waitForDevice(
    (device) => device.name.includes("Test device")
);

await prompt.select(
    device
);

Things to keep in mind

The application must request a supported device prompt in response to the click, and a matching device must be available. For cancellation, call prompt.cancel once instead of selecting a device.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →