Skip to content

Commit

Permalink
feat: allow to customize tmpdir (#7243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Sep 23, 2021
1 parent 7341d9f commit b1f6e86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion experimental/puppeteer-firefox/lib/Launcher.js
Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions src/node/Launcher.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 = [];
Expand Down

0 comments on commit b1f6e86

Please sign in to comment.