Heroku上的Puppeteer:无法启动浏览器进程

时间:2020-07-30 16:14:51

标签: heroku puppeteer

我在Heroku上使用Puppeteer,收到以下错误:

Failed to launch the browser process! /usr/src/app/node_modules/puppeteer/.local-chromium/linux-756035/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md

4 个答案:

答案 0 :(得分:7)

  1. 将浏览器声明为:

    const browser = await puppeteer.launch({
                      headless: true,
                      args: ['--no-sandbox','--disable-setuid-sandbox']
                    })
    
  2. 安装 heroku buildpack puppeteer heroku buildpack

  3. 必须清除heroku缓存

  4. git add .

  5. git commit -m "some text"

  6. git push heroku master

答案 1 :(得分:2)

这可能有帮助(从Puppeteer官方网站复制)

在Heroku(https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-on-heroku)上运行木偶

在Heroku上运行Puppeteer还需要一些其他依赖项,而Heroku为您准备的Linux盒中没有这些依赖项。要在部署时添加依赖项,请在“设置”>“构建包”下,将Puppeteer Heroku构建包添加到应用程序的构建包列表中。

buildpack的URL为https://github.com/jontewks/puppeteer-heroku-buildpack

确保在启动Puppeteer时使用的是“ --no-sandbox”模式。可以通过将其作为参数传递给您的.launch()调用来完成:puppeteer.launch({args:['--no-sandbox']}));。

单击添加buildpack时,只需将该URL粘贴到输入中,然后单击“保存”。在下一次部署中,您的应用还将安装Puppeteer需要运行的依赖项。

如果您需要呈现中文,日文或韩文字符,则可能需要使用带有其他字体文件的buildpack,例如https://github.com/CoffeeAndCode/puppeteer-heroku-buildpack

@timleland还有另一本简单的指南,其中包括一个示例项目:https://timleland.com/headless-chrome-on-heroku/

答案 2 :(得分:0)

是否可以在 Heroku 上使用 headless:false 运行它? 它给了我这个错误:

Error: Failed to launch the browser process!
14 Jan 2021 03:32:18.882186 <190>1 2021-01-14T01:32:18.282094+00:00 app background.1 - - [24:24:0114/013218.244739:ERROR:browser_main_loop.cc(1512)] Unable to open X display.

答案 3 :(得分:0)

你不能使用 headless: false 在 Heroku 上运行 Puppeteer,因为它没有可显示的 GUI。

你需要使用 headless: true 那是因为它在没有 GUI 的 Linux 上运行

如果您还有其他错误,您可能需要阅读官方 Puppeteer 故障排除指南:Running Puppeteer on Heroku.