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就知道了文件的位置。

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

  • 相关阅读:
    后端开发-IDEA-SSM框架-mapper扫描
    测试软件注意事项
    字符串中重复最多的字符及重复次数
    【windows】server2012R2 服务器的日志出现大量Windows安全日志事件ID 4625
    【办公】管理员已阻止你运行此应用。有关详细信息,请与管理员联系。windows10
    【linux】dellR420更换系统盘,重做系统
    【mysql】MySQL InnoDB 表损坏,显示错误: “MySQL is trying to open a table handle but the .ibd file for table ### does not exist”
    【linux】服务器的网站后台无法上传图片报错error‘8’,云锁文件删除无法删除
    【linux】记录一次服务器无法使用ssh 错误修改文件导致服务器无法启动
    【linux】nginx访问量统计
  • 原文地址:https://www.cnblogs.com/c-x-a/p/14604076.html
Copyright © 2011-2022 走看看