@@ -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 ;
86104const cwd = process . cwd ( ) ;
87105const { env} = process ;
88106const 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.
118148const { 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