From 75bd912f5f339625753268c52eab7c37fb59ebb9 Mon Sep 17 00:00:00 2001 From: Igor Starovierov Date: Sat, 20 Jun 2026 12:21:48 +0000 Subject: [PATCH] fix(cli): apply headless default on implicit daemon auto-start The `chrome-devtools start` command handler defaults headless to true when not explicitly provided, but the implicit auto-start path (triggered transparently when running a tool command like `new_page` with no running daemon) bypassed this logic entirely, inheriting the MCP server's built-in default of headless=false. This caused failures in environments without an X server (e.g., devcontainers, CI). Extract a shared getDefaultedStartArgs() helper that applies the same defaults (`headless: true`, `isolated: true`) for both the explicit `start` command and the implicit auto-start path. --- src/bin/chrome-devtools.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/bin/chrome-devtools.ts b/src/bin/chrome-devtools.ts index cab71cb3a..fefc9d3d9 100644 --- a/src/bin/chrome-devtools.ts +++ b/src/bin/chrome-devtools.ts @@ -39,6 +39,18 @@ async function start(args: string[], sessionId: string) { const defaultArgs = ['--viaCli', '--experimentalStructuredContent']; +function getDefaultedStartArgs( + argv: Record, +): string[] { + if (argv.isolated === undefined && argv.userDataDir === undefined) { + argv.isolated = true; + } + if (argv.headless === undefined) { + argv.headless = true; + } + return serializeArgs(cliOptions, argv); +} + const startCliOptions = { ...cliOptions, } as Partial; @@ -96,13 +108,7 @@ y.command( await stopDaemon(argv.sessionId); } // Defaults but we do not want to affect the yargs conflict resolution. - if (argv.isolated === undefined && argv.userDataDir === undefined) { - argv.isolated = true; - } - if (argv.headless === undefined) { - argv.headless = true; - } - const args = serializeArgs(cliOptions, argv); + const args = getDefaultedStartArgs(argv); await start(args, argv.sessionId); process.exit(0); }, @@ -226,7 +232,8 @@ for (const [commandName, commandDef] of Object.entries(commands)) { const sessionId = argv.sessionId as string; try { if (!isDaemonRunning(sessionId)) { - await start([], sessionId); + const args = getDefaultedStartArgs({}); + await start(args, sessionId); } const commandArgs: Record = {};