gpt4 book ai didi

javascript - Puppeteer 集群示例抛出错误 : Unable to get browser page

转载 作者:搜寻专家 更新时间:2023-10-31 23:44:18 26 4
gpt4 key购买 nike

我在 puppeteer-cluster 中使用这个例子文档

我在 Node 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)

最佳答案

当库无法创建新的浏览器页面时会发生此错误。抛出错误 here在多次尝试打开新的上下文/页面/浏览器(取决于您的设置)之后。

调试日志

要获得有关错误原因的更多信息,您可以查看 debugging log .这将以 Debug模式启动应用程序并将记录更多信息。要进入 Debug模式,您需要使用环境变量 DEBUG='puppeteer-cluster:*':

启动应用程序
# Linux
DEBUG='puppeteer-cluster:*' node application.js
# Windows Powershell
$env:DEBUG='puppeteer-cluster:*';node application.js

问题

在您的情况下,调试日志显示(从您上面的评论中复制):

puppeteer-cluster: Worker Error getting browser page (try: 9), message: this.browser.createIncognitoBrowserContext is not a function +660ms

这意味着,没有 createIncognitoBrowserContext 库可以用来创建新的上下文。正如您已经确认的那样,是这种情况,因为您使用的是旧的 puppeteer 安装。要使用设置 { concurrency: Cluster.CONCURRENCY_CONTEXT },您必须至少使用 version 1.5.0因为那是引入上下文的时候。

修复

要解决此问题,请更新您的 puppeteer 安装:

npm install puppeteer@latest

关于javascript - Puppeteer 集群示例抛出错误 : Unable to get browser page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56196941/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com