Skip to content

Commit 8a21061

Browse files
committed
fix(cli): handle empty --browserUrl to prevent Invalid URL crash
1 parent 54bd938 commit 8a21061

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

src/McpResponse.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ import type {
77
ImageContent,
88
TextContent,
99
} from '@modelcontextprotocol/sdk/types.js';
10-
import type { ResourceType } from 'puppeteer-core';
10+
import type {ResourceType} from 'puppeteer-core';
1111

12-
import { formatConsoleEvent } from './formatters/consoleFormatter.js';
12+
import {formatConsoleEvent} from './formatters/consoleFormatter.js';
1313
import {
1414
getFormattedHeaderValue,
1515
getShortDescriptionForRequest,
1616
getStatusFromRequest,
1717
} from './formatters/networkFormatter.js';
18-
import { formatA11ySnapshot } from './formatters/snapshotFormatter.js';
19-
import type { McpContext } from './McpContext.js';
20-
import type { ImageContentData, Response } from './tools/ToolDefinition.js';
21-
import { paginate, type PaginationOptions } from './utils/pagination.js';
18+
import {formatA11ySnapshot} from './formatters/snapshotFormatter.js';
19+
import type {McpContext} from './McpContext.js';
20+
import type {ImageContentData, Response} from './tools/ToolDefinition.js';
21+
import {paginate, type PaginationOptions} from './utils/pagination.js';
2222

2323
export class McpResponse implements Response {
2424
// ✅ added properties here (not duplicated)
25-
public consoleMessages: any[] = [];
25+
public consoleMessages: unknown[] = [];
2626
public cleanedConsoleData: string[] = [];
2727

2828
#includePages = false;
@@ -84,7 +84,7 @@ export class McpResponse implements Response {
8484
let text =
8585
typeof entry === 'string'
8686
? entry
87-
: entry.text ?? JSON.stringify(entry);
87+
: (entry.text ?? JSON.stringify(entry));
8888
text = text.replace(/\bt=\d+(?::\d+){0,2}\b/g, '');
8989
text = text.replace(/\bLog>\b/g, '');
9090
text = text.replace(/\s+/g, ' ').trim();
@@ -192,15 +192,16 @@ export class McpResponse implements Response {
192192
response.push(`Emulating: ${cpuThrottlingRate}x slowdown`);
193193
}
194194

195-
const dialog = context.getDialog();
196-
if (dialog) {
197-
response.push(`# Open dialog
195+
const dialog = context.getDialog();
196+
if (dialog) {
197+
response.push(`# Open dialog
198198
${dialog.type()}: ${dialog.message()} (default value: ${dialog.message()}).`);
199199

200-
// Add this line to satisfy the test
201-
response.push("Call browser_handle_dialog to handle it before continuing.");
202-
}
203-
200+
// Add this line to satisfy the test
201+
response.push(
202+
'Call browser_handle_dialog to handle it before continuing.',
203+
);
204+
}
204205

205206
if (this.#includePages) {
206207
const parts = [`## Pages`];
@@ -250,7 +251,7 @@ ${dialog.type()}: ${dialog.message()} (default value: ${dialog.message()}).`);
250251
response.push('Invalid page number provided. Showing first page.');
251252
}
252253

253-
const { startIndex, endIndex, currentPage, totalPages } =
254+
const {startIndex, endIndex, currentPage, totalPages} =
254255
paginationResult;
255256
response.push(
256257
`Showing ${startIndex + 1}-${endIndex} of ${requests.length} (Page ${

src/cli.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ export const cliOptions = {
1414
'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.',
1515
alias: 'u',
1616
coerce: (url: string) => {
17-
if (!url || url.trim() === '') {
18-
return undefined;
19-
}
20-
return new URL(url).toString();
17+
if (!url.trim()) return undefined;
18+
const parsed = new URL(url);
19+
return parsed.href.replace(/\/$/, ''); // remove trailing slash
2120
},
2221
},
2322
headless: {

src/tools/console.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export const consoleTool = defineTool({
1717
schema: {},
1818
handler: async (_request, response) => {
1919
response.setIncludeConsoleData(true);
20-
return (response as any).cleanedConsoleData ?? [];
21-
22-
20+
return (response as unknown).cleanedConsoleData ?? [];
2321
},
2422
});

0 commit comments

Comments
 (0)