From b1f6e8692b0bc7e8551b2a78169c830cd80a7acb Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Thu, 23 Sep 2021 09:26:00 +0200 Subject: [PATCH] feat: allow to customize tmpdir (#7243) --- docs/api.md | 1 + experimental/puppeteer-firefox/lib/Launcher.js | 4 +++- src/node/Launcher.ts | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 53eca17b1694a..2996a1e874882 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 `/.local-chromium`, where `` 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. diff --git a/experimental/puppeteer-firefox/lib/Launcher.js b/experimental/puppeteer-firefox/lib/Launcher.js index 77a8a7186af8c..85b2e9a359890 100644 --- a/experimental/puppeteer-firefox/lib/Launcher.js +++ b/experimental/puppeteer-firefox/lib/Launcher.js @@ -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', diff --git a/src/node/Launcher.ts b/src/node/Launcher.ts index 402ae0ad0d7f1..27f3e1f2af0de 100644 --- a/src/node/Launcher.ts +++ b/src/node/Launcher.ts @@ -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 { const profilePath = await mkdtempAsync( - path.join(os.tmpdir(), 'puppeteer_dev_firefox_profile-') + path.join(tmpDir(), 'puppeteer_dev_firefox_profile-') ); const prefsJS = []; const userJS = [];