(Created on )

Puppeteer: This should never happen.

A file-chooser event's frame ID cannot be found in the CDP frame registry.


A file-chooser event’s frame ID cannot be found in the CDP frame registry.

Error message

This should never happen.

How this error happens

A CDP file-chooser event names the frame that opened the chooser. If that frame is gone from Puppeteer’s frame registry, the event cannot be associated with its input. Removing the iframe during its click is a relevant race.

The snippets use an open Chrome/CDP page named page.

await page.setContent(
    '<iframe srcdoc="<input id=upload type=file>"></iframe>'
);

const iframe = await page.$("iframe");
const frame = await iframe.contentFrame();

await frame.$eval("#upload", (input) => {
    input.addEventListener("click", () => {
        window.frameElement.remove();
    });
});

await Promise.all([
    page.waitForFileChooser({
        timeout: 5000,
    }),
    frame.click("#upload"),
]);

How to fix

Keep the input’s frame attached until the chooser has been handled. Remove the frame-replacement handler from this controlled example.

await page.setContent(
    '<iframe srcdoc="<input id=upload type=file>"></iframe>'
);

const iframe = await page.$("iframe");
const frame = await iframe.contentFrame();

const [chooser] = await Promise.all([
    page.waitForFileChooser(),
    frame.click("#upload"),
]);

await chooser.accept([
    "/absolute/path/report.csv",
]);

Things to keep in mind

The file must exist. Event ordering can instead produce a chooser timeout or detached-frame error in the failing case. If the registry assertion occurs with a stable frame, retain the minimal reproduction; do not insert guessed frame IDs into private maps.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →