Puppeteer: Custom object serialization not possible. Use plain objects instead.
The BiDi serializer cannot encode a custom object instance.
The BiDi serializer cannot encode a custom object instance.
Error message
Custom object serialization not possible. Use plain objects instead.
How this error happens
WebDriver BiDi cannot serialize an arbitrary class instance as a function argument. Its methods and prototype do not form a plain data payload.
The snippets use a WebDriver BiDi page named page.
class Settings {
constructor() {
this.theme = "dark";
}
}
await page.evaluate(
(settings) => settings.theme,
new Settings()
);
How to fix
Pass a plain object with the values the page needs.
const settings = {
theme: "dark",
};
const theme = await page.evaluate(
(value) => value.theme,
settings
);
console.log(theme);
Things to keep in mind
Do not assume every value can be fixed with JSON.stringify. Functions, symbols, cycles and special data types need an intentional representation.