From 8802d83d6eca3d00d98dde634f080f4fa1d25c1e Mon Sep 17 00:00:00 2001 From: Li Hau Tan Date: Tue, 1 Oct 2019 12:24:10 +0800 Subject: [PATCH] feat: add custom debugging port option --- docs/api.md | 2 ++ lib/Launcher.js | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index b1b200481a76c..0b2ebf5c431a9 100644 --- a/docs/api.md +++ b/docs/api.md @@ -462,6 +462,7 @@ This methods attaches Puppeteer to an existing Chromium instance. - `args` <[Array]<[string]>> Additional arguments to pass to the browser instance. The list of Chromium flags can be found [here](http://peter.sh/experiments/chromium-command-line-switches/). - `userDataDir` <[string]> Path to a [User Data Directory](https://chromium.googlesource.com/chromium/src/+/master/docs/user_data_dir.md). - `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. + - `debuggingPort` <[number]> Specify custom debugging port. Pass `0` to discover a random port. Defaults to `0`. - returns: <[Array]<[string]>> The default flags that Chromium will be launched with. @@ -537,6 +538,7 @@ try { - `timeout` <[number]> Maximum time in milliseconds to wait for the browser instance to start. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. - `dumpio` <[boolean]> Whether to pipe the 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). + - `debuggingPort` <[number]> Specify custom debugging port. Pass `0` to discover a random port. Defaults to `0`. - `env` <[Object]> Specify environment variables that will be visible to the browser. Defaults to `process.env`. - `devtools` <[boolean]> Whether to auto-open a DevTools panel for each tab. If this option is `true`, the `headless` option will be set `false`. - `pipe` <[boolean]> Connects to the browser over a pipe instead of a WebSocket. Defaults to `false`. diff --git a/lib/Launcher.js b/lib/Launcher.js index c5060f7ae691b..22e0b5da52ba1 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -235,7 +235,8 @@ class Launcher { devtools = false, headless = !devtools, args = [], - userDataDir = null + userDataDir = null, + debuggingPort = null } = options; const chromeArguments = [...DEFAULT_ARGS]; if (userDataDir) @@ -249,6 +250,8 @@ class Launcher { '--mute-audio' ); } + if (debuggingPort) + chromeArguments.push(`--remote-debugging-port=${debuggingPort}`); if (args.every(arg => arg.startsWith('-'))) chromeArguments.push('about:blank'); chromeArguments.push(...args); @@ -418,6 +421,7 @@ function getWSEndpoint(browserURL) { * @property {Array=} args * @property {string=} userDataDir * @property {boolean=} devtools + * @property {number=} debuggingPort */ /**