Skip to content

Commit

Permalink
feat: add custom debugging port option
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Oct 1, 2019
1 parent fff2737 commit 8802d83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/api.md
Expand Up @@ -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.
Expand Down Expand Up @@ -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`.
Expand Down
6 changes: 5 additions & 1 deletion lib/Launcher.js
Expand Up @@ -235,7 +235,8 @@ class Launcher {
devtools = false,
headless = !devtools,
args = [],
userDataDir = null
userDataDir = null,
debuggingPort = null
} = options;
const chromeArguments = [...DEFAULT_ARGS];
if (userDataDir)
Expand All @@ -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);
Expand Down Expand Up @@ -418,6 +421,7 @@ function getWSEndpoint(browserURL) {
* @property {Array<string>=} args
* @property {string=} userDataDir
* @property {boolean=} devtools
* @property {number=} debuggingPort
*/

/**
Expand Down

0 comments on commit 8802d83

Please sign in to comment.