【问题标题】:Puppeteer and Headless Chrome Crawler on macOS 11.1 Big SurmacOS 11.1 Big Sur 上的 Puppeteer 和 Headless Chrome Crawler
【发布时间】:2021-01-13 14:41:31
【问题描述】:

在安装了 macOS 11.1 (Big Sur) 的 Intel MacBook Pro 上运行 Headless Chrome Crawler (hccrawler) 时,我们收到以下错误:

hccrawler:console error Failed to load resource: net::ERR_FAILED at https://example.com/some-page
(node:12722) UnhandledPromiseRejectionWarning: Error: Page crashed!
    at Page._onTargetCrashed (./node_modules/puppeteer/lib/Page.js:156:24)
    at CDPSession.Page.client.on.event (./node_modules/puppeteer/lib/Page.js:132:56)
    at CDPSession.emit (events.js:198:13)
    at CDPSession.EventEmitter.emit (domain.js:448:20)
    at CDPSession._onMessage (./node_modules/puppeteer/lib/Connection.js:232:12)
    at Connection._onMessage (./node_modules/puppeteer/lib/Connection.js:119:19)

注意:为了获得更详细的日志,我使用了DEBUG='hccrawler:*' 环境变量。

版本:

  • node.js:10.16
  • 无头 Chrome 爬虫:1.8.0
  • 傀儡师:1.5.0

对于以前版本的 macOS 和 Ubuntu,它仍然可以正常工作。知道问题可能是什么吗?会不会是最新的 macOS 版本以某种方式阻止了 Puppeteer 生成的 Chromium 进程?

【问题讨论】:

    标签: node.js macos puppeteer chromium


    【解决方案1】:

    升级到最新版本的 headless-chrome-crawler(master 分支)解决了这个问题。将此添加到您的 package.json 文件中:

    "headless-chrome-crawler": "git://github.com/yujiosaka/headless-chrome-crawler.git#f4004f6f1a27534222703f9161f44815c8eefbe3"
    

    "headless-chrome-crawler": "git://github.com/yujiosaka/headless-chrome-crawler.git#master"
    

    这会将 Puppeteer 1.20.0 和 Chromium r686378 安装到您的 node_modules。

    注意:当您阅读本文时,可能已经有新版本的 HCC > 1.8.0,因此您可能只能执行 npm install headless-chrome-crawler@latest

    另外请注意,您可以使用自定义 Chromium 路径作为传递给 hccrawler.launch() 的选项的一部分,这对于调试或快速尝试其他版本很有用:

    hccrawler.launch({
      // ...
      executablePath: '/path/to/custom/Chromium.app/Contents/MacOS/Chromium'
    });
    

    如果打包的 Chromium 版本仍然无法运行,您也可以提供 Google Chrome 安装的路径,例如:

    hccrawler.launch({
      // ...
      executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    });
    

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 2021-03-31
      • 2021-04-15
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 2021-12-04
      • 1970-01-01
      相关资源
      最近更新 更多