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

时间:2019-05-18 07:38:29

标签: javascript node.js puppeteer puppeteer-cluster

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

我正在节点v10.15.3上运行此程序,我试图将headless属性和slowMo传递给操纵up选项。

我希望代码注销并创建页面的屏幕截图,但是,发生的情况是启动了多个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)

2 个答案:

答案 0 :(得分:2)

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

调试日志

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

# Linux
DEBUG='puppeteer-cluster:*' node application.js
# Windows Powershell
$env:DEBUG='puppeteer-cluster:*';node application.js

问题

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

  

puppeteer-cluster:工作者获取浏览器页面时出错(尝试:9),消息:this.browser.createIncognitoBrowserContext不是+ 660ms函数

这意味着该库没有可用于创建新上下文的createIncognitoBrowserContext。如您已经确认的,情况就是这样,因为您使用的是旧的操纵up安装程序。要使用设置{ concurrency: Cluster.CONCURRENCY_CONTEXT },必须至少使用version 1.5.0,就像引入上下文时一样。

修复

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

npm install puppeteer@latest

答案 1 :(得分:1)

问题是我在使用较旧版本的puppeteer的puppeteer-cluster之前使用了puppeteer-pool。

我删除了puppeteer-pool并安装了puppeteer,它可以按预期工作