From c225b93037c7948607f5bb9b414149c50f0d19e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Thu, 5 Oct 2017 23:34:35 +0200 Subject: [PATCH] feat(Launcher): Allow environment variables definition when launching chromium (#912) This patch adds `env` option to the `puppeteer.launch` method to define custom environment variables to the launched chrome. --- docs/api.md | 1 + lib/Launcher.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 064407264b3c7..e1dce5785c768 100644 --- a/docs/api.md +++ b/docs/api.md @@ -196,6 +196,7 @@ This methods attaches Puppeteer to an existing Chromium instance. - `timeout` <[number]> Maximum time in milliseconds to wait for the Chrome instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - `dumpio` <[boolean]> Whether to pipe browser process stdout and stderr into `process.stdout` and `process.stderr`. Defaults to `false`. - `userDataDir` <[string]> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md). + - `env` <[Object]> Specify environment variables that will be visible to Chromium. Defaults to `process.env`. - returns: <[Promise]<[Browser]>> Promise which resolves to browser instance. The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. diff --git a/lib/Launcher.js b/lib/Launcher.js index dfc5b50c187e2..c906125477b17 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -89,7 +89,14 @@ class Launcher { if (Array.isArray(options.args)) chromeArguments.push(...options.args); - const chromeProcess = childProcess.spawn(chromeExecutable, chromeArguments, {detached: true}); + const chromeProcess = childProcess.spawn( + chromeExecutable, + chromeArguments, + { + detached: true, + env: options.env || process.env + } + ); if (options.dumpio) { chromeProcess.stdout.pipe(process.stdout); chromeProcess.stderr.pipe(process.stderr);