Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Puppeteer to write to a specific temp folder when using PM2 with a local windows service user?

We are running a Node.js backend on a Windows Server with PM2. For PDF generation we use Puppeteer.

Chromium started with pm2 as Local Service user uses wrong temp folder

Current installation: PM2 is running as Service installed by using pm2-installer https://github.com/jessety/pm2-installer) (using the offline installer, as the target is a windows server without internet). This PM2 starts a node application which starts a puppeteer-Chromium instance. So this Chrome is running with the Local Service user.

Puppeteer is started using a specific userDataDir.

The Problem is now that Puppeteer tries to write to C:\Users\Administrator\AppData\Local\Temp\... where it does not have the permissions to write to as it is not running as Administrator.

Chrome debug log says: Failed to create temporary file

So the questions are:

  • Why is Chrome writing to the Temp folder of the admin and not to a temp folder specific to the Local Service User or to the configured userDataDir (which is used by chrome for other files, so it's correctly configured)?
  • How can I change Chromium to use a Temp folder it has permissions to?
like image 635
Simon Thiel Avatar asked Oct 19 '25 03:10

Simon Thiel


1 Answers

You can configure the temp directory by overriding the PUPPETEER_TMP_DIR environment variable. See their README for more information.

https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#environment-variables

like image 192
Sefa Avatar answered Oct 21 '25 17:10

Sefa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!