Skip to content

Commit 998d4be

Browse files
author
Natallia Harshunova
committed
Rename cli arguments to allowedUrlPattern and blockedUrlPattern
1 parent f5f6565 commit 998d4be

8 files changed

Lines changed: 73 additions & 62 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,13 @@ The Chrome DevTools MCP server supports the following configuration option:
636636
Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.
637637
- **Type:** array
638638

639-
- **`--blocklist`**
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
639+
- **`--blockedUrlPattern`/ `--blocked-url-pattern`**
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). Accepts an array of patterns.
641+
- **Type:** array
642642

643-
- **`--allowlist`**
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
643+
- **`--allowedUrlPattern`/ `--allowed-url-pattern`**
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). Accepts an array of patterns.
645+
- **Type:** array
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: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -204,37 +204,17 @@ export const cliOptions = {
204204
describe:
205205
'Additional arguments for Chrome. Only applies when Chrome is launched by chrome-devtools-mcp.',
206206
},
207-
blocklist: {
208-
type: 'string',
207+
blockedUrlPattern: {
208+
type: 'array',
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). Supports comma-separated patterns.',
211-
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-
},
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). Accepts an array of patterns.',
211+
conflicts: ['allowedUrlPattern'],
222212
},
223-
allowlist: {
224-
type: 'string',
213+
allowedUrlPattern: {
214+
type: 'array',
225215
describe:
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.',
227-
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-
},
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). Accepts an array of patterns.',
217+
conflicts: ['blockedUrlPattern'],
238218
},
239219
ignoreDefaultChromeArg: {
240220
type: 'array',

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ export async function createMcpServer(
9999
chromeArgs.push(`--proxy-server=${serverArgs.proxyServer}`);
100100
}
101101
const devtools = serverArgs.experimentalDevtools ?? false;
102-
const blocklist = serverArgs.blocklist
103-
? serverArgs.blocklist.map(String)
102+
const blocklist = serverArgs.blockedUrlPattern
103+
? serverArgs.blockedUrlPattern.map(String)
104104
: undefined;
105-
const allowlist = serverArgs.allowlist
106-
? serverArgs.allowlist.map(String)
105+
const allowlist = serverArgs.allowedUrlPattern
106+
? serverArgs.allowedUrlPattern.map(String)
107107
: undefined;
108108

109109
const browser =

src/telemetry/flag_usage_metrics.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@
297297
"flagType": "boolean"
298298
},
299299
{
300-
"name": "blocklist_present",
300+
"name": "blocked_url_pattern_present",
301301
"flagType": "boolean"
302302
},
303303
{
304-
"name": "allowlist_present",
304+
"name": "allowed_url_pattern_present",
305305
"flagType": "boolean"
306306
}
307307
]

