Mos*_*hie 2 javascript node.js puppeteer puppeteer-cluster
我在puppeteer-cluster文档中使用这个示例
我在节点 v10.15.3 上运行它,我尝试将 headless 属性和 SlowMo 传递给 puppeteer 选项。
我希望代码能够注销并创建页面的屏幕截图,但是,发生的情况是几个 chrome 实例启动,它们不加载任何页面,然后控制台挂起并出现错误:
(node:30826) UnhandledPromiseRejectionWarning: Error: Unable to get browser page
at Worker.<anonymous> (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:43:31)
at Generator.next (<anonymous>)
at fulfilled (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:4:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:30826) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 21)
(node:30826) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:30826) UnhandledPromiseRejectionWarning: Error: Unable to get browser page
at Worker.<anonymous> (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:43:31)
at Generator.next (<anonymous>)
at fulfilled (/Users/Starlord/Code/oppose/node_modules/puppeteer-cluster/dist/Worker.js:4:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:30826) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 22)
^Cinternal/process/per_thread.js:198
throw errnoException(err, 'kill');
^
Error: kill ESRCH
at process.kill (internal/process/per_thread.js:198:13)
at process.killChrome (/Users/Starlord/Code/oppose/node_modules/puppeteer/lib/Launcher.js:110:17)
at process.emit (events.js:189:13)
Run Code Online (Sandbox Code Playgroud)
当库无法创建新的浏览器页面时,会发生此错误。多次尝试打开新的上下文/页面/浏览器(取决于您的设置)后,会在此处引发错误。
调试日志
要获取有关导致错误的原因的更多信息,您可以检查调试日志。这将在调试模式下启动应用程序并将记录更多信息。要进入调试模式,您需要使用环境变量启动应用程序DEBUG='puppeteer-cluster:*':
# Linux
DEBUG='puppeteer-cluster:*' node application.js
# Windows Powershell
$env:DEBUG='puppeteer-cluster:*';node application.js
Run Code Online (Sandbox Code Playgroud)
问题
在您的情况下,调试日志显示(从上面的评论复制):
puppeteer-cluster:工作人员获取浏览器页面时出错(尝试:9),消息:this.browser.createIncognitoBrowserContext 不是函数 +660ms
这意味着,createIncognitoBrowserContext库无法用来创建新的上下文。正如您已经确认的那样,情况确实如此,因为您使用的是旧的木偶操作者安装。要使用该设置{ concurrency: Cluster.CONCURRENCY_CONTEXT },您必须至少使用1.5.0 版本,因为这是引入上下文时的版本。
使固定
要解决此问题,请更新您的 puppeteer 安装:
npm install puppeteer@latest
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4367 次 |
| 最近记录: |