Skip to content
Permalink
Browse files
feat: allow to customize tmpdir (#7243)
  • Loading branch information
Kikobeats committed Sep 23, 2021
1 parent 7341d9f commit b1f6e8692b0bc7e8551b2a78169c830cd80a7acb
Showing with 9 additions and 3 deletions.
  1. +1 −0 docs/api.md
  2. +3 −1 experimental/puppeteer-firefox/lib/Launcher.js
  3. +5 −2 src/node/Launcher.ts
@@ -465,6 +465,7 @@ If Puppeteer doesn't find them in the environment during the installation step,

- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run the browser.
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
- `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).
- `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`.
- `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is Puppeteer's package root.
- `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.
@@ -30,7 +30,9 @@ const WebSocketTransport = require('./WebSocketTransport');
const mkdtempAsync = util.promisify(fs.mkdtemp);
const removeFolderAsync = util.promisify(removeFolder);

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

const FIREFOX_PROFILE_PATH = path.join(tmpDir(), 'puppeteer_firefox_profile-');

const DEFAULT_ARGS = [
'-no-remote',
@@ -31,8 +31,11 @@ import {
ChromeReleaseChannel,
PuppeteerNodeLaunchOptions,
} from './LaunchOptions.js';

import { Product } from '../common/Product.js';

const tmpDir = () => process.env.PUPPETEER_TMP_DIR || os.tmpdir();

/**
* Describes a launcher - a class that is able to create and launch a browser instance.
* @public
@@ -81,7 +84,7 @@ class ChromeLauncher implements ProductLauncher {
waitForInitialPage = true,
} = options;

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

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

0 comments on commit b1f6e86

Please sign in to comment.