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

Ligonsker's avatar

Can't get Spatie Browsershot to work, few different errors

Hello, I am trying to make Spatie Browsershot work on Windows with XAMPP. First of all I installed puppeteer:

npm install -g puppeteer

At first I wanted to output the result directly to the browser, so I had the following code in the controller:

use Spatie\Browsershot\Browsershot;

    public function createPDFWithBrowsershot(Request $request)
    {
        Browsershot::html('<h1>Test</h1>')->pdf();
    }

But then I get the following error:

The command "node ^"C:^\xampp^\htdocs^\my_project^\vendor^\spatie^\browsershot^\src/../bin/browser.js^ ..."

So then I tried to do the following (though not sure it's a good option for Windows, but it did make the above error disappear):

    public function createPDFWithBrowsershot(Request $request)
    {
        Browsershot::html('<h1>Test</h1>')->setNodeBinary('PATH %~dp0;%PATH%;')->pdf();
    }

And the error above disappeared, however the page was blank.

So instead of trying to output the PDF to the browser, I tried to save it as a pdf file:

    public function createPDFWithBrowsershot(Request $request)
    {
        $save_to_file = 'C:/pdfs/file.pdf';
        Browsershot::html('<h1>Test</h1>')->setNodeBinary('PATH %~dp0;%PATH%;')->savePdf($save_to_file);
    }

But I got a new error:

For some reason Chrome did not write a file at C:/pdfs/file.pdf. Command ======= [] Output ======

I also tried several other paths:

 $save_to_file = 'C:\pdfs\file.pdf';

or

$save_to_file = storage_path('pdfs/file.pdf');

But I get the same error.

I even tried uninstalling the global puppeteer and installing it only in my project:

npm install puppeteer

Nothing makes it work

Why?

0 likes
3 replies
LaryAI's avatar
Level 58

It seems like the issue might be related to the path of the Node.js binary. Instead of using the setNodeBinary method, try setting the path to the Node.js binary directly in your system's environment variables.

Here are the steps to do this on Windows:

  1. Open the Start menu and search for "Environment Variables".
  2. Click on "Edit the system environment variables".
  3. Click on the "Environment Variables" button.
  4. Under "System Variables", find the "Path" variable and click "Edit".
  5. Click "New" and add the path to the directory containing the Node.js binary (e.g. C:\Program Files\nodejs).
  6. Click "OK" to close all the windows.

After setting the path, try running the code again without using the setNodeBinary method.

If that doesn't work, try running the code with the no-sandbox option:

Browsershot::html('<h1>Test</h1>')->noSandbox()->pdf();

If none of these solutions work, it might be worth checking the Spatie Browsershot documentation and GitHub issues for any known issues or solutions specific to your setup.

Ligonsker's avatar

C:\Program Files\nodejs is already in system variables Path

lance2k's avatar

Have you fixed yours? my friend on xampp had the same problem.

Please or to participate in this conversation.