Skip to content

Commit ffa844a

Browse files
committed
feat: support passing args to Chrome
1 parent 2982195 commit ffa844a

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ 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+
- **Default:** ``
298+
294299
<!-- END AUTO GENERATED OPTIONS -->
295300

296301
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: 11 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,16 @@ 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+
default: [],
94+
},
9695
} satisfies Record<string, YargsOptions>;
9796

9897
export function parseArguments(version: string, argv = process.argv) {
@@ -122,6 +121,10 @@ export function parseArguments(version: string, argv = process.argv) {
122121
'$0 --viewport 1280x720',
123122
'Launch Chrome with the initial viewport size of 1280x720px',
124123
],
124+
[
125+
`$0 --chrome-args='--no-sandbox' --chrome-args='--disable-setuid-sandbox'`,
126+
'Launch Chrome without sandboxes. Use with caution.',
127+
],
125128
]);
126129

127130
return yargsInstance

src/main.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ describe('cli args parsing', () => {
1717
isolated: false,
1818
$0: 'npx chrome-devtools-mcp@latest',
1919
channel: 'stable',
20+
'chrome-arg': [],
21+
chromeArg: [],
2022
});
2123
});
2224

@@ -35,6 +37,8 @@ describe('cli args parsing', () => {
3537
'browser-url': 'http://localhost:3000',
3638
browserUrl: 'http://localhost:3000',
3739
u: 'http://localhost:3000',
40+
'chrome-arg': [],
41+
chromeArg: [],
3842
});
3943
});
4044

@@ -54,6 +58,8 @@ describe('cli args parsing', () => {
5458
browserUrl: undefined,
5559
u: undefined,
5660
channel: 'stable',
61+
'chrome-arg': [],
62+
chromeArg: [],
5763
});
5864
});
5965

@@ -72,6 +78,8 @@ describe('cli args parsing', () => {
7278
'executable-path': '/tmp/test 123/chrome',
7379
e: '/tmp/test 123/chrome',
7480
executablePath: '/tmp/test 123/chrome',
81+
'chrome-arg': [],
82+
chromeArg: [],
7583
});
7684
});
7785

@@ -92,6 +100,26 @@ describe('cli args parsing', () => {
92100
width: 888,
93101
height: 777,
94102
},
103+
'chrome-arg': [],
104+
chromeArg: [],
105+
});
106+
});
107+
108+
it('parses viewport', async () => {
109+
const args = parseArguments('1.0.0', [
110+
'node',
111+
'main.js',
112+
`--chrome-arg='--no-sandbox'`,
113+
`--chrome-arg='--disable-setuid-sandbox'`,
114+
]);
115+
assert.deepStrictEqual(args, {
116+
_: [],
117+
headless: false,
118+
isolated: false,
119+
$0: 'npx chrome-devtools-mcp@latest',
120+
channel: 'stable',
121+
'chrome-arg': ['--no-sandbox', '--disable-setuid-sandbox'],
122+
chromeArg: ['--no-sandbox', '--disable-setuid-sandbox'],
95123
});
96124
});
97125
});

0 commit comments

Comments
 (0)