在heroku上没有无头的情况下激活镀铬时出错 [英] Error while excuting chrome without headless on heroku

查看:128
本文介绍了在heroku上没有无头的情况下激活镀铬时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个项目,我需要构建一个应用程序,需要在浏览器中打开一个URL才能使用它上面的一些函数。

我用的是



参见故障排除指南以获取更多帮助。


I am currently working on project where I need to build an application that needs to open an URL in a browser in order to use some functions on it.
for that I used puppeteer inside a nodejs script in order to open the browser on the server side so I can use it like an api .

Here's the code (nodejs):

app.get('/do', (req, res) => {
    console.log("ok");
    (async() => {
        var browser = await puppeteer.launch(
            { args: ['--no-sandbox','--disable-setuid-sandbox'], headless: false });
        var page = await browser.newPage();
        await page.goto('https://url.com');//i hid the url for personal reason
        await page.waitFor(1000); // to wait for 1000ms
        await page.waitFor('body div'); // to wait for the 'body div' selector in body
        await page.waitFor(() => Math.random() < 0.5); // to wait for the predicate
        await page.screenshot({
            path: 'public/photo.png'
        });

        await browser.close();
        await res.end('<html><head></title></head><body><h1><img src=photo.png ></img></h1></body></html>');
    })();

});

This code works locally but when I deploy on heroku it shows me this error :

app[web.1]: /send
app[web.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Failed to launch chrome!
app[web.1]: /app/node_modules/puppeteer/.local-chromium/linux-515411/chrome-linux/nacl_helper: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
app[web.1]: [21:21:1228/131735.202176:ERROR:nacl_fork_delegate_linux.cc(316)] Bad NaCl helper startup ack (0 bytes)
app[web.1]:
app[web.1]:
app[web.1]: TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
app[web.1]:
app[web.1]: (node:4) [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.

But if I remove headless: false it works but the problem is that the url shows a warming page that I need to use a browser like chrome or mozilla or safari.

How can I resolve this issue ?

解决方案

You need to include the Puppeteer Heroku buildpack to the list of buildpacks for your app. Go to your Heroku dashboard and open your app. Go to Settings > Buildpacks > Add buildpack and use this URL.

https://github.com/jontewks/puppeteer-heroku-buildpack

When you click add buildpack, simply paste that URL into the input, and click save. On the next deploy, your app will also install the dependencies that Puppeteer needs to run.

See the troubleshooting guide for more help.

这篇关于在heroku上没有无头的情况下激活镀铬时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