我正在尝试在Electron中使用Pupppeteer进行一些自动化。我使用简单的命令node test.js
测试了以下代码,没有任何错误:
(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();
})();
但是当我在Electron中运行完全相同的代码时,出现以下错误,指出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
我该如何解决?
最佳答案
尝试传递一个字符串来求值,而不是传递一个函数(用反引号引起来)。
您也可以尝试使用eval('your-code-as-string');进行 package 。
关于javascript - 未捕获( promise )错误: Passed function is not well-serializable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66293772/