puppeteer插件啟動chrome失敗: Error: Failed to launch the browser process!


最近使用puppeteer插件啟動chrome失敗,有的系統無法啟動喚起chrome

自己筆記本電腦安裝有360會提示被阻止,允許執行即可調用成功,公司電腦,沒有任何提示直接無法啟動(公司殺毒軟件無法配置關閉)

控制台報錯:

(node:2620) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md

    at onClose (E:\shimoxix2\node\node-pup\node_modules\_puppeteer@5.2.0@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:193:20)
    at ChildProcess.<anonymous> (E:\shimoxix2\node\node-pup\node_modules\_puppeteer@5.2.0@puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:184:79)
    at ChildProcess.emit (events.js:201:15)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:257:12)
(node:2620) 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: 1)
(node:2620) [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.

  后來經過嘗試發現

  強制配置chrome路徑executablePath,並指定可以打開看到瀏覽器效果headless,可以勉強使用,如果不允許瀏覽器可視,我做的頁面抓取內容會失敗。。

  const browser = await puppeteer.launch({
    //如果無法啟動chrome,指定瀏覽器路徑:executablePath,headless設置為false:可以看到瀏覽器
    executablePath:'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
    headless: false, //可以看到打開瀏覽器效果,默認值true
    puppeteerOptions: {
      ignoreHTTPSErrors: true,
      dumpio: false,
    }
  });

 

后來發現,linux啟動puppeteer 需要在有桌面的命令行下運行,比如ubuntu桌面。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM