Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom debugging port option #4993

Merged
merged 5 commits into from Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the documentation, you stated that passing 0 for the debuggingPort will assign a random port but I think this if clause will prevent that from happening.

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