Skip to content

Commit 5922f00

Browse files
committed
fix: code formatting
1 parent 08b5661 commit 5922f00

File tree

7 files changed

+164
-166
lines changed

7 files changed

+164
-166
lines changed

src/McpResponse.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import type { ImageContentData, Response } from './tools/ToolDefinition.js';
7-
import type { McpContext } from './McpContext.js';
8-
import { ImageContent, TextContent } from '@modelcontextprotocol/sdk/types.js';
6+
import type {ImageContentData, Response} from './tools/ToolDefinition.js';
7+
import type {McpContext} from './McpContext.js';
8+
import {ImageContent, TextContent} from '@modelcontextprotocol/sdk/types.js';
99
import {
1010
getFormattedHeaderValue,
1111
getShortDescriptionForRequest,
1212
getStatusFromRequest,
1313
} from './formatters/networkFormatter.js';
14-
import { formatA11ySnapshot } from './formatters/snapshotFormatter.js';
15-
import { formatConsoleEvent } from './formatters/consoleFormatter.js';
14+
import {formatA11ySnapshot} from './formatters/snapshotFormatter.js';
15+
import {formatConsoleEvent} from './formatters/consoleFormatter.js';
1616
import {
1717
paginateNetworkRequests,
1818
type NetworkRequestsListingOptions,
@@ -219,15 +219,14 @@ Call browser_handle_dialog to handle it before continuing.`);
219219
response.push('Invalid page token provided. Showing first page.');
220220
}
221221

222-
const { startIndex, endIndex, total } = paginationResult;
222+
const {startIndex, endIndex, total} = paginationResult;
223223
if (total === 0) {
224224
if (paginationOptions?.requestType) {
225225
response.push('No requests found for the selected type(s).');
226226
} else {
227227
response.push('No requests found.');
228228
}
229-
}
230-
else {
229+
} else {
231230
response.push(`Showing ${startIndex + 1}-${endIndex} of ${total}.`);
232231
for (const request of paginationResult.requests) {
233232
response.push(getShortDescriptionForRequest(request));

src/tools/ToolDefinition.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66

77
import z from 'zod';
8-
import { Dialog, ElementHandle, Page } from 'puppeteer-core';
9-
import type { FilterableResourceType } from '../utils/networkUtils.js';
10-
import { ToolCategories } from './categories.js';
11-
import { TraceResult } from '../trace-processing/parse.js';
8+
import {Dialog, ElementHandle, Page} from 'puppeteer-core';
9+
import type {FilterableResourceType} from '../utils/networkUtils.js';
10+
import {ToolCategories} from './categories.js';
11+
import {TraceResult} from '../trace-processing/parse.js';
1212

1313
export interface ToolDefinition<
1414
Schema extends Zod.ZodRawShape = Zod.ZodRawShape,
@@ -79,7 +79,7 @@ export type Context = Readonly<{
7979
saveTemporaryFile(
8080
data: Uint8Array<ArrayBufferLike>,
8181
mimeType: 'image/png' | 'image/jpeg',
82-
): Promise<{ filename: string }>;
82+
): Promise<{filename: string}>;
8383
waitForEventsAfterAction(action: () => Promise<unknown>): Promise<void>;
8484
}>;
8585

src/tools/network.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
import z from 'zod';
8-
import { FILTERABLE_RESOURCE_TYPES } from '../utils/networkUtils.js';
9-
import { defineTool } from './ToolDefinition.js';
10-
import { ToolCategories } from './categories.js';
8+
import {FILTERABLE_RESOURCE_TYPES} from '../utils/networkUtils.js';
9+
import {defineTool} from './ToolDefinition.js';
10+
import {ToolCategories} from './categories.js';
1111

1212
export const listNetworkRequests = defineTool({
1313
name: 'list_network_requests',

src/utils/networkUtils.ts

Lines changed: 126 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,180 +3,181 @@
33
* Copyright 2025 Google LLC
44
* SPDX-License-Identifier: Apache-2.0
55
*/
6-
import { type HTTPRequest, type ResourceType } from 'puppeteer-core';
6+
import {type HTTPRequest, type ResourceType} from 'puppeteer-core';
77

88
export const FILTERABLE_RESOURCE_TYPES = [
9-
'document',
10-
'stylesheet',
11-
'image',
12-
'media',
13-
'font',
14-
'script',
15-
'xhr',
16-
'fetch',
17-
'prefetch',
18-
'websocket',
19-
'preflight',
20-
'other',
9+
'document',
10+
'stylesheet',
11+
'image',
12+
'media',
13+
'font',
14+
'script',
15+
'xhr',
16+
'fetch',
17+
'prefetch',
18+
'websocket',
19+
'preflight',
20+
'other',
2121
] as const satisfies readonly ResourceType[];
2222

2323
export type FilterableResourceType = (typeof FILTERABLE_RESOURCE_TYPES)[number];
2424

2525
export type NetworkRequestsListingOptions = {
26-
pageSize?: number;
27-
pageToken?: string;
28-
requestType?: FilterableResourceType | FilterableResourceType[];
26+
pageSize?: number;
27+
pageToken?: string;
28+
requestType?: FilterableResourceType | FilterableResourceType[];
2929
};
3030

3131
export type NetworkRequestsListingResult = {
32-
requests: readonly HTTPRequest[];
33-
nextPageToken?: string;
34-
previousPageToken?: string;
35-
startIndex: number;
36-
endIndex: number;
37-
invalidToken: boolean;
38-
total: number;
39-
appliedRequestType?: FilterableResourceType | FilterableResourceType[];
32+
requests: readonly HTTPRequest[];
33+
nextPageToken?: string;
34+
previousPageToken?: string;
35+
startIndex: number;
36+
endIndex: number;
37+
invalidToken: boolean;
38+
total: number;
39+
appliedRequestType?: FilterableResourceType | FilterableResourceType[];
4040
};
4141

4242
const DEFAULT_PAGE_SIZE = 20;
4343
const FILTERABLE_RESOURCE_TYPES_SET = new Set<FilterableResourceType>(
44-
FILTERABLE_RESOURCE_TYPES,
44+
FILTERABLE_RESOURCE_TYPES,
4545
);
4646

4747
export function isFilterableResourceType(
48-
value: ResourceType | string,
48+
value: ResourceType | string,
4949
): value is FilterableResourceType {
50-
return FILTERABLE_RESOURCE_TYPES_SET.has(value as FilterableResourceType);
50+
return FILTERABLE_RESOURCE_TYPES_SET.has(value as FilterableResourceType);
5151
}
5252

5353
export function sanitizeRequestTypeFilter(
54-
requestType?: string | string[] | null,
54+
requestType?: string | string[] | null,
5555
): FilterableResourceType | FilterableResourceType[] | undefined {
56-
if (requestType === undefined || requestType === null) {
57-
return undefined;
58-
}
56+
if (requestType === undefined || requestType === null) {
57+
return undefined;
58+
}
5959

60-
const values = Array.isArray(requestType) ? requestType : [requestType];
61-
const sanitized = values.filter(isFilterableResourceType);
60+
const values = Array.isArray(requestType) ? requestType : [requestType];
61+
const sanitized = values.filter(isFilterableResourceType);
6262

63-
if (!sanitized.length) {
64-
return undefined;
65-
}
63+
if (!sanitized.length) {
64+
return undefined;
65+
}
6666

67-
return Array.isArray(requestType) ? sanitized : sanitized[0];
67+
return Array.isArray(requestType) ? sanitized : sanitized[0];
6868
}
6969

7070
export function filterNetworkRequests(
71-
requests: readonly HTTPRequest[],
72-
requestType?: FilterableResourceType | FilterableResourceType[],
71+
requests: readonly HTTPRequest[],
72+
requestType?: FilterableResourceType | FilterableResourceType[],
7373
): readonly HTTPRequest[] {
74-
if (!requestType) {
75-
return requests;
76-
}
77-
78-
const normalizedTypes = new Set<FilterableResourceType>(
79-
Array.isArray(requestType) ? requestType : [requestType],
80-
);
81-
82-
if (!normalizedTypes.size) {
83-
return requests;
74+
if (!requestType) {
75+
return requests;
76+
}
77+
78+
const normalizedTypes = new Set<FilterableResourceType>(
79+
Array.isArray(requestType) ? requestType : [requestType],
80+
);
81+
82+
if (!normalizedTypes.size) {
83+
return requests;
84+
}
85+
86+
return requests.filter(request => {
87+
const type = request.resourceType();
88+
if (!isFilterableResourceType(type)) {
89+
return false;
8490
}
85-
86-
return requests.filter(request => {
87-
const type = request.resourceType();
88-
if (!isFilterableResourceType(type)) {
89-
return false;
90-
}
91-
return normalizedTypes.has(type);
92-
});
91+
return normalizedTypes.has(type);
92+
});
9393
}
9494

9595
export function paginateNetworkRequests(
96-
requests: readonly HTTPRequest[],
97-
options?: NetworkRequestsListingOptions,
96+
requests: readonly HTTPRequest[],
97+
options?: NetworkRequestsListingOptions,
9898
): NetworkRequestsListingResult {
99-
const sanitizedOptions = options ?? {};
100-
const filteredRequests = filterNetworkRequests(
101-
requests,
102-
sanitizedOptions.requestType,
103-
);
104-
const total = filteredRequests.length;
105-
106-
const hasPaginationOptions = hasPagination(sanitizedOptions);
107-
108-
if (!hasPaginationOptions) {
109-
return {
110-
requests: filteredRequests,
111-
nextPageToken: undefined,
112-
previousPageToken: undefined,
113-
startIndex: 0,
114-
endIndex: total,
115-
invalidToken: false,
116-
total,
117-
appliedRequestType: sanitizedOptions.requestType,
118-
};
119-
}
120-
121-
const pageSize = validatePageSize(sanitizedOptions.pageSize, total);
122-
const { startIndex, invalidToken } = resolveStartIndex(
123-
sanitizedOptions.pageToken,
124-
total,
125-
);
99+
const sanitizedOptions = options ?? {};
100+
const filteredRequests = filterNetworkRequests(
101+
requests,
102+
sanitizedOptions.requestType,
103+
);
104+
const total = filteredRequests.length;
126105

127-
const pageRequests = filteredRequests.slice(startIndex, startIndex + pageSize);
128-
const endIndex = startIndex + pageRequests.length;
129-
130-
const nextPageToken = endIndex < total ? String(endIndex) : undefined;
131-
const previousPageToken =
132-
startIndex > 0 ? String(Math.max(startIndex - pageSize, 0)) : undefined;
106+
const hasPaginationOptions = hasPagination(sanitizedOptions);
133107

108+
if (!hasPaginationOptions) {
134109
return {
135-
requests: pageRequests,
136-
nextPageToken,
137-
previousPageToken,
138-
startIndex,
139-
endIndex,
140-
invalidToken,
141-
total,
142-
appliedRequestType: sanitizedOptions.requestType,
110+
requests: filteredRequests,
111+
nextPageToken: undefined,
112+
previousPageToken: undefined,
113+
startIndex: 0,
114+
endIndex: total,
115+
invalidToken: false,
116+
total,
117+
appliedRequestType: sanitizedOptions.requestType,
143118
};
119+
}
120+
121+
const pageSize = validatePageSize(sanitizedOptions.pageSize, total);
122+
const {startIndex, invalidToken} = resolveStartIndex(
123+
sanitizedOptions.pageToken,
124+
total,
125+
);
126+
127+
const pageRequests = filteredRequests.slice(
128+
startIndex,
129+
startIndex + pageSize,
130+
);
131+
const endIndex = startIndex + pageRequests.length;
132+
133+
const nextPageToken = endIndex < total ? String(endIndex) : undefined;
134+
const previousPageToken =
135+
startIndex > 0 ? String(Math.max(startIndex - pageSize, 0)) : undefined;
136+
137+
return {
138+
requests: pageRequests,
139+
nextPageToken,
140+
previousPageToken,
141+
startIndex,
142+
endIndex,
143+
invalidToken,
144+
total,
145+
appliedRequestType: sanitizedOptions.requestType,
146+
};
144147
}
145148

146149
function hasPagination(options: NetworkRequestsListingOptions): boolean {
147-
return (
148-
options.pageSize !== undefined ||
149-
(options.pageToken !== undefined && options.pageToken !== null)
150-
);
150+
return (
151+
options.pageSize !== undefined ||
152+
(options.pageToken !== undefined && options.pageToken !== null)
153+
);
151154
}
152155

153156
function validatePageSize(pageSize: number | undefined, total: number): number {
154-
if (pageSize === undefined) {
155-
return total || DEFAULT_PAGE_SIZE;
156-
}
157-
if (!Number.isInteger(pageSize) || pageSize <= 0) {
158-
return DEFAULT_PAGE_SIZE;
159-
}
160-
return Math.min(pageSize, Math.max(total, 1));
157+
if (pageSize === undefined) {
158+
return total || DEFAULT_PAGE_SIZE;
159+
}
160+
if (!Number.isInteger(pageSize) || pageSize <= 0) {
161+
return DEFAULT_PAGE_SIZE;
162+
}
163+
return Math.min(pageSize, Math.max(total, 1));
161164
}
162165

163166
function resolveStartIndex(
164-
pageToken: string | undefined,
165-
total: number,
167+
pageToken: string | undefined,
168+
total: number,
166169
): {
167-
startIndex: number;
168-
invalidToken: boolean;
170+
startIndex: number;
171+
invalidToken: boolean;
169172
} {
170-
if (pageToken === undefined || pageToken === null) {
171-
return { startIndex: 0, invalidToken: false };
172-
}
173+
if (pageToken === undefined || pageToken === null) {
174+
return {startIndex: 0, invalidToken: false};
175+
}
173176

174-
const parsed = Number.parseInt(pageToken, 10);
175-
if (Number.isNaN(parsed) || parsed < 0 || parsed >= total) {
176-
return { startIndex: 0, invalidToken: total > 0 };
177-
}
177+
const parsed = Number.parseInt(pageToken, 10);
178+
if (Number.isNaN(parsed) || parsed < 0 || parsed >= total) {
179+
return {startIndex: 0, invalidToken: total > 0};
180+
}
178181

179-
return { startIndex: parsed, invalidToken: false };
182+
return {startIndex: parsed, invalidToken: false};
180183
}
181-
182-

0 commit comments

Comments
 (0)