feat: allow to customize tmpdir (#7243)

This commit is contained in:
Kiko Beats 2021-09-23 09:26:00 +02:00 committed by GitHub
parent 7341d9fadd
commit b1f6e8692b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -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.

View File

@ -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',

View File

@ -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 = [];