@@ -85,6 +85,44 @@ function cdpUrlForPort(cdpPort: number) {
8585 return `http://127.0.0.1:${ cdpPort } ` ;
8686}
8787
88+ export function buildOpenClawChromeLaunchArgs ( params : {
89+ resolved : ResolvedBrowserConfig ;
90+ profile : ResolvedBrowserProfile ;
91+ userDataDir : string ;
92+ } ) : string [ ] {
93+ const { resolved, profile, userDataDir } = params ;
94+ const args : string [ ] = [
95+ `--remote-debugging-port=${ profile . cdpPort } ` ,
96+ `--user-data-dir=${ userDataDir } ` ,
97+ "--no-first-run" ,
98+ "--no-default-browser-check" ,
99+ "--disable-sync" ,
100+ "--disable-background-networking" ,
101+ "--disable-component-update" ,
102+ "--disable-features=Translate,MediaRouter" ,
103+ "--disable-session-crashed-bubble" ,
104+ "--hide-crash-restore-bubble" ,
105+ "--password-store=basic" ,
106+ ] ;
107+
108+ if ( resolved . headless ) {
109+ args . push ( "--headless=new" ) ;
110+ args . push ( "--disable-gpu" ) ;
111+ }
112+ if ( resolved . noSandbox ) {
113+ args . push ( "--no-sandbox" ) ;
114+ args . push ( "--disable-setuid-sandbox" ) ;
115+ }
116+ if ( process . platform === "linux" ) {
117+ args . push ( "--disable-dev-shm-usage" ) ;
118+ }
119+ if ( resolved . extraArgs . length > 0 ) {
120+ args . push ( ...resolved . extraArgs ) ;
121+ }
122+
123+ return args ;
124+ }
125+
88126async function canOpenWebSocket ( url : string , timeoutMs : number ) : Promise < boolean > {
89127 return new Promise < boolean > ( ( resolve ) => {
90128 const ws = openCdpWebSocket ( url , { handshakeTimeoutMs : timeoutMs } ) ;
@@ -280,41 +318,11 @@ export async function launchOpenClawChrome(
280318
281319 // First launch to create preference files if missing, then decorate and relaunch.
282320 const spawnOnce = ( ) => {
283- const args : string [ ] = [
284- `--remote-debugging-port=${ profile . cdpPort } ` ,
285- `--user-data-dir=${ userDataDir } ` ,
286- "--no-first-run" ,
287- "--no-default-browser-check" ,
288- "--disable-sync" ,
289- "--disable-background-networking" ,
290- "--disable-component-update" ,
291- "--disable-features=Translate,MediaRouter" ,
292- "--disable-session-crashed-bubble" ,
293- "--hide-crash-restore-bubble" ,
294- "--password-store=basic" ,
295- ] ;
296-
297- if ( resolved . headless ) {
298- // Best-effort; older Chromes may ignore.
299- args . push ( "--headless=new" ) ;
300- args . push ( "--disable-gpu" ) ;
301- }
302- if ( resolved . noSandbox ) {
303- args . push ( "--no-sandbox" ) ;
304- args . push ( "--disable-setuid-sandbox" ) ;
305- }
306- if ( process . platform === "linux" ) {
307- args . push ( "--disable-dev-shm-usage" ) ;
308- }
309-
310- // Append user-configured extra arguments (e.g., stealth flags, window size)
311- if ( resolved . extraArgs . length > 0 ) {
312- args . push ( ...resolved . extraArgs ) ;
313- }
314-
315- // Always open a blank tab to ensure a target exists.
316- args . push ( "about:blank" ) ;
317-
321+ const args = buildOpenClawChromeLaunchArgs ( {
322+ resolved,
323+ profile,
324+ userDataDir,
325+ } ) ;
318326 return spawn ( exe . path , args , {
319327 stdio : "pipe" ,
320328 env : {
0 commit comments