3

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?
Simon Thiel
  • 2,888
  • 6
  • 24
  • 46

3 Answers3

1

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

Sefa
  • 103
  • 1
  • 10
0

You can change your puppeteer download path with await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './mydownloadfolder'});

Brewha
  • 66
  • 2
  • 3
0

Puppeteer looks for certain environment variables to aid its operations. If Puppeteer doesn't find them in the environment during the installation step, a lowercased variant of these variables will be used from the npm config.

Set below environment variable

PUPPETEER_TMP_DIR - defines the directory to be used by Puppeteer for creating temporary files. Defaults to os.tmpdir()

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

Prasanth Jaya
  • 4,407
  • 2
  • 23
  • 33