javascript - 未捕获(承诺中)错误:传递的函数不能很好地序列化
问题描述
我正在尝试在 Electron 中使用 Puppppeteer 进行一些自动化。我用简单的命令测试了以下代码,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'); 包装它。
推荐阅读
- google-cloud-run - Cloud Run 是否添加类似于 App 引擎的位置感知请求标头?
- python-3.x - ModuleNotFoundError: No module named 'bokeh' 许多已发布的解决方案尝试但失败了
- sql - 此处不允许列,
- r - 有没有办法使用另一个具有原始和新列名的表来重命名 r 中数据框的列?
- android - url.pathname 或 url.searchParams 不是 android react native 中的函数
- c - clang 致命错误:致命错误:找不到“stdint.h”文件
- react-native - 如何将自定义组件添加到抽屉导航
- python - 如何用python语言为nifi创建插件
- c# - FromSqlRaw 返回值
- php - 搜索最小值时从关联数组返回 array_column