(Created on )

Puppeteer: Failed to add page binding with name {value}: globalThis['{value}'] already exists!

A preload page binding collides with an existing globalThis name.


A preload page binding collides with an existing globalThis name.

Error message

Failed to add page binding with name {value}: globalThis['{value}'] already exists!

{value} is replaced by the value shown in your error message.

How this error happens

exposeFunction reserves a binding name on the page. Registering that same name again collides with the existing Puppeteer binding.

The snippets use an open WebDriver BiDi page named page.

await page.exposeFunction(
    "readSettings",
    () => {
        return {
            theme: "dark",
        };
    }
);

await page.exposeFunction(
    "readSettings",
    () => {
        return {
            theme: "light",
        };
    }
);

How to fix

Register once during page setup. If you intentionally replace a binding you own, remove it before registering the replacement.

await page.removeExposedFunction(
    "readSettings"
);

await page.exposeFunction(
    "readSettings",
    () => {
        return {
            theme: "light",
        };
    }
);

Things to keep in mind

Do not overwrite globals owned by the website. CDP names window in this message; BiDi names globalThis. The fix assumes the first registration completed successfully.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →