Chrome DevTools for coding agents
feat: support passing args to Chrome (#338)
Alex Rudenkoe1b536365363
diff --git a/README.md b/README.mdindex 4c5e7a50..be44ccaa 100644--- a/README.md+++ b/README.md@@ -291,6 +291,10 @@ The Chrome DevTools MCP server supports the following configuration option:If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.- **Type:** boolean+- **`--chromeArg`**+ Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.+ - **Type:** array+<!-- END AUTO GENERATED OPTIONS -->Pass them via the `args` property in the JSON configuration. For example:diff --git a/src/browser.ts b/src/browser.tsindex b0a7aaa5..76fd14f4 100644--- a/src/browser.ts+++ b/src/browser.ts@@ -60,7 +60,6 @@ export async function ensureBrowserConnected(options: {interface McpLaunchOptions {acceptInsecureCerts?: boolean;executablePath?: string;- customDevTools?: string;channel?: Channel;userDataDir?: string;headless: boolean;@@ -75,7 +74,7 @@ interface McpLaunchOptions {}export async function launch(options: McpLaunchOptions): Promise<Browser> {- const {channel, executablePath, customDevTools, headless, isolated} = options;+ const {channel, executablePath, headless, isolated} = options;const profileDirName =channel && channel !== 'stable'? `chrome-profile-${channel}`@@ -98,9 +97,6 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {...(options.args ?? []),'--hide-crash-restore-bubble',];- if (customDevTools) {- args.push(`--custom-devtools-frontend=file://${customDevTools}`);- }if (headless) {args.push('--screen-info={3840x2160}');}diff --git a/src/cli.ts b/src/cli.tsindex 17b1df63..513fff33 100644--- a/src/cli.ts+++ b/src/cli.ts@@ -43,13 +43,6 @@ export const cliOptions = {'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',default: false,},- customDevtools: {- type: 'string',- description: 'Path to custom DevTools.',- hidden: true,- conflicts: 'browserUrl',- alias: 'd',- },channel: {type: 'string',description:@@ -89,10 +82,15 @@ export const cliOptions = {description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,},experimentalDevtools: {- type: 'boolean' as const,+ type: 'boolean',describe: 'Whether to enable automation over DevTools targets',hidden: true,},+ chromeArg: {+ type: 'array',+ describe:+ 'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',+ },} satisfies Record<string, YargsOptions>;export function parseArguments(version: string, argv = process.argv) {@@ -122,6 +120,10 @@ export function parseArguments(version: string, argv = process.argv) {'$0 --viewport 1280x720','Launch Chrome with the initial viewport size of 1280x720px',],+ [+ `$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,+ 'Launch Chrome without sandboxes. Use with caution.',+ ],]);return yargsInstancediff --git a/src/main.ts b/src/main.tsindex fdf18550..ada8cb30 100644--- a/src/main.ts+++ b/src/main.ts@@ -69,7 +69,7 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => {let context: McpContext;async function getContext(): Promise<McpContext> {- const extraArgs: string[] = [];+ const extraArgs: string[] = (args.chromeArg ?? []).map(String);if (args.proxyServer) {extraArgs.push(`--proxy-server=${args.proxyServer}`);}@@ -82,7 +82,6 @@ async function getContext(): Promise<McpContext> {: await ensureBrowserLaunched({headless: args.headless,executablePath: args.executablePath,- customDevTools: args.customDevtools,channel: args.channel as Channel,isolated: args.isolated,logFile,diff --git a/tests/cli.test.ts b/tests/cli.test.tsindex 1580825c..ab46582f 100644--- a/tests/cli.test.ts+++ b/tests/cli.test.ts@@ -94,4 +94,22 @@ describe('cli args parsing', () => {},});});++ it('parses viewport', async () => {+ const args = parseArguments('1.0.0', [+ 'node',+ 'main.js',+ `--chrome-arg='--no-sandbox'`,+ `--chrome-arg='--disable-setuid-sandbox'`,+ ]);+ assert.deepStrictEqual(args, {+ _: [],+ headless: false,+ isolated: false,+ $0: 'npx chrome-devtools-mcp@latest',+ channel: 'stable',+ 'chrome-arg': ['--no-sandbox', '--disable-setuid-sandbox'],+ chromeArg: ['--no-sandbox', '--disable-setuid-sandbox'],+ });+ });});