Skip to content

Commit 010125b

Browse files
committed
add --performance-crux flag, defaulted to true
Change-Id: Ia6dcaf83b12fe44a5167a5c7c8fb7e40276af61c
1 parent 446f32f commit 010125b

8 files changed

Lines changed: 60 additions & 4 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ MCP clients.
3030
Performance tools may send trace URLs to the Google CrUX API to fetch real-user
3131
experience data. This helps provide a holistic performance picture by
3232
presenting field data alongside lab data. This data is collected by the [Chrome
33-
User Experience Report (CrUX)](https://developer.chrome.com/docs/crux).
33+
User Experience Report (CrUX)](https://developer.chrome.com/docs/crux). To disable
34+
this, run with the `--no-performance-crux` flag.
3435

3536
## **Usage statistics**
3637

@@ -469,6 +470,11 @@ The Chrome DevTools MCP server supports the following configuration option:
469470
- **Type:** boolean
470471
- **Default:** `true`
471472

473+
- **`--performanceCrux`/ `--performance-crux`**
474+
Set to false to disable CrUX (field data) integration in performance tools.
475+
- **Type:** boolean
476+
- **Default:** `true`
477+
472478
- **`--usageStatistics`/ `--usage-statistics`**
473479
Set to false to opt-out of usage statistics collection. Google collects usage data to improve the tool, handled under the Google Privacy Policy (https://policies.google.com/privacy). This is independent from Chrome browser metrics.
474480
- **Type:** boolean

src/McpContext.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ interface McpContextOptions {
6969
experimentalDevToolsDebugging: boolean;
7070
// Whether all page-like targets are exposed as pages.
7171
experimentalIncludeAllPages?: boolean;
72+
// Whether CrUX data should be fetched.
73+
performanceCrux: boolean;
7274
}
7375

7476
const DEFAULT_TIMEOUT = 5_000;
@@ -376,6 +378,10 @@ export class McpContext implements Context {
376378
return this.#isRunningTrace;
377379
}
378380

381+
isCruxEnabled(): boolean {
382+
return this.#options.performanceCrux;
383+
}
384+
379385
getDialog(): Dialog | undefined {
380386
return this.#dialog;
381387
}

src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ export const cliOptions = {
204204
hidden: true,
205205
describe: 'Set to false to exclude tools related to extensions.',
206206
},
207+
performanceCrux: {
208+
type: 'boolean',
209+
default: true,
210+
describe:
211+
'Set to false to disable CrUX (field data) integration in performance tools.',
212+
},
207213
usageStatistics: {
208214
type: 'boolean',
209215
default: true,
@@ -297,6 +303,10 @@ export function parseArguments(version: string, argv = process.argv) {
297303
'$0 --no-usage-statistics',
298304
'Do not send usage statistics https://github.com/ChromeDevTools/chrome-devtools-mcp#usage-statistics.',
299305
],
306+
[
307+
'$0 --no-performance-crux',
308+
'Disable CrUX (field data) integration in performance tools.',
309+
],
300310
]);
301311

302312
return yargsInstance

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ async function getContext(): Promise<McpContext> {
105105
context = await McpContext.from(browser, logger, {
106106
experimentalDevToolsDebugging: devtools,
107107
experimentalIncludeAllPages: args.experimentalIncludeAllPages,
108+
performanceCrux: args.performanceCrux,
108109
});
109110
}
110111
return context;
@@ -115,7 +116,7 @@ const logDisclaimers = () => {
115116
`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
116117
debug, and modify any data in the browser or DevTools.
117118
Avoid sharing sensitive or personal information that you do not want to share with MCP clients.
118-
Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data.`,
119+
Performance tools may send trace URLs to the Google CrUX API to fetch real-user experience data. To disable, run with --no-performance-crux.`,
119120
);
120121

121122
if (args.usageStatistics) {

src/tools/ToolDefinition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface Response {
102102
export type Context = Readonly<{
103103
isRunningPerformanceTrace(): boolean;
104104
setIsRunningPerformanceTrace(x: boolean): void;
105+
isCruxEnabled(): boolean;
105106
recordedTraces(): TraceResult[];
106107
storeTraceRecording(result: TraceResult): void;
107108
getSelectedPage(): Page;

src/tools/performance.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ async function stopTracingAndAppendOutput(
203203
const result = await parseRawTraceBuffer(traceEventsBuffer);
204204
response.appendResponseLine('The performance trace has been stopped.');
205205
if (traceResultIsSuccess(result)) {
206-
await populateCruxData(result);
206+
if (context.isCruxEnabled()) {
207+
await populateCruxData(result);
208+
}
207209
context.storeTraceRecording(result);
208210
response.attachTraceSummary(result);
209211
} else {

tests/tools/performance.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,31 @@ describe('performance', () => {
325325
);
326326
});
327327
});
328+
329+
it('does not fetch CrUX data if performanceCrux is false', async () => {
330+
const rawData = loadTraceAsBuffer('basic-trace.json.gz');
331+
await withMcpContext(
332+
async (response, context) => {
333+
context.setIsRunningPerformanceTrace(true);
334+
const selectedPage = context.getSelectedPage();
335+
sinon.stub(selectedPage.tracing, 'stop').resolves(rawData);
336+
337+
await stopTrace.handler({params: {}}, response, context);
338+
339+
const cruxEndpoint =
340+
'https://chromeuxreport.googleapis.com/v1/records:queryRecord';
341+
const cruxCall = (globalThis.fetch as sinon.SinonStub)
342+
.getCalls()
343+
.find(call => call.args[0].toString().startsWith(cruxEndpoint));
344+
assert.strictEqual(
345+
cruxCall,
346+
undefined,
347+
'CrUX fetch should not have been called',
348+
);
349+
},
350+
{performanceCrux: false},
351+
);
352+
});
328353
});
329354
});
330355

tests/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,11 @@ export async function withBrowser(
8080

8181
export async function withMcpContext(
8282
cb: (response: McpResponse, context: McpContext) => Promise<void>,
83-
options: {debug?: boolean; autoOpenDevTools?: boolean} = {},
83+
options: {
84+
debug?: boolean;
85+
autoOpenDevTools?: boolean;
86+
performanceCrux?: boolean;
87+
} = {},
8488
) {
8589
await withBrowser(async browser => {
8690
const response = new McpResponse();
@@ -92,6 +96,7 @@ export async function withMcpContext(
9296
logger('test'),
9397
{
9498
experimentalDevToolsDebugging: false,
99+
performanceCrux: options.performanceCrux ?? true,
95100
},
96101
Locator,
97102
);

0 commit comments

Comments
 (0)