Puppeteer: Failed to add page binding with name {value}: window['{value}'] already exists!
exposeFunction attempts to register an already-known window binding name.
exposeFunction attempts to register an already-known window binding name.
Error message
Failed to add page binding with name {value}: window['{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 Chrome/CDP 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.