Skip to content

Commit b1f6e86

Browse files
authored
feat: allow to customize tmpdir (#7243)
1 parent 7341d9f commit b1f6e86

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

docs/api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ If Puppeteer doesn't find them in the environment during the installation step,
465465

466466
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run the browser.
467467
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
468+
- `PUPPETEER_TMP_DIR` - defines the directory to be used by Puppeteer for creating temporary files. Defaults to [`os.tmpdir()`](https://nodejs.org/api/os.html#os_os_tmpdir).
468469
- `PUPPETEER_DOWNLOAD_HOST` - overwrite URL prefix that is used to download Chromium. Note: this includes protocol and might even include path prefix. Defaults to `https://storage.googleapis.com`.
469470
- `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is Puppeteer's package root.
470471
- `PUPPETEER_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Puppeteer to use. See [puppeteer.launch([options])](#puppeteerlaunchoptions) on how executable path is inferred. **BEWARE**: Puppeteer is only [guaranteed to work](https://github.com/puppeteer/puppeteer/#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.

experimental/puppeteer-firefox/lib/Launcher.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const WebSocketTransport = require('./WebSocketTransport');
3030
const mkdtempAsync = util.promisify(fs.mkdtemp);
3131
const removeFolderAsync = util.promisify(removeFolder);
3232

33-
const FIREFOX_PROFILE_PATH = path.join(os.tmpdir(), 'puppeteer_firefox_profile-');
33+
const tmpDir = () => process.env.PUPPETEER_TMP_DIR || os.tmpdir();
34+
35+
const FIREFOX_PROFILE_PATH = path.join(tmpDir(), 'puppeteer_firefox_profile-');
3436

3537
const DEFAULT_ARGS = [
3638
'-no-remote',

src/node/Launcher.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ import {
3131
ChromeReleaseChannel,
3232
PuppeteerNodeLaunchOptions,
3333
} from './LaunchOptions.js';
34+
3435
import { Product } from '../common/Product.js';
3536

37+
const tmpDir = () => process.env.PUPPETEER_TMP_DIR || os.tmpdir();
38+
3639
/**
3740
* Describes a launcher - a class that is able to create and launch a browser instance.
3841
* @public
@@ -81,7 +84,7 @@ class ChromeLauncher implements ProductLauncher {
8184
waitForInitialPage = true,
8285
} = options;
8386

84-
const profilePath = path.join(os.tmpdir(), 'puppeteer_dev_chrome_profile-');
87+
const profilePath = path.join(tmpDir(), 'puppeteer_dev_chrome_profile-');
8588
const chromeArguments = [];
8689
if (!ignoreDefaultArgs) chromeArguments.push(...this.defaultArgs(options));
8790
else if (Array.isArray(ignoreDefaultArgs))
@@ -385,7 +388,7 @@ class FirefoxLauncher implements ProductLauncher {
385388

386389
async _createProfile(extraPrefs: { [x: string]: unknown }): Promise<string> {
387390
const profilePath = await mkdtempAsync(
388-
path.join(os.tmpdir(), 'puppeteer_dev_firefox_profile-')
391+
path.join(tmpDir(), 'puppeteer_dev_firefox_profile-')
389392
);
390393
const prefsJS = [];
391394
const userJS = [];

0 commit comments

Comments
 (0)