Skip to content

Commit e1b5363

Browse files
authored
feat: support passing args to Chrome (#338)
Drive-by: removes custom devtools frontend as a dedicated argument. Closes #261
1 parent a11df57 commit e1b5363

File tree

5 files changed

+34
-15
lines changed

5 files changed

+34
-15
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ The Chrome DevTools MCP server supports the following configuration option:
291291
If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.
292292
- **Type:** boolean
293293

294+
- **`--chromeArg`**
295+
Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
296+
- **Type:** array
297+
294298
<!-- END AUTO GENERATED OPTIONS -->
295299

296300
Pass them via the `args` property in the JSON configuration. For example:

src/browser.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export async function ensureBrowserConnected(options: {
6060
interface McpLaunchOptions {
6161
acceptInsecureCerts?: boolean;
6262
executablePath?: string;
63-
customDevTools?: string;
6463
channel?: Channel;
6564
userDataDir?: string;
6665
headless: boolean;
@@ -75,7 +74,7 @@ interface McpLaunchOptions {
7574
}
7675

7776
export async function launch(options: McpLaunchOptions): Promise<Browser> {
78-
const {channel, executablePath, customDevTools, headless, isolated} = options;
77+
const {channel, executablePath, headless, isolated} = options;
7978
const profileDirName =
8079
channel && channel !== 'stable'
8180
? `chrome-profile-${channel}`
@@ -98,9 +97,6 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
9897
...(options.args ?? []),
9998
'--hide-crash-restore-bubble',
10099
];
101-
if (customDevTools) {
102-
args.push(`--custom-devtools-frontend=file://${customDevTools}`);
103-
}
104100
if (headless) {
105101
args.push('--screen-info={3840x2160}');
106102
}

src/cli.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,6 @@ export const cliOptions = {
4343
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',
4444
default: false,
4545
},
46-
customDevtools: {
47-
type: 'string',
48-
description: 'Path to custom DevTools.',
49-
hidden: true,
50-
conflicts: 'browserUrl',
51-
alias: 'd',
52-
},
5346
channel: {
5447
type: 'string',
5548
description:
@@ -89,10 +82,15 @@ export const cliOptions = {
8982
description: `If enabled, ignores errors relative to self-signed and expired certificates. Use with caution.`,
9083
},
9184
experimentalDevtools: {
92-
type: 'boolean' as const,
85+
type: 'boolean',
9386
describe: 'Whether to enable automation over DevTools targets',
9487
hidden: true,
9588
},
89+
chromeArg: {
90+
type: 'array',
91+
describe:
92+
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
93+
},
9694
} satisfies Record<string, YargsOptions>;
9795

9896
export function parseArguments(version: string, argv = process.argv) {
@@ -122,6 +120,10 @@ export function parseArguments(version: string, argv = process.argv) {
122120
'$0 --viewport 1280x720',
123121
'Launch Chrome with the initial viewport size of 1280x720px',
124122
],
123+
[
124+
`$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,
125+
'Launch Chrome without sandboxes. Use with caution.',
126+
],
125127
]);
126128

127129
return yargsInstance

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => {
6969

7070
let context: McpContext;
7171
async function getContext(): Promise<McpContext> {
72-
const extraArgs: string[] = [];
72+
const extraArgs: string[] = (args.chromeArg ?? []).map(String);
7373
if (args.proxyServer) {
7474
extraArgs.push(`--proxy-server=${args.proxyServer}`);
7575
}
@@ -82,7 +82,6 @@ async function getContext(): Promise<McpContext> {
8282
: await ensureBrowserLaunched({
8383
headless: args.headless,
8484
executablePath: args.executablePath,
85-
customDevTools: args.customDevtools,
8685
channel: args.channel as Channel,
8786
isolated: args.isolated,
8887
logFile,

tests/cli.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,22 @@ describe('cli args parsing', () => {
9494
},
9595
});
9696
});
97+
98+
it('parses viewport', async () => {
99+
const args = parseArguments('1.0.0', [
100+
'node',
101+
'main.js',
102+
`--chrome-arg='--no-sandbox'`,
103+
`--chrome-arg='--disable-setuid-sandbox'`,
104+
]);
105+
assert.deepStrictEqual(args, {
106+
_: [],
107+
headless: false,
108+
isolated: false,
109+
$0: 'npx chrome-devtools-mcp@latest',
110+
channel: 'stable',
111+
'chrome-arg': ['--no-sandbox', '--disable-setuid-sandbox'],
112+
chromeArg: ['--no-sandbox', '--disable-setuid-sandbox'],
113+
});
114+
});
97115
});

0 commit comments

Comments
 (0)