Skip to content

Commit a07ff56

Browse files
author
Natallia Harshunova
committed
Refactor options configuration
1 parent f1892a9 commit a07ff56

3 files changed

Lines changed: 55 additions & 8 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -637,12 +637,12 @@ The Chrome DevTools MCP server supports the following configuration option:
637637
- **Type:** array
638638

639639
- **`--blocklist`**
640-
Restricts network access by blocking specified URL patterns (uses URLPattern API https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources).
641-
- **Type:** array
640+
Restricts network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Supports comma-separated patterns.
641+
- **Type:** string
642642

643643
- **`--allowlist`**
644-
Restricts network access by allowing only specified URL patterns (uses URLPattern API https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources).
645-
- **Type:** array
644+
Restricts network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Supports comma-separated patterns.
645+
- **Type:** string
646646

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

src/bin/chrome-devtools-mcp-cli-options.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,36 @@ export const cliOptions = {
205205
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
206206
},
207207
blocklist: {
208-
type: 'array',
208+
type: 'string',
209209
describe:
210-
'Restricts network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources).',
210+
'Restricts network access by blocking specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Silently detaches from targets with blocked URLs upon connection, and blocks runtime requests (including navigations and subresources). Supports comma-separated patterns.',
211211
conflicts: ['allowlist'],
212+
coerce: (value: string | string[] | undefined) => {
213+
if (!value) {
214+
return undefined;
215+
}
216+
const arr = Array.isArray(value) ? value : [value];
217+
return arr
218+
.flatMap(val => val.split(','))
219+
.map(s => s.trim())
220+
.filter(Boolean);
221+
},
212222
},
213223
allowlist: {
214-
type: 'array',
224+
type: 'string',
215225
describe:
216-
'Restricts network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources).',
226+
'Restricts network access by allowing only specified URL patterns (uses https://urlpattern.spec.whatwg.org/). Requires Chrome 149+. Silently detaches from targets with unallowed URLs upon connection, and blocks runtime requests (including navigations and subresources). Supports comma-separated patterns.',
217227
conflicts: ['blocklist'],
228+
coerce: (value: string | string[] | undefined) => {
229+
if (!value) {
230+
return undefined;
231+
}
232+
const arr = Array.isArray(value) ? value : [value];
233+
return arr
234+
.flatMap(val => val.split(','))
235+
.map(s => s.trim())
236+
.filter(Boolean);
237+
},
218238
},
219239
ignoreDefaultChromeArg: {
220240
type: 'array',

tests/cli.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,31 @@ describe('cli args parsing', () => {
345345
);
346346
assert.strictEqual(disabledArgs.performanceCrux, false);
347347
});
348+
349+
it('parses blocklist and allowlist flags with comma separation', async () => {
350+
const defaultArgs = parseArguments('1.0.0', ['node', 'main.js']);
351+
assert.strictEqual(defaultArgs.blocklist, undefined);
352+
assert.strictEqual(defaultArgs.allowlist, undefined);
353+
354+
const blocklistArgs = parseArguments(
355+
'1.0.0',
356+
[
357+
'node',
358+
'main.js',
359+
'--blocklist=https://example.com/ads/*,https://tracker.com/*',
360+
],
361+
{},
362+
);
363+
assert.deepStrictEqual(blocklistArgs.blocklist, [
364+
'https://example.com/ads/*',
365+
'https://tracker.com/*',
366+
]);
367+
368+
const allowlistArgs = parseArguments(
369+
'1.0.0',
370+
['node', 'main.js', '--allowlist=https://trusted.com/*'],
371+
{},
372+
);
373+
assert.deepStrictEqual(allowlistArgs.allowlist, ['https://trusted.com/*']);
374+
});
348375
});

0 commit comments

Comments
 (0)