I installed Laravel Sail on PHP 8.3. I am trying to generate PDF using Spatie/laravel-pdf
but am having a problem with browsershot. I added this line in its docker file
RUN npm install --global --unsafe-perm puppeteer
However, this code
return Pdf::view('food-list.list')
->format('a4')
->save('invoice.pdf');
returns error
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/721750128-0390599001719145322/index.html”,”action”:”pdf”,”options”:{“path”:”invoice.pdf”,”args”:[],”viewport”:{“width”:800,”height”:600},”displayHeaderFooter”:false,”format”:”a4″,”printBackground”:true}}'”
failed. Exit Code: 1(General error) Working directory:
/var/www/html/vendor/laravel/octane/bin Output: ================ Error
Output: ================ Error: Could not find Chrome (ver.
126.0.6478.63). 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: /root/.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:295: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:89:37)
at async ChromeLauncher.launch
(/var/www/html/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:70:28)
at async callChrome
(/var/www/html/vendor/spatie/browsershot/bin/browser.cjs:92:23)
what shall I do?