Uncaught (in promise) Error: Passed function is not well-serializable

Viewed 258

I'm trying to use Pupppeteer in Electron to do some automation. I tested the following code with simple command node test.js without any errors:

(async () => {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();
    await page.goto('https://www.facebook.com/');
    await page.waitFor(2000);
    await page.click('button[type="submit"]');
    await page.waitFor(2000);
    await page.screenshot({ path: 'example.png' });
    await browser.close();
  })();

but when I ran the exact same code in in Electron I get the following error which points out there an error with await page.click('button[type="submit"]');

Uncaught (in promise) Error: Passed function is not well-serializable!
at ExecutionContext._evaluateInternal (ExecutionContext.ts:247)
at ExecutionContext.evaluateHandle (ExecutionContext.ts:191)
at ElementHandle.evaluateHandle (JSHandle.ts:183)
at Object.internalHandler.queryOne (QueryHandler.ts:68)
at ElementHandle.$ (JSHandle.ts:778)
at DOMWorld.$ (DOMWorld.ts:171)
at async DOMWorld.click (DOMWorld.ts:434)
at async file:/Users/usr/Desktop/aa/renderer.js:17

how can I fix it??

1 Answers

Try to pass a string to evaluate rather than a function (wrap it with backticks).

You can also try and wrap it with eval('your-code-as-string');

Related