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桌面。

 

posted on 2020-07-20 16:52  靖儿  阅读(7497)  评论(0编辑  收藏  举报

导航