diff --git a/README.md b/README.md index 4c5e7a501..be44ccaa9 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 + Pass them via the `args` property in the JSON configuration. For example: diff --git a/src/browser.ts b/src/browser.ts index b0a7aaa5a..76fd14f42 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 { - 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 { ...(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.ts index 17b1df633..513fff338 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; 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 yargsInstance diff --git a/src/main.ts b/src/main.ts index fdf185506..ada8cb308 100644 --- a/src/main.ts +++ b/src/main.ts @@ -69,7 +69,7 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => { let context: McpContext; async function getContext(): Promise { - 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 { : 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.ts index 1580825c7..ab46582f0 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'], + }); + }); });