mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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.
This commit is contained in:
parent
97e40e6823
commit
c225b93037
@ -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.
|
- `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`.
|
- `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).
|
- `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.
|
- 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.
|
The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed.
|
||||||
|
@ -89,7 +89,14 @@ class Launcher {
|
|||||||
if (Array.isArray(options.args))
|
if (Array.isArray(options.args))
|
||||||
chromeArguments.push(...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) {
|
if (options.dumpio) {
|
||||||
chromeProcess.stdout.pipe(process.stdout);
|
chromeProcess.stdout.pipe(process.stdout);
|
||||||
chromeProcess.stderr.pipe(process.stderr);
|
chromeProcess.stderr.pipe(process.stderr);
|
||||||
|
Loading…
Reference in New Issue
Block a user