Skip to content

Commit 7d8ae17

Browse files
committed
works
Change-Id: I2b5dcda9b32db8ec0ca1270e267edfeb562ff7b5
1 parent 44687f9 commit 7d8ae17

5 files changed

Lines changed: 58 additions & 49 deletions

File tree

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tools/performance.ts

Lines changed: 32 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -194,50 +194,37 @@ async function stopTracingAndAppendOutput(
194194
}
195195

196196
async function populateCruxData(result: TraceResult): Promise<void> {
197-
try {
198-
logger('populateCruxData called');
199-
const cruxManager = DevTools.CrUXManager.CrUXManager.instance();
200-
cruxManager.setEndpointForTesting(
201-
'https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=AIzaSyBn5gimNjhiEyA_euicSKko6IlD3HdgUfk',
202-
);
203-
const settings = DevTools.Common.Settings.Settings.instance();
204-
const cruxSetting = settings.createSetting('field-data', {enabled: true});
205-
206-
if (!cruxSetting.get().enabled) {
207-
logger('CrUX is disabled in settings');
208-
return;
209-
}
210-
211-
const urls = new Set<string>();
212-
if (result.insights) {
213-
for (const insightSet of result.insights.values()) {
214-
urls.add(insightSet.url.href);
215-
}
216-
} else {
217-
const mainUrl = result.parsedTrace.data.Meta.mainFrameURL;
218-
if (mainUrl) {
219-
urls.add(mainUrl);
220-
}
221-
}
222-
223-
if (urls.size === 0) {
224-
logger('No URLs found for CrUX data');
225-
return;
226-
}
227-
228-
logger(
229-
`Fetching CrUX data for ${urls.size} URLs: ${Array.from(urls).join(', ')}`,
230-
);
231-
const cruxData = await Promise.all(
232-
Array.from(urls).map(async url => {
233-
const data = await cruxManager.getFieldDataForPage(url);
234-
logger(`CrUX data for ${url}: ${data ? 'found' : 'not found'}`);
235-
return data;
236-
}),
237-
);
238-
239-
result.parsedTrace.metadata.cruxFieldData = cruxData;
240-
} catch (err) {
241-
logger('Error populating CrUX data:', err);
197+
logger('populateCruxData called');
198+
const cruxManager = DevTools.CrUXManager.CrUXManager.instance();
199+
// go/jtfbx
200+
cruxManager.setEndpointForTesting(
201+
'https://chromeuxreport.googleapis.com/v1/records:queryRecord?key=AIzaSyBn5gimNjhiEyA_euicSKko6IlD3HdgUfk',
202+
);
203+
const settings = DevTools.Common.Settings.Settings.instance();
204+
const cruxSetting = settings.createSetting('field-data', {enabled: true});
205+
cruxSetting.set({enabled: true});
206+
207+
// Gather URLs to fetch CrUX data for
208+
const urls = [...(result.parsedTrace.insights?.values() ?? [])].map(c =>
209+
c.url.toString(),
210+
);
211+
urls.push(result.parsedTrace.data.Meta.mainFrameURL);
212+
const urlSet = new Set(urls);
213+
214+
if (urlSet.size === 0) {
215+
logger('No URLs found for CrUX data');
216+
return;
242217
}
218+
logger(
219+
`Fetching CrUX data for ${urlSet.size} URLs: ${Array.from(urlSet).join(', ')}`,
220+
);
221+
const cruxData = await Promise.all(
222+
Array.from(urlSet).map(async url => {
223+
const data = await cruxManager.getFieldDataForPage(url);
224+
logger(`CrUX data for ${url}: ${data ? 'found' : 'not found'}`);
225+
return data;
226+
}),
227+
);
228+
229+
result.parsedTrace.metadata.cruxFieldData = cruxData;
243230
}

tests/McpResponse.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ exports[`McpResponse > adds throttling setting when it is not null 1`] = `
7171
# test response
7272
## Network emulation
7373
Emulating: Slow 3G
74-
Default navigation timeout set to 100000 ms
74+
Default navigation timeout set to 600000 ms
7575
`;
7676

7777
exports[`McpResponse > allows response text lines to be added 1`] = `

tests/tools/performance.test.js.snapshot

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ Metrics (lab / observed):
7373
- Load duration: 15 ms, bounds: {min: 122411037986, max: 122411052690}
7474
- Render delay: 73 ms, bounds: {min: 122411052690, max: 122411126100}
7575
- CLS: 0.00
76-
Metrics (field / real users): n/a – no data for this page in CrUX
76+
Metrics (field / real users):
77+
- LCP: 2595 ms (scope: url)
78+
- LCP breakdown:
79+
- TTFB: 1273 ms (scope: url)
80+
- Load delay: 86 ms (scope: url)
81+
- Load duration: 451 ms (scope: url)
82+
- Render delay: 786 ms (scope: url)
83+
- INP: 140 ms (scope: url)
84+
- CLS: 0.06 (scope: url)
85+
- The above data is from CrUX–Chrome User Experience Report. It's how the page performs for real users.
86+
- The values shown above are the p75 measure of all real Chrome users
87+
- The scope indicates if the data came from the entire origin, or a specific url
88+
- Lab metrics describe how this specific page load performed, while field metrics are an aggregation of results from real-world users. Best practice is to prioritize metrics that are bad in field data. Lab metrics may be better or worse than fields metrics depending on the developer's machine, network, or the actions performed while tracing.
7789
Available insights:
7890
- insight name: LCPBreakdown
7991
description: Each [subpart has specific improvement strategies](https://developer.chrome.com/docs/performance/insights/lcp-breakdown). Ideally, most of the LCP time should be spent on loading the resources, not within delays.

tests/tools/performance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('performance', () => {
7575
});
7676
});
7777

78-
it.only('can autostop and store a recording', async () => {
78+
it('can autostop and store a recording', async () => {
7979
const rawData = loadTraceAsBuffer('basic-trace.json.gz');
8080

8181
await withMcpContext(async (response, context) => {

0 commit comments

Comments
 (0)