zoukankan      html  css  js  c++  java
  • mac使用puppeteer报错,UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!

    (node:63185) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process! spawn /Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer-core/.local-chromium/mac-818858/chrome-mac/Chromium.app/Contents/MacOS/Chromium ENOENT
    
    
    TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
    
        at onClose (/Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
        at ChildProcess.<anonymous> (/Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:185:85)
        at ChildProcess.emit (events.js:315:20)
        at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
        at onErrorNT (internal/child_process.js:465:16)
        at processTicksAndRejections (internal/process/task_queues.js:80:21)
    (Use `node --trace-warnings ...` to show where the warning was created)
    (node:63185) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
    (node:63185) [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.
    

    问题原因,没有在默认路径下找到Chromium。

    解决步骤:
    断点调试
    跟踪到文件

    /node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js
    

    找到这一行

            const outputPath = this._getFolderPath(revision);
    

    打印输出outputPath,结果为

    ‌/Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer-core/.local-chromium/mac-818858
    

    再结合程序报道那个错误,其中给出了完整的路径

    /Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer-core/.local-chromium/mac-818858/chrome-mac/Chromium.app/Contents/MacOS/Chromium
    

    可以发现.local-chromium往后就没有东西了。所以程序找不到是理所当然了。

    接下来就是查找chromium到底在什么位置,通过以下代码可以得到它的路径。

    const puppeteer = require("puppeteer");
    const browserFetcher = puppeteer.createBrowserFetcher();
    
    const run=async ()=>{
      const res=await browserFetcher.download("818858") //程序第一次报错会显示这个版本号
      console.log(res)
    }
    run()
    

    得到信息

    {
      revision: '818858',
      executablePath: '/Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer/.local-chromium/mac-818858/chrome-mac/Chromium.app/Contents/MacOS/Chromium',
      folderPath: '/Users/chennan/xxxx/crawler-core/webapp/node_modules/puppeteer/.local-chromium/mac-818858',
      local: true,
      url: 'https://storage.googleapis.com/chromium-browser-snapshots/Mac/818858/chrome-mac.zip',
      product: 'chrome'
    }
    
    

    通过executablePath就知道了文件的位置。

    然后补全之前的路径即可。

  • 相关阅读:
    input File 提交文件上传 无法传递数据的原因
    谈谈运维该掌握那些技能
    虚拟机vmware 下Centos 系统磁盘扩容
    jenkins针对不同的项目组对用户进行权限分配
    Mac Catalina 手残误删系统文件恢复过程
    自动化持续集成
    zabbix 监控之主动配置模式
    nginx对请求后缀或IP访问限制
    elasticsearch7.2.1 报错 Received fatal alert: handshake_failure
    使用nexus创建npm私服
  • 原文地址:https://www.cnblogs.com/c-x-a/p/14604076.html
Copyright © 2011-2022 走看看