-2

Im using Laravel 10 with laravel spatie browsershot to take a screenshot of a specific url in my website and transform it into a pdf file. All is working fine on my locale machine. After pulling on the live server which is a ubuntu server, i test the function on tinker as the root user and it works fine. But when i access the website from my browser and clicking the button that generates the pdf im getting the following error:

Error: Failed to launch the browser process! cmd_run.go:1046: WARNING: cannot create user data directory: cannot create snap home dir: mkdir /var/www/snap: permission denied /system.slice/php8.1-fpm.service is not a snap cgroup TROUBLESHOOTING: https://pptr.dev/troubleshooting at Interface.onClose (/var/www/mywebsite/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24) at Interface.emit (node:events:525:35) at Interface.close (node:internal/readline/interface:536:10) at Socket.onend (node:internal/readline/interface:262:10) at Socket.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1359:12) at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

how can i fix the permissions? i tried setting the www directory with root:www-data and still no fix.

  • Does this answer your question? [How do I change permissions for a folder and its subfolders/files?](https://stackoverflow.com/questions/3740152/how-do-i-change-permissions-for-a-folder-and-its-subfolders-files) – N69S Apr 26 '23 at 14:33
  • Is this a dockerized app ? – jurandou Apr 27 '23 at 07:13

1 Answers1

1

You can manually set path of your user data directory mentioned in the documentation. https://spatie.be/docs/browsershot/v2/usage/creating-images

and check once the permission of your folder, in this case it is /tmp/session-1.

$image = Browsershot::url('https://example.com')
    ->userDataDir('/tmp/session-1')

Also there are some issue with puppeteer version I have personally faced like opening browser in headless mode, so try some other versions as I switched my version to 17 after facing issue from version 19 and installed version 17 using below command.

$ npm install peppeteer@17.1.3
Zafeer Ahmad
  • 240
  • 5
  • 17