的Puppeteer群集示例抛出错误:无法获取浏览器页面

我在puppeteer-cluster文档中使用此示例

我正在节点v10.15.3上运行此程序,我尝试将headless属性和slowMo传递给伪造者选项.

我希望代码注销并创建页面的屏幕截图,但是,发生的情况是启动了几个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 =’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.如您已经确认的,情况就是这样,因为您使用的是旧的操纵up安装程序.要使用设置{并发:Cluster.CONCURRENCY_CONTEXT},您必须至少使用version 1.5.0,因为引入上下文时就是这样.

固定

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

npm install puppeteer@latest
上一篇:myEclipse笔记(1):优化配置


下一篇:无头浏览器 Puppeteer 初探