豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ The Chrome DevTools MCP server supports the following configuration option:
Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
- **Type:** array

- **`--ignoreDefaultChromeArg`/ `--ignore-default-chrome-arg`**
Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
- **Type:** array

- **`--categoryEmulation`/ `--category-emulation`**
Set to false to exclude tools related to emulation.
- **Type:** boolean
Expand Down
9 changes: 7 additions & 2 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ interface McpLaunchOptions {
width: number;
height: number;
};
args?: string[];
chromeArgs?: string[];
ignoreDefaultChromeArgs?: string[];
devtools: boolean;
}

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

const args: LaunchOptions['args'] = [
...(options.args ?? []),
...(options.chromeArgs ?? []),
'--hide-crash-restore-bubble',
];
const ignoreDefaultArgs: LaunchOptions['ignoreDefaultArgs'] =
options.ignoreDefaultChromeArgs ?? false;

if (headless) {
args.push('--screen-info={3840x2160}');
}
Expand All @@ -194,6 +198,7 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
pipe: true,
headless,
args,
ignoreDefaultArgs: ignoreDefaultArgs,
acceptInsecureCerts: options.acceptInsecureCerts,
handleDevToolsAsPage: true,
});
Expand Down
9 changes: 9 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ export const cliOptions = {
describe:
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
},
ignoreDefaultChromeArg: {
type: 'array',
describe:
'Explicitly disable default arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
},
categoryEmulation: {
type: 'boolean',
default: true,
Expand Down Expand Up @@ -229,6 +234,10 @@ export function parseArguments(version: string, argv = process.argv) {
`$0 --chrome-arg='--no-sandbox' --chrome-arg='--disable-setuid-sandbox'`,
'Launch Chrome without sandboxes. Use with caution.',
],
[
`$0 --ignore-default-chrome-arg='--disable-extensions'`,
'Disable the default arguments provided by Puppeteer. Use with caution.',
],
['$0 --no-category-emulation', 'Disable tools in the emulation category'],
[
'$0 --no-category-performance',
Expand Down
10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ server.server.setRequestHandler(SetLevelRequestSchema, () => {

let context: McpContext;
async function getContext(): Promise<McpContext> {
const extraArgs: string[] = (args.chromeArg ?? []).map(String);
const chromeArgs: string[] = (args.chromeArg ?? []).map(String);
const ignoreDefaultChromeArgs: string[] = (
args.ignoreDefaultChromeArg ?? []
).map(String);
if (args.proxyServer) {
extraArgs.push(`--proxy-server=${args.proxyServer}`);
chromeArgs.push(`--proxy-server=${args.proxyServer}`);
}
const devtools = args.experimentalDevtools ?? false;
const browser =
Expand All @@ -78,7 +81,8 @@ async function getContext(): Promise<McpContext> {
userDataDir: args.userDataDir,
logFile,
viewport: args.viewport,
args: extraArgs,
chromeArgs,
ignoreDefaultChromeArgs,
acceptInsecureCerts: args.acceptInsecureCerts,
devtools,
});
Expand Down
2 changes: 1 addition & 1 deletion tests/browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('browser', () => {
userDataDir: folderPath,
executablePath: executablePath(),
devtools: false,
args: ['--remote-debugging-port=0'],
chromeArgs: ['--remote-debugging-port=0'],
});
try {
const connectedBrowser = await ensureBrowserConnected({
Expand Down
24 changes: 24 additions & 0 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,30 @@ describe('cli args parsing', () => {
});
});

it('parses ignore chrome args', async () => {
const args = parseArguments('1.0.0', [
'node',
'main.js',
`--ignore-default-chrome-arg='--disable-extensions'`,
`--ignore-default-chrome-arg='--disable-cancel-all-touches'`,
]);
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
'ignore-default-chrome-arg': [
'--disable-extensions',
'--disable-cancel-all-touches',
],
ignoreDefaultChromeArg: [
'--disable-extensions',
'--disable-cancel-all-touches',
],
});
});

it('parses wsEndpoint with ws:// protocol', async () => {
const args = parseArguments('1.0.0', [
'node',
Expand Down