Puppeteer cluster example throwing Error: Unable to get browser page
Puppeteer cluster example throwing Error: Unable to get browser page
我在 puppeteer-cluster 文档中使用这个示例
我 运行 在节点 v10.15.3 上,我尝试将无头 属性 和 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)
问题是我在 puppeteer-cluster 之前使用了 puppeteer-pool,它使用了旧版本的 puppeteer。
我删除了 puppeteer-pool 并安装了 puppeteer,它按预期工作
当图书馆无法创建新的浏览器页面时会发生此错误。多次尝试打开新的 context/page/browser(取决于您的设置)后,会抛出错误 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
库可以用来创建新的上下文。正如您已经确认的那样,是这种情况,因为您使用的是旧的人偶安装。要使用设置 { concurrency: Cluster.CONCURRENCY_CONTEXT }
,您必须至少使用 version 1.5.0,就像引入上下文时那样。
修复
要解决此问题,请更新您的 puppeteer 安装:
npm install puppeteer@latest
我在 puppeteer-cluster 文档中使用这个示例
我 运行 在节点 v10.15.3 上,我尝试将无头 属性 和 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)
问题是我在 puppeteer-cluster 之前使用了 puppeteer-pool,它使用了旧版本的 puppeteer。
我删除了 puppeteer-pool 并安装了 puppeteer,它按预期工作
当图书馆无法创建新的浏览器页面时会发生此错误。多次尝试打开新的 context/page/browser(取决于您的设置)后,会抛出错误 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
库可以用来创建新的上下文。正如您已经确认的那样,是这种情况,因为您使用的是旧的人偶安装。要使用设置 { concurrency: Cluster.CONCURRENCY_CONTEXT }
,您必须至少使用 version 1.5.0,就像引入上下文时那样。
修复
要解决此问题,请更新您的 puppeteer 安装:
npm install puppeteer@latest