I’m using this Laravel package: https://github.com/spatie/browsershot to take a screenshot. It’s based on Puppeteer
But when I run it returns this error
Error Output:
Error: Could not find Chrome (ver. 119.0.6045.105). This can occur if either
1. you did not perform an installation before running the script (e.g. `npx puppeteer browsers install chrome`) or
2. your cache path is incorrectly configured (which is: /home/sail/.cache/puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
at ChromeLauncher.resolveExecutablePath (/var/www/html/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:278:27)
at ChromeLauncher.executablePath (/var/www/html/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:209:25)
at ChromeLauncher.computeLaunchArguments (/var/www/html/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:103:37)
at async ChromeLauncher.launch (/var/www/html/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:69:28)
at async callChrome (/var/www/html/vendor/spatie/browsershot/bin/browser.cjs:91:23)
{"exception":"[object] (Symfony\Component\Process\Exception\ProcessFailedException(code: 0): The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=`npm root -g` node '/var/www/html/vendor/spatie/browsershot/src/../bin/browser.cjs' '{"url":"file:\/\/\/tmp\/2013666216-0476504001704712330\/index.html","action":"screenshot","options":{"type":"jpeg","quality":100,"args":["--no-sandbox"],"viewport":{"width":1200,"height":630},"displayHeaderFooter":false,"newHeadless":true}}'" failed.
I checked the /home/sail/.cache/puppeteer/chrome
and see there is an folder name linux-115.0.5790.170/chrome-linux64
so I think Chrome already downloaded success.
Do you know why?
2
Answers
OK, after 12 hours of debugging and feeling crazy, I finally made it work
Since Puppeteer v19, the Chrome will be saved to
~/.cache/puppeteer
instead of insidenode_modules
But some servers don't allow to read the
~/.cache/puppeteer
, that's why it's there but still shows theCould not find
error. You need to move the.cache
folder to your root project.In my case, I create a
.puppeteerrc.cjs
fileMake sure you uninstall and re-install the Puppeteer again:
After that, we need to install some required dependencies here https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-doesnt-launch-on-linux
I'm using Ubuntu so I need to install:
I had a similar issue a while back for an automated test using Selenium that was using a headless browser to login to a remote site and retrieve a file. Whenever Chrome updated, the version didn’t match.
Try using :
to update your installed Chrome to the latest binaries and then re-run.