Skip to content

Commit 9a51af2

Browse files
authored
feat: Allow opting out of default Chrome launch arguments (#729)
Related Issue - #430 ### Description When Chrome is launched via Puppeteer, it automatically adds a set of default flags like `--enable-automation --disable-extensions --disable-component-extensions-with-background-pages.` Currently, there is no way to opt out of these defaults, which makes certain use cases difficult or impossible to support. this PR adds a way to selectively ignore specific default Chrome launch flags applied by Puppeteer using its [ignoreDefaultArgs](https://pptr.dev/api/puppeteer.launchoptions#ignoredefaultargs) property. ```json { "name": "chrome-devtools-mcp", "version": "latest", "mcpServers": { "chrome-devtools": { "command": "npx", "args": [ "chrome-devtools-mcp@latest", "--ignore-default-chrome-arg='--enable-automation'", "--ignore-default-chrome-arg='--disable-extensions'" ] } } } ``` **Feedback appreciated** @OrKoN
1 parent 1f532b8 commit 9a51af2

File tree

6 files changed

+52
-6
lines changed

6 files changed

+52
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ The Chrome DevTools MCP server supports the following configuration option:
428428
Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
429429
- **Type:** array
430430

431+
- **`--ignoreDefaultChromeArg`/ `--ignore-default-chrome-arg`**
432+
Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
433+
- **Type:** array
434+
431435
- **`--categoryEmulation`/ `--category-emulation`**
432436
Set to false to exclude tools related to emulation.
433437
- **Type:** boolean

src/browser.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ interface McpLaunchOptions {
142142
width: number;
143143
height: number;
144144
};
145-
args?: string[];
145+
chromeArgs?: string[];
146+
ignoreDefaultChromeArgs?: string[];
146147
devtools: boolean;
147148
}
148149

@@ -167,9 +168,12 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
167168
}
168169

169170
const args: LaunchOptions['args'] = [
170-
...(options.args ?? []),
171+
...(options.chromeArgs ?? []),
171172
'--hide-crash-restore-bubble',
172173
];
174+
const ignoreDefaultArgs: LaunchOptions['ignoreDefaultArgs'] =
175+
options.ignoreDefaultChromeArgs ?? false;
176+
173177
if (headless) {
174178
args.push('--screen-info={3840x2160}');
175179
}
@@ -194,6 +198,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
194198
pipe: true,
195199
headless,
196200
args,
201+
ignoreDefaultArgs: ignoreDefaultArgs,
197202
acceptInsecureCerts: options.acceptInsecureCerts,
198203
handleDevToolsAsPage: true,
199204
});

src/cli.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ export const cliOptions = {
168168
describe:
169169
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
170170
},
171+
ignoreDefaultChromeArg: {
172+
type: 'array',
173+
describe:
174+
'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
175+
},
171176
categoryEmulation: {
172177
type: 'boolean',
173178
default: true,
@@ -229,6 +234,10 @@ export function parseArguments(version: string, argv = process.argv) {
229234
`$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,
230235
'Launch Chrome without sandboxes. Use with caution.',
231236
],
237+
[
238+
`$0 --ignore-default-chrome-arg='--disable-extensions'`,
239+
'Disable the default arguments provided by Puppeteer. Use with caution.',
240+
],
232241
['$0 --no-category-emulation', 'Disable tools in the emulation category'],
233242
[
234243
'$0 --no-category-performance',

src/main.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => {
5454

5555
let context: McpContext;
5656
async function getContext(): Promise<McpContext> {
57-
const extraArgs: string[] = (args.chromeArg ?? []).map(String);
57+
const chromeArgs: string[] = (args.chromeArg ?? []).map(String);
58+
const ignoreDefaultChromeArgs: string[] = (
59+
args.ignoreDefaultChromeArg ?? []
60+
).map(String);
5861
if (args.proxyServer) {
59-
extraArgs.push(`--proxy-server=${args.proxyServer}`);
62+
chromeArgs.push(`--proxy-server=${args.proxyServer}`);
6063
}
6164
const devtools = args.experimentalDevtools ?? false;
6265
const browser =
@@ -78,7 +81,8 @@ async function getContext(): Promise<McpContext> {
7881
userDataDir: args.userDataDir,
7982
logFile,
8083
viewport: args.viewport,
81-
args: extraArgs,
84+
chromeArgs,
85+
ignoreDefaultChromeArgs,
8286
acceptInsecureCerts: args.acceptInsecureCerts,
8387
devtools,
8488
});

tests/browser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('browser', () => {
8282
userDataDir: folderPath,
8383
executablePath: executablePath(),
8484
devtools: false,
85-
args: ['--remote-debugging-port=0'],
85+
chromeArgs: ['--remote-debugging-port=0'],
8686
});
8787
try {
8888
const connectedBrowser = await ensureBrowserConnected({

tests/cli.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,30 @@ describe('cli args parsing', () => {
143143
});
144144
});
145145

146+
it('parses ignore chrome args', async () => {
147+
const args = parseArguments('1.0.0', [
148+
'node',
149+
'main.js',
150+
`--ignore-default-chrome-arg='--disable-extensions'`,
151+
`--ignore-default-chrome-arg='--disable-cancel-all-touches'`,
152+
]);
153+
assert.deepStrictEqual(args, {
154+
...defaultArgs,
155+
_: [],
156+
headless: false,
157+
$0: 'npx chrome-devtools-mcp@latest',
158+
channel: 'stable',
159+
'ignore-default-chrome-arg': [
160+
'--disable-extensions',
161+
'--disable-cancel-all-touches',
162+
],
163+
ignoreDefaultChromeArg: [
164+
'--disable-extensions',
165+
'--disable-cancel-all-touches',
166+
],
167+
});
168+
});
169+
146170
it('parses wsEndpoint with ws:// protocol', async () => {
147171
const args = parseArguments('1.0.0', [
148172
'node',

0 commit comments

Comments
 (0)