Skip to content

Commit 5a9d24a

Browse files
author
Natallia Harshunova
committed
Refactor options configuration
1 parent e3acb48 commit 5a9d24a

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
@@ -616,12 +616,12 @@ The Chrome DevTools MCP server supports the following configuration option:
616616
- **Type:** array
617617

618618
- **`--blocklist`**
619-
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).
620-
- **Type:** array
619+
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.
620+
- **Type:** string
621621

622622
- **`--allowlist`**
623-
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).
624-
- **Type:** array
623+
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.
624+
- **Type:** string
625625

626626
- **`--ignoreDefaultChromeArg`/ `--ignore-default-chrome-arg`**
627627
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
@@ -211,16 +211,36 @@ export const cliOptions = {
211211
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
212212
},
213213
blocklist: {
214-
type: 'array',
214+
type: 'string',
215215
describe:
216-
'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).',
216+
'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.',
217217
conflicts: ['allowlist'],
218+
coerce: (value: string | string[] | undefined) => {
219+
if (!value) {
220+
return undefined;
221+
}
222+
const arr = Array.isArray(value) ? value : [value];
223+
return arr
224+
.flatMap(val => val.split(','))
225+
.map(s => s.trim())
226+
.filter(Boolean);
227+
},
218228
},
219229
allowlist: {
220-
type: 'array',
230+
type: 'string',
221231
describe:
222-
'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).',
232+
'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.',
223233
conflicts: ['blocklist'],
234+
coerce: (value: string | string[] | undefined) => {
235+
if (!value) {
236+
return undefined;
237+
}
238+
const arr = Array.isArray(value) ? value : [value];
239+
return arr
240+
.flatMap(val => val.split(','))
241+
.map(s => s.trim())
242+
.filter(Boolean);
243+
},
224244
},
225245
ignoreDefaultChromeArg: {
226246
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)