stereobooster / react-snap

👻 Zero-configuration framework-agnostic static prerendering for SPAs
MIT License
5.05k stars 394 forks source link

Error: Failed to launch chrome! #527

Closed AndreaMastracchio closed 3 years ago

AndreaMastracchio commented 3 years ago

Hi Guys! thank you in advance for the help.

I am getting this error in deploying my App initialized with CRA.

"Error: Failed to launch chrome! (chrome:4474): Gtk-WARNING **: 13:53:38.045: cannot open display: TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md at onClose (/tmp/build_68def651/node_modules/react-snap/node_modules/puppeteer/lib/Launcher.js:348:14) at ChildProcess. (/tmp/build_68def651/node_modules/react-snap/node_modules/puppeteer/lib/Launcher.js:338:60) at ChildProcess.emit (events.js:327:22) at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)"

I tried to add to package.json that line

""reactSnap": { "puppeteerArgs": [ "--no-sandbox", "--disable-setuid-sandbox" ] } " and the buildpack on heroku:

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

But it's still not working.

Could you please help me?

Thanks, Andrea

AndreaMastracchio commented 3 years ago

Hi! adding on my server.js

"app.get('*', function(req, res) { var urlToScreenshot = parseUrl(req.query.url); if (validUrl.isWebUri(urlToScreenshot)) { (async() => { const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }); const page = await browser.newPage(); await page.goto(urlToScreenshot); await browser.close(); })(); } else { res.send('Invalid url: ' + urlToScreenshot); }

});"

resolve issue!