我在 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
Run Code Online (Sandbox Code Playgroud)
小智 7
将浏览器声明为:
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox','--disable-setuid-sandbox']
})
Run Code Online (Sandbox Code Playgroud)
安装heroku buildpack puppeteer heroku buildpack
必须清除heroku缓存
git add .
git commit -m "some text"
git push heroku master
小智 5
也许这会有所帮助(从 Puppeteer 官方网站复制)
在 Heroku 上运行 Puppeteer ( https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#running-puppeteer-on-heroku )
在 Heroku 上运行 Puppeteer 需要一些额外的依赖项,而 Heroku 为您提供的 Linux 机器中未包含这些依赖项。要添加部署依赖项,请将 Puppeteer Heroku 构建包添加到“设置”>“构建包”下应用程序的构建包列表中。
构建包的网址是https://github.com/jontewks/puppeteer-heroku-buildpack
确保启动 Puppeteer 时使用“--no-sandbox”模式。这可以通过将其作为参数传递给 .launch() 调用来完成:puppeteer.launch({ args: ['--no-sandbox'] });。
当您单击“添加构建包”时,只需将该 url 粘贴到输入中,然后单击“保存”即可。在下次部署时,您的应用程序还将安装 Puppeteer 运行所需的依赖项。
如果您需要渲染中文、日文或韩文字符,您可能需要使用带有其他字体文件的构建包,例如https://github.com/CoffeeAndCode/puppeteer-heroku-buildpack
@timleland 还提供了另一个简单指南,其中包含示例项目: https: //timleland.com/headless-chrome-on-heroku/。
| 归档时间: |
|
| 查看次数: |
2973 次 |
| 最近记录: |