Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chrish@diversifiedtechnology.com's avatar

Spatie Laravel PDF

I am using spatie laravel PDF and I understand you need to have the browser shot requirements installed. I have puppeteer installed. When I attempt to run laravel pdf I get the following error:

I cannot figure out what the issue is. If this is a path issue how can I use it so the path is always correct ?

The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=npm root -g node '/home/vagrant/code/vendor/spatie/browsershot/src/../bin/browser.cjs' '{"url":"file:///tmp/1064156310-0386617001709077580/index.html","action":"pdf","options":{"args":[],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"format":"a4","printBackground":true}}'" failed.

Exit Code: 1(General error)

Working directory: /home/vagrant/code/public

Output:

Error Output:

Error: Could not find Chrome (ver. 122.0.6261.69). 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/vagrant/.cache/puppeteer). For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration. at ChromeLauncher.resolveExecutablePath (/home/vagrant/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:285:27) at ChromeLauncher.executablePath (/home/vagrant/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:196:25) at ChromeLauncher.computeLaunchArguments (/home/vagrant/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ChromeLauncher.js:89:37) at async ChromeLauncher.launch (/home/vagrant/code/node_modules/puppeteer-core/lib/cjs/puppeteer/node/ProductLauncher.js:70:28) at async callChrome (/home/vagrant/code/vendor/spatie/browsershot/bin/browser.cjs:91:23)
0 likes
4 replies
LaryAI's avatar
Level 58

It seems like the issue you're encountering is related to the Spatie Browsershot package not being able to find the Chrome executable that Puppeteer uses to generate PDFs. Here are a few steps you can take to resolve this issue:

  1. Ensure Chrome is Installed: First, make sure that Chrome is indeed installed on your system. If you're using Puppeteer, it typically downloads a compatible version of Chromium, but you can also use a system-installed version of Chrome.

  2. Install Chrome with Puppeteer: If you haven't already, you can install Chrome using Puppeteer with the following command:

    npx puppeteer install
    

    This should download Chromium to the default location that Puppeteer expects.

  3. Check Puppeteer Cache Path: The error message suggests that there might be an issue with the cache path configuration. Verify that the path /home/vagrant/.cache/puppeteer exists and is accessible by the user running the Laravel application.

  4. Set the Path to Chrome Manually: If Puppeteer cannot find Chrome automatically, you can specify the path to the Chrome executable manually in your Browsershot call. Here's an example of how to do this:

    use Spatie\Browsershot\Browsershot;
    
    $pathToChrome = '/path/to/google-chrome'; // Replace with the actual path to Chrome
    
    Browsershot::html('Your HTML content')
        ->setChromePath($pathToChrome)
        ->save('example.pdf');
    
  5. Check Permissions: Ensure that the user running the Laravel application has the necessary permissions to execute the Chrome binary.

  6. Debugging: If the issue persists, you can debug by running the command that Browsershot is trying to execute directly in your terminal. This might give you more insight into what's going wrong.

  7. Check Browsershot Documentation: Review the Browsershot documentation and ensure that you're following all the setup instructions correctly.

If you've tried all the above steps and are still facing issues, please provide more details about your environment, such as the operating system, whether you're using Homestead, Docker, or any other specific setup that might affect the execution of Browsershot.

chrish@diversifiedtechnology.com's avatar

I am on a windows machine using homestead and I have vuejs serving the front end

kokoshneta's avatar

Have you seen this question? Which version of Puppeteer are you using?

The only solution I have managed to find is to downgrade to Puppeteer 17.

2 likes

Please or to participate in this conversation.