Skip to content

Chrome DevTools for coding agents

refactor: centralize config defaults and conflict checks (#2753)

Nikolay Vitkova739ba89940a
diff --git a/docs/configuration.md b/docs/configuration.md
index a0a060d5..1e30afbc 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -98,6 +98,7 @@ The Chrome DevTools MCP server supports the following configuration option:
Specify a different Chrome channel that should be used. The default is the stable channel version.
- **Type:** string
- **Choices:** `canary`, `dev`, `beta`, `stable`
+ - **Default:** `stable`
- **`--proxyServer`/ `--proxy-server`**
Proxy server configuration for Chrome passed as --proxy-server when launching the browser. See https://www.chromium.org/developers/design-documents/network-settings/ for details.
@@ -199,6 +200,7 @@ The Chrome DevTools MCP server supports the following configuration option:
Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").
- **Type:** string
- **Choices:** `jpeg`, `png`, `webp`
+ - **Default:** `png`
- **`--screenshotQuality`/ `--screenshot-quality`**
Override the default compression quality (0-100) used by take_screenshot for JPEG and WebP when the caller does not specify one. Lower values mean smaller files. Ignored for PNG. Unset preserves the Puppeteer default.
diff --git a/src/ToolHandler.ts b/src/ToolHandler.ts
index 61115bdc..af4e578c 100644
--- a/src/ToolHandler.ts
+++ b/src/ToolHandler.ts
@@ -7,7 +7,6 @@
import type {ParsedArguments} from './config/mcp-options.js';
import type {McpContext} from './McpContext.js';
import type {McpPage} from './McpPage.js';
-import type {DataFormat} from './McpResponse.js';
import {McpResponse} from './McpResponse.js';
import {SlimMcpResponse} from './SlimMcpResponse.js';
import {ClearcutLogger} from './telemetry/ClearcutLogger.js';
@@ -244,14 +243,11 @@ export class ToolHandler {
}
devToolsData = await context.getDevToolsData(page);
pageUrl = context.getSelectedMcpPageUrl(page);
- // Resolve data format: --experimentalDataFormat takes precedence, fall back to legacy --experimentalToonFormat
- let dataFormat: DataFormat = 'default';
- if (this.serverArgs.experimentalDataFormat) {
- dataFormat = this.serverArgs.experimentalDataFormat as DataFormat;
- } else if (this.serverArgs.experimentalToonFormat) {
- dataFormat = 'toon';
- }
-
+ // --experimentalDataFormat takes precedence over the legacy
+ // --experimentalToonFormat.
+ const dataFormat =
+ this.serverArgs.experimentalDataFormat ??
+ (this.serverArgs.experimentalToonFormat ? 'toon' : 'default');
const {content, structuredContent} = await response.handle(
context,
dataFormat,
diff --git a/src/config/browser-options.ts b/src/config/browser-options.ts
index a1973cab..2b9af492 100644
--- a/src/config/browser-options.ts
+++ b/src/config/browser-options.ts
@@ -11,21 +11,13 @@ export const browserOptions = {
type: 'boolean',
description:
'If specified, automatically connects to a browser (Chrome 144+) running locally from the user data directory identified by the channel param (default channel is stable). Requires the remote debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.',
- conflicts: ['isolated', 'executablePath'],
default: false,
- coerce: (value: boolean | undefined) => {
- if (!value) {
- return;
- }
- return value;
- },
},
browserUrl: {
type: 'string',
description:
'Connect to a running, debuggable Chrome instance (e.g. `http://127.0.0.1:9222`). For more details see: https://github.com/ChromeDevTools/chrome-devtools-mcp/blob/main/docs/advanced-usage.md#connecting-to-a-running-chrome-instance.',
alias: 'u',
- conflicts: ['wsEndpoint'],
coerce: (url: string | undefined) => {
if (!url) {
return;
@@ -43,7 +35,6 @@ export const browserOptions = {
description:
'WebSocket endpoint to connect to a running Chrome instance (e.g., ws://127.0.0.1:9222/devtools/browser/<id>). Alternative to --browserUrl.',
alias: 'w',
- conflicts: ['browserUrl'],
coerce: (url: string | undefined) => {
if (!url) {
return;
@@ -94,26 +85,25 @@ export const browserOptions = {
executablePath: {
type: 'string',
description: 'Path to custom Chrome executable.',
- conflicts: ['browserUrl', 'wsEndpoint'],
alias: 'e',
},
isolated: {
type: 'boolean',
description:
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.',
+ defaultDescription: 'false',
},
userDataDir: {
type: 'string',
description:
'Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE',
- conflicts: ['browserUrl', 'wsEndpoint', 'isolated'],
},
channel: {
type: 'string',
description:
'Specify a different Chrome channel that should be used. The default is the stable channel version.',
choices: ['canary', 'dev', 'beta', 'stable'] as const,
- conflicts: ['browserUrl', 'wsEndpoint', 'executablePath'],
+ defaultDescription: 'stable',
},
proxyServer: {
type: 'string',
diff --git a/src/config/category-options.ts b/src/config/category-options.ts
index d1056261..cbb73cb7 100644
--- a/src/config/category-options.ts
+++ b/src/config/category-options.ts
@@ -10,8 +10,8 @@ export interface CategoryOption {
type: 'boolean';
describe: string;
default?: boolean;
+ defaultDescription?: string;
hidden?: boolean;
- conflicts?: string[];
}
export type CategoryFlagName<T extends ToolCategory = ToolCategory> =
@@ -25,8 +25,7 @@ const categoryOverrides: Record<
ToolCategory,
{
describe?: string;
- hidden?: true;
- conflicts?: string[];
+ hidden?: boolean;
offByDefault?: boolean;
}
> = {
@@ -55,7 +54,6 @@ const categoryOverrides: Record<
[ToolCategory.PWA]: {
describe:
'Set to true to include tools for automating Progressive Web Apps (install, launch, uninstall, and OS state). This feature is only supported with a pipe connection; autoConnect, browserUrl, and wsEndpoint are not supported.',
- conflicts: ['autoConnect', 'browserUrl', 'wsEndpoint'],
offByDefault: true,
},
};
@@ -70,6 +68,9 @@ function createOption(category: ToolCategory): CategoryOption {
type: 'boolean',
describe,
...overrides,
+ // Off-by-default categories have no default so that they stay unset unless
+ // passed explicitly. This keeps them out of conflict checks and lets
+ // --viaCli apply its own categoryExtensions default.
...(overrides.offByDefault ? {} : {default: true}),
};
}
diff --git a/src/config/mcp-options.ts b/src/config/mcp-options.ts
index 0f86c91e..a253639a 100644
--- a/src/config/mcp-options.ts
+++ b/src/config/mcp-options.ts
@@ -45,6 +45,7 @@ export const mcpOptions = {
},
acceptInsecureCerts: {
type: 'boolean',
+ default: false,
description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
},
pageIdRouting: {
@@ -62,10 +63,12 @@ export const mcpOptions = {
},
experimentalDevtools: {
type: 'boolean',
+ default: false,
describe: 'Whether to enable automation over DevTools targets',
},
experimentalVision: {
type: 'boolean',
+ default: false,
describe:
'Whether to enable coordinate-based tools such as click_at(x,y). Usually requires a computer-use model able to produce accurate coordinates by looking at screenshots.',
},
@@ -82,12 +85,14 @@ export const mcpOptions = {
},
experimentalToonFormat: {
type: 'boolean',
+ default: false,
describe:
'Deprecated: use --experimentalDataFormat=toon instead. Whether to format structured data using TOON (requires @toon-format/toon).',
hidden: true,
},
experimentalDataFormat: {
type: 'string',
+ defaultDescription: 'default',
describe:
'Override format for structured data in text responses. Default uses built-in formatters. "toon" (requires @toon-format/toon) or "gcf" (requires @blackwell-systems/gcf) replace structured content with the specified encoding.',
choices: ['default', 'toon', 'gcf'] as const,
@@ -95,16 +100,19 @@ export const mcpOptions = {
},
experimentalIncludeAllPages: {
type: 'boolean',
+ default: false,
describe:
'Whether to include all kinds of pages such as webviews or background pages as pages.',
},
experimentalInteropTools: {
type: 'boolean',
+ default: false,
describe: 'Whether to enable interoperability tools',
hidden: true,
},
experimentalScreencast: {
type: 'boolean',
+ default: false,
describe:
'Exposes experimental screencast tools (requires ffmpeg). Install ffmpeg https://www.ffmpeg.org/download.html and ensure it is available in the MCP server PATH.',
},
@@ -135,7 +143,6 @@ export const mcpOptions = {
string: true,
describe:
"Restricts browser's network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",
- conflicts: ['allowedUrlPattern'],
coerce: (arg: string[] | undefined) => {
if (arg === undefined) {
return undefined;
@@ -154,7 +161,6 @@ export const mcpOptions = {
string: true,
describe:
"Restricts browser's network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Accepts an array of patterns. A pattern that uses a regexp group in any component (for example `(127\\.\\d+\\.\\d+\\.\\d+)` in the hostname) is rejected, because it is not enforced on redirects or subresources; use an exact value or a `*`/`:name` wildcard instead.",
- conflicts: ['blockedUrlPattern'],
coerce: (arg: string[] | undefined) => {
if (arg === undefined) {
return undefined;
@@ -204,11 +210,13 @@ export const mcpOptions = {
},
clearcutIncludePidHeader: {
type: 'boolean',
+ default: false,
hidden: true,
describe: 'Include watchdog PID in Clearcut request headers (for testing).',
},
screenshotFormat: {
type: 'string',
+ default: 'png' as const,
description:
'Override the default output format used by take_screenshot when the caller does not specify one. JPEG and WebP are ~3-5x smaller than PNG, which reduces transfer and storage size. To reduce context size use --screenshotMaxWidth / --screenshotMaxHeight, since image tokens scale with dimensions rather than encoded bytes. Unset preserves the existing default ("png").',
choices: ['jpeg', 'png', 'webp'] as const,
@@ -263,11 +271,13 @@ export const mcpOptions = {
},
slim: {
type: 'boolean',
+ default: false,
describe:
'Exposes a "slim" set of 3 tools covering navigation, script execution and screenshots only. Useful for basic browser tasks.',
},
viaCli: {
type: 'boolean',
+ default: false,
describe:
'Set by Chrome DevTools CLI if the MCP server is started via the CLI client (this arg exists for usage stats)',
hidden: true,
@@ -320,9 +330,6 @@ export function getMcpOptionsForViaCli(): typeof mcpOptions {
'experimentalStructuredContent cli option unexpectedly does not have a default',
);
}
- if ('default' in mcpOptions.isolated) {
- throw new Error('isolated cli option unexpectedly has a default');
- }
return {
...mcpOptions,
@@ -336,7 +343,8 @@ export function getMcpOptionsForViaCli(): typeof mcpOptions {
},
categoryExtensions: {
...mcpOptions.categoryExtensions,
- default: true,
+ defaultDescription:
+ 'true unless autoConnect, browserUrl or wsEndpoint is set',
},
experimentalStructuredContent: {
...mcpOptions.experimentalStructuredContent,
@@ -346,6 +354,8 @@ export function getMcpOptionsForViaCli(): typeof mcpOptions {
...mcpOptions.isolated,
description:
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.',
+ defaultDescription:
+ 'true unless userDataDir, autoConnect, browserUrl or wsEndpoint is set',
},
};
}
@@ -399,6 +409,42 @@ export function parser(
})
.options(options)
.showHelpOnFail(false, 'Specify --help for available options')
+ .check(args => {
+ const activeArgs = new Set<string>();
+
+ for (const [key, val] of Object.entries(args)) {
+ if (val !== undefined && val !== false) {
+ activeArgs.add(key);
+ }
+ }
+
+ const CONFLICTS: Array<Array<keyof typeof mcpOptions>> = [
+ ['channel', 'executablePath', 'browserUrl', 'wsEndpoint'],
+ ['userDataDir', 'browserUrl', 'wsEndpoint'],
+ ['userDataDir', 'isolated'],
+ ['autoConnect', 'isolated'],
+ ['autoConnect', 'executablePath'],
+ ['blockedUrlPattern', 'allowedUrlPattern'],
+ ['categoryPwa', 'autoConnect'],
+ ['categoryPwa', 'browserUrl', 'wsEndpoint'],
+ ['categoryExtensions', 'autoConnect'],
+ ['categoryExtensions', 'browserUrl', 'wsEndpoint'],
+ ];
+
+ for (const group of CONFLICTS) {
+ // Find all active arguments within this conflict group
+ const activeInGroup = group.filter(arg => activeArgs.has(arg));
+
+ if (activeInGroup.length > 1) {
+ const [arg1, arg2] = activeInGroup;
+ throw new Error(
+ `Arguments ${arg1} and ${arg2} are mutually exclusive`,
+ );
+ }
+ }
+
+ return true;
+ })
.middleware(args => {
if (isViaCli) {
if (args.filesystemRoot === DEFAULT_FILESYSTEM_ROOT) {
@@ -410,18 +456,25 @@ export function parser(
cliFilesystemArgs.filesystemRoot = undefined;
}
// Defaults that cannot be set in options without affecting yargs conflict resolution.
+ const connectsToExistingBrowser =
+ args.autoConnect || args.browserUrl || args.wsEndpoint;
if (
args.isolated === undefined &&
args.userDataDir === undefined &&
- !args.autoConnect &&
- !args.browserUrl &&
- !args.wsEndpoint
+ !connectsToExistingBrowser
) {
args.isolated = true;
}
+ if (
+ args.categoryExtensions === undefined &&
+ !connectsToExistingBrowser
+ ) {
+ args.categoryExtensions = true;
+ }
}
- // We can't set default in the options else
- // Yargs will complain
+ // Only fall back to stable when Chrome is launched by channel. Leaving it
+ // unset otherwise keeps it out of telemetry (computeFlagUsage) for
+ // browserUrl, wsEndpoint and executablePath.
if (
!args.channel &&
!args.browserUrl &&
diff --git a/tests/ToolHandler.test.ts b/tests/ToolHandler.test.ts
index a0393b49..9013cea1 100644
--- a/tests/ToolHandler.test.ts
+++ b/tests/ToolHandler.test.ts
@@ -15,6 +15,7 @@ import sinon from 'sinon';
import {parseArguments} from '../src/config/mcp-options.js';
import {McpContext} from '../src/McpContext.js';
import {McpPage} from '../src/McpPage.js';
+import {McpResponse, type DataFormat} from '../src/McpResponse.js';
import {ClearcutLogger} from '../src/telemetry/ClearcutLogger.js';
import {zod} from '../src/third_party/index.js';
import {ToolHandler} from '../src/ToolHandler.js';
@@ -167,6 +168,57 @@ describe('ToolHandler', () => {
assert.strictEqual(result.isError, undefined);
});
+ const dataFormatCases: Array<{argv: string[]; expected: DataFormat}> = [
+ {argv: [], expected: 'default'},
+ {argv: ['--experimentalToonFormat'], expected: 'toon'},
+ {argv: ['--experimentalDataFormat=gcf'], expected: 'gcf'},
+ {
+ argv: ['--experimentalToonFormat', '--experimentalDataFormat=default'],
+ expected: 'default',
+ },
+ {
+ argv: ['--experimentalToonFormat', '--experimentalDataFormat=gcf'],
+ expected: 'gcf',
+ },
+ ];
+ for (const {argv, expected} of dataFormatCases) {
+ it(`resolves data format ${expected} from [${argv.join(' ')}]`, async () => {
+ const tool: ToolDefinition = {
+ name: 'global_tool',
+ description: 'A global tool',
+ annotations: {
+ category: ToolCategory.NAVIGATION,
+ readOnlyHint: true,
+ },
+ schema: {},
+ blockedByDialog: false,
+ verifyFilesSchema: {},
+ handler: async () => undefined,
+ };
+ const mockContext = sinon.createStubInstance(McpContext);
+ mockContext.browser = getMockBrowser({
+ process: sinon.createStubInstance(ChildProcess),
+ });
+ const handleStub = sinon
+ .stub(McpResponse.prototype, 'handle')
+ .resolves({content: [], structuredContent: {}});
+ const serverArgs = parseArguments(
+ '1.0.0',
+ ['node', 'script.js', ...argv],
+ {CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: 'true'},
+ );
+
+ await new ToolHandler(
+ tool,
+ serverArgs,
+ async () => mockContext,
+ new Mutex(),
+ ).handle({});
+
+ sinon.assert.calledOnceWithExactly(handleStub, mockContext, expected);
+ });
+ }
+
it('passes devToolsData and pageUrl to logger', async () => {
const baseTool: ToolDefinition = {
name: 'test_tool',
diff --git a/tests/browser.test.ts b/tests/browser.test.ts
index c1e8a566..9d3a5272 100644
--- a/tests/browser.test.ts
+++ b/tests/browser.test.ts
@@ -103,6 +103,25 @@ describe('browser', () => {
sinon.assert.notCalled(pptrBrowser.disconnect);
});
+ it('does not pass a channel to Puppeteer when executablePath is set', async () => {
+ const pptrBrowser = createMockPuppeteerBrowser();
+ const launchStub = sinon.stub(puppeteer, 'launch').resolves(pptrBrowser);
+
+ const args = createMockParsedArguments({
+ isolated: true,
+ channel: 'stable',
+ executablePath: '/path/to/chrome',
+ });
+ const manager = new BrowserManager(args);
+
+ await manager.ensureBrowser();
+
+ sinon.assert.calledOnceWithMatch(launchStub, {
+ channel: undefined,
+ executablePath: '/path/to/chrome',
+ });
+ });
+
it('connects to a browser when browserUrl is set and disconnects on close()', async () => {
const pptrBrowser = createMockPuppeteerBrowser();
const launchStub = sinon.stub(puppeteer, 'launch');
diff --git a/tests/cli.test.ts b/tests/cli.test.ts
index 2dcafe87..7d63b7bf 100644
--- a/tests/cli.test.ts
+++ b/tests/cli.test.ts
@@ -16,6 +16,7 @@ import {
mcpOptions,
parser,
} from '../src/config/mcp-options.js';
+import {computeFlagUsage} from '../src/telemetry/flagUtils.js';
import {createTempFile} from './utils.js';
@@ -34,17 +35,29 @@ describe('cli args parsing', () => {
categoryNetwork: true,
categoryDebugging: true,
categoryMemory: true,
- autoConnect: undefined,
+ autoConnect: false,
+ headless: false,
+ acceptInsecureCerts: false,
performanceCrux: true,
usageStatistics: true,
javascriptEvaluation: true,
redactNetworkHeaders: false,
allowUnrestrictedPaths: false,
filesystemRoot: DEFAULT_FILESYSTEM_ROOT,
+ experimentalDevtools: false,
+ experimentalVision: false,
+ experimentalToonFormat: false,
+ experimentalIncludeAllPages: false,
+ experimentalInteropTools: false,
+ experimentalScreencast: false,
memoryDebugging: false,
experimentalStructuredContent: false,
pageIdRouting: true,
sourceMaps: true,
+ clearcutIncludePidHeader: false,
+ screenshotFormat: 'png',
+ slim: false,
+ viaCli: false,
devtoolsComments: false,
};
@@ -53,7 +66,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
});
@@ -75,7 +87,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
browserUrl: 'http://localhost:3000',
});
@@ -106,7 +117,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
userDataDir: '/tmp/chrome-profile',
@@ -118,10 +128,9 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
- browserUrl: undefined,
channel: 'stable',
+ browserUrl: undefined,
});
});
@@ -130,7 +139,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
executablePath: '/tmp/test 123/chrome',
});
@@ -141,7 +149,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
viewport: {
@@ -159,7 +166,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
chromeArg: ['--no-sandbox', '--disable-setuid-sandbox'],
@@ -214,7 +220,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
ignoreDefaultChromeArg: [
@@ -232,7 +237,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
wsEndpoint: 'ws://127.0.0.1:9222/devtools/browser/abc123',
});
@@ -246,7 +250,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
wsEndpoint: 'wss://example.com:9222/devtools/browser/abc123',
});
@@ -270,7 +273,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
categoryEmulation: false,
@@ -281,7 +283,6 @@ describe('cli args parsing', () => {
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
- headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
autoConnect: true,
@@ -629,6 +630,282 @@ describe('cli args parsing', () => {
cliOptions.filesystemRoot?.defaultDescription,
'OS temp directory',
);
+ assert.strictEqual(
+ cliOptions.isolated?.defaultDescription,
+ 'true unless userDataDir, autoConnect, browserUrl or wsEndpoint is set',
+ );
+ assert.strictEqual(
+ cliOptions.categoryExtensions?.defaultDescription,
+ 'true unless autoConnect, browserUrl or wsEndpoint is set',
+ );
+ });
+
+ describe('mutual exclusivity', () => {
+ it('rejects isolated with userDataDir', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--isolated',
+ '--user-data-dir',
+ '/tmp/chrome-profile',
+ ]),
+ /Arguments userDataDir and isolated are mutually exclusive/,
+ );
+ });
+
+ it('rejects isolated with autoConnect', async () => {
+ assert.throws(
+ () => parseArguments(['--isolated', '--auto-connect']),
+ /Arguments autoConnect and isolated are mutually exclusive/,
+ );
+ });
+
+ it('rejects autoConnect with executablePath', async () => {
+ assert.throws(
+ () =>
+ parseArguments(['--auto-connect', '--executablePath', '/bin/chrome']),
+ /Arguments autoConnect and executablePath are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryPwa with autoConnect', async () => {
+ assert.throws(
+ () => parseArguments(['--category-pwa', '--auto-connect']),
+ /Arguments categoryPwa and autoConnect are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryPwa with browserUrl', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--category-pwa',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments categoryPwa and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryPwa with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--category-pwa',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments categoryPwa and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ it('rejects explicit channel with browserUrl', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--channel=canary',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments channel and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects explicit channel with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--channel',
+ 'canary',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments channel and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ it('rejects explicit channel with executablePath', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--channel',
+ 'canary',
+ '--executablePath',
+ '/bin/chrome',
+ ]),
+ /Arguments channel and executablePath are mutually exclusive/,
+ );
+ });
+
+ it('rejects browserUrl with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--browserUrl',
+ 'http://localhost:9222',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments browserUrl and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ it('rejects executablePath with browserUrl', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--executablePath',
+ '/bin/chrome',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments executablePath and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects executablePath with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--executablePath',
+ '/bin/chrome',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments executablePath and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ it('rejects userDataDir with browserUrl', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--user-data-dir',
+ '/tmp/dir',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments userDataDir and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects userDataDir with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--user-data-dir',
+ '/tmp/dir',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments userDataDir and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ it('rejects blockedUrlPattern with allowedUrlPattern', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--blocked-url-pattern',
+ 'https://a.com/*',
+ '--allowed-url-pattern',
+ 'https://a.com/*',
+ ]),
+ /Arguments blockedUrlPattern and allowedUrlPattern are mutually exclusive/,
+ );
+ });
+
+ it('rejects config-based channel with browserUrl', async () => {
+ using testConfig = createTempFile(
+ JSON.stringify({channel: 'canary'}),
+ 'cd4a.test.config.channel.json',
+ );
+ assert.throws(
+ () =>
+ parseArguments([
+ '--config',
+ testConfig.path,
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments channel and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryExtensions with autoConnect', async () => {
+ assert.throws(
+ () => parseArguments(['--category-extensions', '--auto-connect']),
+ /Arguments categoryExtensions and autoConnect are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryExtensions with browserUrl', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--category-extensions',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments categoryExtensions and browserUrl are mutually exclusive/,
+ );
+ });
+
+ it('rejects categoryExtensions with wsEndpoint', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--category-extensions',
+ '--wsEndpoint',
+ 'ws://localhost:9222',
+ ]),
+ /Arguments categoryExtensions and wsEndpoint are mutually exclusive/,
+ );
+ });
+
+ for (const connectArgs of [
+ ['--browserUrl', 'http://localhost:9222'],
+ ['--wsEndpoint', 'ws://localhost:9222'],
+ ['--executablePath', '/tmp/chrome'],
+ ]) {
+ it(`does not default channel with ${connectArgs[0]}`, async () => {
+ const args = parseArguments(connectArgs);
+ assert.strictEqual(args.channel, undefined);
+ });
+ }
+
+ for (const connectArgs of [
+ ['--browserUrl', 'http://localhost:9222'],
+ ['--wsEndpoint', 'ws://localhost:9222'],
+ ['--auto-connect'],
+ ]) {
+ it(`allows viaCli with ${connectArgs[0]} without enabling extensions`, async () => {
+ const args = parseArguments(['--viaCli', ...connectArgs]);
+ assert.strictEqual(args.categoryExtensions, undefined);
+ assert.strictEqual(args.isolated, undefined);
+ });
+ }
+
+ it('rejects explicit categoryExtensions with browserUrl in viaCli', async () => {
+ assert.throws(
+ () =>
+ parseArguments([
+ '--viaCli',
+ '--category-extensions',
+ '--browserUrl',
+ 'http://localhost:9222',
+ ]),
+ /Arguments categoryExtensions and browserUrl are mutually exclusive/,
+ );
+ });
+ });
+
+ describe('dataFormat', () => {
+ it('keeps experimentalToonFormat and experimentalDataFormat separate', () => {
+ const args = parseArguments(['--experimentalToonFormat']);
+ assert.strictEqual(args.experimentalToonFormat, true);
+ assert.strictEqual(args.experimentalDataFormat, undefined);
+ });
});
});
@@ -694,3 +971,35 @@ describe('cli command strings', () => {
}
});
});
+
+describe('flag usage telemetry', () => {
+ it('reports the stable channel for a default launch', async () => {
+ const usage = computeFlagUsage(parseArguments([]), mcpOptions);
+ assert.strictEqual(usage.isolated_present, false);
+ assert.strictEqual(usage.channel_present, true);
+ assert.strictEqual(usage.channel, 'CHANNEL_STABLE');
+ });
+
+ for (const connectArgs of [
+ ['--browserUrl', 'http://localhost:9222'],
+ ['--wsEndpoint', 'ws://localhost:9222'],
+ ['--executablePath', '/tmp/chrome'],
+ ]) {
+ it(`does not report channel with ${connectArgs[0]}`, async () => {
+ const usage = computeFlagUsage(parseArguments(connectArgs), mcpOptions);
+ assert.strictEqual(usage.isolated_present, false);
+ assert.strictEqual(usage.channel_present, false);
+ assert.strictEqual(usage.channel, undefined);
+ });
+ }
+
+ it('does not report experimentalDataFormat for legacy experimentalToonFormat', async () => {
+ const usage = computeFlagUsage(
+ parseArguments(['--experimentalToonFormat']),
+ mcpOptions,
+ );
+ assert.strictEqual(usage.experimental_toon_format, true);
+ assert.strictEqual(usage.experimental_data_format_present, false);
+ assert.strictEqual(usage.experimental_data_format, undefined);
+ });
+});