tests/browser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('browser', () => {
113113
const browser = await launch({
114114
headless: true,
115115
isolated: true,
116-
executablePath: executablePath(),
116+
executablePath: await executablePath(),
117117
devtools: false,
118118
blocklist: ['*://*:*/blocked.html'],
119119
});
@@ -157,7 +157,7 @@ describe('browser', () => {
157157
const browser = await launch({
158158
headless: true,
159159
isolated: true,
160-
executablePath: executablePath(),
160+
executablePath: await executablePath(),
161161
devtools: false,
162162
allowlist: ['*://*/allowed.html'],
163163
});

tests/cli.test.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,30 +346,61 @@ describe('cli args parsing', () => {
346346
assert.strictEqual(disabledArgs.performanceCrux, false);
347347
});
348348

349-
it('parses blocklist and allowlist flags with comma separation', async () => {
349+
it('parses blocked-url-pattern flags as array', async () => {
350350
const defaultArgs = parseArguments('1.0.0', ['node', 'main.js']);
351-
assert.strictEqual(defaultArgs.blocklist, undefined);
352-
assert.strictEqual(defaultArgs.allowlist, undefined);
351+
assert.strictEqual(defaultArgs.blockedUrlPattern, undefined);
353352

354-
const blocklistArgs = parseArguments(
353+
const singleArgs = parseArguments(
354+
'1.0.0',
355+
['node', 'main.js', '--blocked-url-pattern=https://example.com/*'],
356+
{},
357+
);
358+
assert.deepStrictEqual(singleArgs.blockedUrlPattern, [
359+
'https://example.com/*',
360+
]);
361+
362+
const repeatedArgs = parseArguments(
355363
'1.0.0',
356364
[
357365
'node',
358366
'main.js',
359-
'--blocklist=https://example.com/ads/*,https://tracker.com/*',
367+
'--blocked-url-pattern=https://a.com/*',
368+
'--blocked-url-pattern=https://b.com/*',
360369
],
361370
{},
362371
);
363-
assert.deepStrictEqual(blocklistArgs.blocklist, [
364-
'https://example.com/ads/*',
365-
'https://tracker.com/*',
372+
assert.deepStrictEqual(repeatedArgs.blockedUrlPattern, [
373+
'https://a.com/*',
374+
'https://b.com/*',
375+
]);
376+
});
377+
378+
it('parses allowed-url-pattern flags as array', async () => {
379+
const defaultArgs = parseArguments('1.0.0', ['node', 'main.js']);
380+
assert.strictEqual(defaultArgs.allowedUrlPattern, undefined);
381+
382+
const singleArgs = parseArguments(
383+
'1.0.0',
384+
['node', 'main.js', '--allowed-url-pattern=https://example.com/*'],
385+
{},
386+
);
387+
assert.deepStrictEqual(singleArgs.allowedUrlPattern, [
388+
'https://example.com/*',
366389
]);
367390

368-
const allowlistArgs = parseArguments(
391+
const repeatedArgs = parseArguments(
369392
'1.0.0',
370-
['node', 'main.js', '--allowlist=https://trusted.com/*'],
393+
[
394+
'node',
395+
'main.js',
396+
'--allowed-url-pattern=https://a.com/*',
397+
'--allowed-url-pattern=https://b.com/*',
398+
],
371399
{},
372400
);
373-
assert.deepStrictEqual(allowlistArgs.allowlist, ['https://trusted.com/*']);
401+
assert.deepStrictEqual(repeatedArgs.allowedUrlPattern, [
402+
'https://a.com/*',
403+
'https://b.com/*',
404+
]);
374405
});
375406
});

tests/security_policies.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('Security Policies Integration', () => {
7575
);
7676
},
7777
{
78-
blocklist: [server.getRoute('/blocked.html')],
78+
blockedUrlPattern: [server.getRoute('/blocked.html')],
7979
},
8080
);
8181
});
@@ -138,7 +138,7 @@ describe('Security Policies Integration', () => {
138138
);
139139
},
140140
{
141-
allowlist: [server.getRoute('/allowed.html')],
141+
allowedUrlPattern: [server.getRoute('/allowed.html')],
142142
},
143143
);
144144
});
@@ -231,7 +231,7 @@ describe('Security Policies Integration', () => {
231231
);
232232
},
233233
{
234-
blocklist: [server.getRoute('/blocked.html')],
234+
blockedUrlPattern: [server.getRoute('/blocked.html')],
235235
},
236236
);
237237
});

tests/utils.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ export async function withBrowser(
7474
autoOpenDevTools?: boolean;
7575
executablePath?: string;
7676
args?: string[];
77-
blocklist?: string[];
78-
allowlist?: string[];
77+
blockedUrlPattern?: string[];
78+
allowedUrlPattern?: string[];
7979
} = {},
8080
) {
8181
const launchOptions: LaunchOptions = {
@@ -88,8 +88,8 @@ export async function withBrowser(
8888
handleDevToolsAsPage: true,
8989
args: [...(options.args || []), '--screen-info={3840x2160}'],
9090
enableExtensions: true,
91-
blocklist: options.blocklist,
92-
allowlist: options.allowlist,
91+
blocklist: options.blockedUrlPattern,
92+
allowlist: options.allowedUrlPattern,
9393
};
9494
const key = JSON.stringify(launchOptions);
9595

@@ -119,8 +119,8 @@ export async function withMcpContext(
119119
performanceCrux?: boolean;
120120
executablePath?: string;
121121
args?: string[];
122-
blocklist?: string[];
123-
allowlist?: string[];
122+
blockedUrlPattern?: string[];
123+
allowedUrlPattern?: string[];
124124
} = {},
125125
args: ParsedArguments = {} as ParsedArguments,
126126
) {

0 commit comments

Comments
 (0)