I’m trying to get Spatie’s Browsershot to work on a Windows server, but so far with no luck.
I have Node and NPM installed at the latest versions, and I can install Puppeteer (version 19.2.2) with no issues. Browsershot is required in Composer and is called correctly.
According to the configuration page, the default location of the Chromium browser that is downloaded and installed with Puppeteer since version 19.0.0 is ~/.cache/puppeteer. Indeed, when I look in the current user’s folder on the server, this folder exists and contains a subfolder chrome/win64-1056772/chrome-win, in which there is a chrome.exe executable.
However, when I run Browsershot, I get this error message:
Error: Could not find Chromium (rev. 1056772). This can occur if either
1. you did not perform an installation before running the script (e.g. `npm install`) or
2. your cache path is incorrectly configured (which is: C:\Windows\system32\config\systemprofile\.cache\puppeteer).
For (2), check out our guide on configuring puppeteer at https://pptr.dev/guides/configuration.
at ChromeLauncher.resolveExecutablePath (C:\inetpub\vhosts\my_project\app\node_modules\puppeteer-core\lib\cjs\puppeteer\node\ProductLauncher.js:120:27)
at ChromeLauncher.executablePath (C:\inetpub\vhosts\my_project\app\node_modules\puppeteer-core\lib\cjs\puppeteer\node\ChromeLauncher.js:166:25)
at ChromeLauncher.launch (C:\inetpub\vhosts\my_project\app\node_modules\puppeteer-core\lib\cjs\puppeteer\node\ChromeLauncher.js:70:37)
at async callChrome (C:\inetpub\vhosts\my_project\app\vendor\spatie\browsershot\bin\browser.js:84:23)
Note the cache path it gives there: C:\Windows\system32\config\systemprofile\.cache\puppeteer. This folder does not exist, and I’m not even sure if the error message is generating this path dynamically, or if it’s just a static path that hasn’t been updated since the default location was changed in version 19.0.0. I’ve tried copying the entire cache folder into the systemprofile folder, just in case, but this had no effect.
I’ve also tried adding a .puppeteerrc.cjs file in the project root, as well as defining an environmental variable. The config file definitely gets picked up when reinstalling Puppeteer, because I made a typo in it first time around, which caused the installer to fail completely.
I’ve also tried calling Browsershot with a custom Chromium executable path, copy-pasting the absolute path to the executable (or its containing folder).
But nothing works. Puppeteer still cannot find Chromium.
I’m kind of at my wits’ end now. Where can I go from here to figure out where Puppeteer through Browsershot is actually trying to load the executable from – and fix it if it’s trying from the wrong location?