Skip to content

Commit 34199e7

Browse files
bmeurerDevtools-frontend LUCI CQ
authored andcommitted
[npm] Add profile directory and remote debugging port options.
Teach `npm start` about `--user-data-dir` and `--remote-debugging-port` command line flags for Chrome. Fixed: 416602639 Change-Id: Ib84afc8a6f367561cd1d2ab3a6314a16da2f22e2 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6530461 Reviewed-by: Ergün Erdoğmuş <ergunsh@chromium.org> Auto-Submit: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
1 parent eefe420 commit 34199e7

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

docs/get_the_code.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ npm start -- --disable-features=DevToolsWellKnown --enable-features=DevToolsFree
199199

200200
which you can use to override the default feature set.
201201

202+
##### Remote debugging
203+
204+
The `npm start` command also supports launching Chrome for remote debugging via
205+
206+
```bash
207+
npm start -- --remote-debugging-port=9222
208+
```
209+
210+
or
211+
212+
```bash
213+
npm start -- --browser=canary --remote-debugging-port=9222 --user-data-dir=\`mktemp -d`
214+
```
215+
216+
Note that you have to also pass the `--user-data-dir` and point it to a non-standard profile directory (a freshly created
217+
temporary directory in this example) for security reason when using any Chrome version except for Chrome for Testing.
218+
[This article](https://developer.chrome.com/blog/remote-debugging-port) explains the reasons behind it.
219+
202220
#### Running from file system
203221

204222
This works with Chromium 79 or later.

scripts/run_start.mjs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,42 @@ const argv = yargs(hideBin(process.argv))
6565
default: true,
6666
description: 'Automatically open DevTools for new tabs',
6767
})
68+
.option('remote-debugging-port', {
69+
type: 'number',
70+
description: 'Launch Chrome with the remote debugging port',
71+
})
6872
.option('target', {
6973
alias: 't',
7074
type: 'string',
7175
default: 'Default',
7276
description: 'Specify the target build subdirectory under //out',
7377
})
78+
.option('user-data-dir', {
79+
type: 'string',
80+
description: 'Launch Chrome with the given profile directory',
81+
})
7482
.option('verbose', {
7583
type: 'boolean',
7684
default: false,
7785
description: 'Enable verbose logging',
7886
})
79-
.group(['unstable-features', 'enable-features', 'disable-features'], 'Feature set:')
87+
.group(['unstable-features', 'enable-features', 'disable-features'], 'Feature options:')
8088
.usage('npm start -- [options] [urls...]')
8189
.help('help')
8290
.version(false)
8391
.parseSync();
8492

85-
const {browser, disableFeatures, enableFeatures, unstableFeatures, open, target, verbose} = argv;
93+
const {
94+
browser,
95+
disableFeatures,
96+
enableFeatures,
97+
unstableFeatures,
98+
open,
99+
remoteDebuggingPort,
100+
target,
101+
userDataDir,
102+
verbose,
103+
} = argv;
86104
const cwd = process.cwd();
87105
const {env} = process;
88106
const runBuildPath = path.join(import.meta.dirname, 'run_build.mjs');
@@ -114,6 +132,18 @@ function findBrowserBinary() {
114132
return browser;
115133
}
116134

135+
// The `--remote-debugging-port` command line flag only has an effect in Chrome
136+
// nowadays when used with a non-default data directory, so we fail if the user
137+
// didn't also specify the `--user-data-dir` command line flag. In Chrome for
138+
// Testing the remote debugging port still works with the default profile.
139+
if (remoteDebuggingPort && browser !== 'cft' && !userDataDir) {
140+
console.error(
141+
'The `--remote-debugging-port` command line switch must be accompanied by the `--user-data-dir` switch\n' +
142+
'to point to a non-standard directory. See https://developer.chrome.com/blog/remote-debugging-port for\n' +
143+
'more information.\n');
144+
process.exit(1);
145+
}
146+
117147
// Perform the initial build.
118148
const {status} = childProcess.spawnSync(process.argv[0], [runBuildPath, `--target=${target}`], {
119149
cwd,
@@ -156,6 +186,14 @@ function start() {
156186
}
157187
args.push(...featureSet);
158188

189+
// Custom flags for Chrome.
190+
if (remoteDebuggingPort) {
191+
args.push(`--remote-debugging-port=${remoteDebuggingPort}`);
192+
}
193+
if (userDataDir) {
194+
args.push(`--user-data-dir=${userDataDir}`);
195+
}
196+
159197
// Open with our freshly built DevTools front-end.
160198
const genDir = path.join(rootPath(), 'out', target, 'gen');
161199
const customDevToolsFrontEndPath = isInChromiumDirectory().isInChromium ?

0 commit comments

Comments
 (0)