我正在使用这个 Laravel 包:https://github.com/spatie/browsershot 来截取屏幕截图。它基于 Puppeteer
但是当我运行时它返回此错误
错误输出:
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.
我检查了
/home/sail/.cache/puppeteer/chrome
,看到有一个文件夹名称linux-115.0.5790.170/chrome-linux64
,所以我认为Chrome已经下载成功了。
你知道为什么吗?
不久前,我在使用 Selenium 进行自动化测试时遇到了类似的问题,该测试使用无头浏览器登录远程站点并检索文件。每当 Chrome 更新时,版本都会不匹配。
尝试使用:
sudo apt install google-chrome-stable
将已安装的 Chrome 更新到最新的二进制文件,然后重新运行。