Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
- **Emulation** (2 tools)
- [`emulate`](docs/tool-reference.md#emulate)
- [`resize_page`](docs/tool-reference.md#resize_page)
- **Performance** (3 tools)
- **Performance** (5 tools)
- [`coverage_start`](docs/tool-reference.md#coverage_start)
- [`coverage_stop`](docs/tool-reference.md#coverage_stop)
- [`performance_analyze_insight`](docs/tool-reference.md#performance_analyze_insight)
- [`performance_start_trace`](docs/tool-reference.md#performance_start_trace)
- [`performance_stop_trace`](docs/tool-reference.md#performance_stop_trace)
Expand Down
27 changes: 26 additions & 1 deletion docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
- **[Emulation](#emulation)** (2 tools)
- [`emulate`](#emulate)
- [`resize_page`](#resize_page)
- **[Performance](#performance)** (3 tools)
- **[Performance](#performance)** (5 tools)
- [`coverage_start`](#coverage_start)
- [`coverage_stop`](#coverage_stop)
- [`performance_analyze_insight`](#performance_analyze_insight)
- [`performance_start_trace`](#performance_start_trace)
- [`performance_stop_trace`](#performance_stop_trace)
Expand Down Expand Up @@ -215,6 +217,29 @@

## Performance

### `coverage_start`

**Description:** Starts code coverage tracking on the selected page. This tracks which JavaScript and CSS code is actually used, helping identify unused code that could be removed to improve page performance.

**Parameters:**

- **includeCSS** (boolean) _(optional)_: Whether to include CSS coverage. Defaults to true.
- **includeJS** (boolean) _(optional)_: Whether to include JavaScript coverage. Defaults to true.
- **resetOnNavigation** (boolean) _(optional)_: Whether to reset coverage data on page navigation. Defaults to true.

---

### `coverage_stop`

**Description:** Stops code coverage tracking and returns a comprehensive report showing URLs, total bytes, used bytes, unused bytes, and usage percentage for each JavaScript and CSS resource. Results are sorted by unused bytes (most wasted first) and paginated.

**Parameters:**

- **pageIdx** (integer) _(optional)_: Page index (0-based). Use this to navigate through results. For example, pageIdx: 1 shows the next page.
- **pageSize** (integer) _(optional)_: Number of results to show per page. Maximum and default is 5 to keep output manageable.

---

### `performance_analyze_insight`

**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.
Expand Down
21 changes: 21 additions & 0 deletions src/McpContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class McpContext implements Context {
#consoleCollector: ConsoleCollector;

#isRunningTrace = false;
#isRunningCoverage = false;
#coverageOptions: {includeJS: boolean; includeCSS: boolean} = {
includeJS: true,
includeCSS: true,
};
#networkConditionsMap = new WeakMap<Page, string>();
#cpuThrottlingRateMap = new WeakMap<Page, number>();
#geolocationMap = new WeakMap<Page, GeolocationOptions>();
Expand Down Expand Up @@ -306,6 +311,22 @@ export class McpContext implements Context {
return this.#isRunningTrace;
}

setIsRunningCoverage(x: boolean): void {
this.#isRunningCoverage = x;
}

isRunningCoverage(): boolean {
return this.#isRunningCoverage;
}

setCoverageOptions(options: {includeJS: boolean; includeCSS: boolean}): void {
this.#coverageOptions = options;
}

getCoverageOptions(): {includeJS: boolean; includeCSS: boolean} {
return this.#coverageOptions;
}

getDialog(): Dialog | undefined {
return this.#dialog;
}
Expand Down
9 changes: 9 additions & 0 deletions src/tools/ToolDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ export interface Response {
/**
* Only add methods required by tools/*.
*/
export interface CoverageOptions {
includeJS: boolean;
includeCSS: boolean;
}

export type Context = Readonly<{
isRunningPerformanceTrace(): boolean;
setIsRunningPerformanceTrace(x: boolean): void;
recordedTraces(): TraceResult[];
storeTraceRecording(result: TraceResult): void;
isRunningCoverage(): boolean;
setIsRunningCoverage(x: boolean): void;
getCoverageOptions(): CoverageOptions;
setCoverageOptions(options: CoverageOptions): void;
getSelectedPage(): Page;
getDialog(): Dialog | undefined;
clearDialog(): void;
Expand Down
Loading