Skip to content

Commit 098a904

Browse files
authored
fix(cli): tolerate empty browser URLs (#298)
it seems some clients default to empty default values for args. We can accept that and do not error for these. Closes #264
1 parent 8200194 commit 098a904

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export const cliOptions = {
1414
description:
1515
'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.',
1616
alias: 'u',
17-
coerce: (url: string) => {
17+
coerce: (url: string | undefined) => {
18+
if (!url) {
19+
return;
20+
}
1821
try {
1922
new URL(url);
2023
} catch {

tests/cli.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ describe('cli args parsing', () => {
3838
});
3939
});
4040

41+
it('parses an empty browser url', async () => {
42+
const args = parseArguments('1.0.0', [
43+
'node',
44+
'main.js',
45+
'--browserUrl',
46+
'',
47+
]);
48+
assert.deepStrictEqual(args, {
49+
_: [],
50+
headless: false,
51+
isolated: false,
52+
$0: 'npx chrome-devtools-mcp@latest',
53+
'browser-url': undefined,
54+
browserUrl: undefined,
55+
u: undefined,
56+
channel: 'stable',
57+
});
58+
});
59+
4160
it('parses with executable path', async () => {
4261
const args = parseArguments('1.0.0', [
4362
'node',

0 commit comments

Comments
 (0)