@paulirish/trace_engine 0.0.61 → 0.0.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.tmp/tsbuildinfo/analyze-trace.d.mts.map +1 -1
- package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
- package/analyze-inspector-issues.mjs +1 -1
- package/analyze-trace.mjs +1 -2
- package/core/platform/ArrayUtilities.d.ts +2 -0
- package/core/platform/ArrayUtilities.js +11 -1
- package/core/platform/ArrayUtilities.js.map +1 -1
- package/core/platform/HostRuntime.d.ts +4 -0
- package/core/platform/HostRuntime.js +25 -0
- package/core/platform/HostRuntime.js.map +1 -0
- package/core/platform/KeyboardUtilities.d.ts +6 -2
- package/core/platform/KeyboardUtilities.js.map +1 -1
- package/core/platform/StringUtilities.d.ts +2 -0
- package/core/platform/StringUtilities.js +64 -13
- package/core/platform/StringUtilities.js.map +1 -1
- package/core/platform/api/HostRuntime.d.ts +36 -0
- package/core/platform/api/HostRuntime.js +5 -0
- package/core/platform/api/HostRuntime.js.map +1 -0
- package/core/platform/api/api-tsconfig.json +43 -0
- package/core/platform/api/api.d.ts +2 -0
- package/core/platform/api/api.js +6 -0
- package/core/platform/api/api.js.map +1 -0
- package/core/platform/api/api_node_typecheck-tsconfig.json +48 -0
- package/core/platform/api/bundle-tsconfig.json +1 -0
- package/core/platform/api/devtools_entrypoint-bundle-typescript-tsconfig.json +48 -0
- package/core/platform/browser/HostRuntime.d.ts +2 -0
- package/core/platform/browser/HostRuntime.js +64 -0
- package/core/platform/browser/HostRuntime.js.map +1 -0
- package/core/platform/browser/browser-tsconfig.json +48 -0
- package/core/platform/browser/browser.d.ts +2 -0
- package/core/platform/browser/browser.js +6 -0
- package/core/platform/browser/browser.js.map +1 -0
- package/core/platform/browser/bundle-tsconfig.json +1 -0
- package/core/platform/browser/devtools_entrypoint-bundle-typescript-tsconfig.json +48 -0
- package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/core/platform/node/HostRuntime.d.ts +2 -0
- package/core/platform/node/HostRuntime.js +73 -0
- package/core/platform/node/HostRuntime.js.map +1 -0
- package/core/platform/node/bundle-tsconfig.json +1 -0
- package/core/platform/node/devtools_entrypoint-bundle-typescript-tsconfig.json +48 -0
- package/core/platform/node/node-tsconfig.json +52 -0
- package/core/platform/node/node.d.ts +2 -0
- package/core/platform/node/node.js +6 -0
- package/core/platform/node/node.js.map +1 -0
- package/core/platform/platform-tsconfig.json +17 -5
- package/core/platform/platform.d.ts +2 -2
- package/core/platform/platform.js +2 -2
- package/core/platform/platform.js.map +1 -1
- package/core/platform/platform_node_typecheck-tsconfig.json +74 -0
- package/generated/protocol.d.ts +1507 -583
- package/locales/af.json +74 -38
- package/locales/am.json +73 -37
- package/locales/ar.json +72 -36
- package/locales/as.json +74 -38
- package/locales/az.json +73 -37
- package/locales/be.json +72 -36
- package/locales/bg.json +72 -36
- package/locales/bn.json +74 -38
- package/locales/bs.json +72 -36
- package/locales/ca.json +72 -36
- package/locales/cs.json +72 -36
- package/locales/cy.json +73 -37
- package/locales/da.json +74 -38
- package/locales/de.json +72 -36
- package/locales/el.json +73 -37
- package/locales/en-GB.json +74 -38
- package/locales/en-US.json +86 -17
- package/locales/en-XL.json +86 -17
- package/locales/es-419.json +72 -36
- package/locales/es.json +73 -37
- package/locales/et.json +74 -38
- package/locales/eu.json +72 -36
- package/locales/fa.json +73 -37
- package/locales/fi.json +72 -36
- package/locales/fil.json +74 -38
- package/locales/fr-CA.json +72 -36
- package/locales/fr.json +162 -126
- package/locales/gl.json +73 -37
- package/locales/gu.json +73 -37
- package/locales/he.json +74 -38
- package/locales/hi.json +73 -37
- package/locales/hr.json +72 -36
- package/locales/hu.json +73 -37
- package/locales/hy.json +73 -37
- package/locales/id.json +74 -38
- package/locales/is.json +73 -37
- package/locales/it.json +72 -36
- package/locales/ja.json +72 -36
- package/locales/ka.json +73 -37
- package/locales/kk.json +72 -36
- package/locales/km.json +73 -37
- package/locales/kn.json +72 -36
- package/locales/ko.json +72 -36
- package/locales/ky.json +72 -36
- package/locales/lo.json +72 -36
- package/locales/lt.json +72 -36
- package/locales/lv.json +72 -36
- package/locales/mk.json +75 -39
- package/locales/ml.json +72 -36
- package/locales/mn.json +73 -37
- package/locales/mr.json +74 -38
- package/locales/ms.json +72 -36
- package/locales/my.json +72 -36
- package/locales/ne.json +73 -37
- package/locales/nl.json +73 -37
- package/locales/no.json +72 -36
- package/locales/or.json +72 -36
- package/locales/pa.json +72 -36
- package/locales/pl.json +72 -36
- package/locales/pt-PT.json +72 -36
- package/locales/pt.json +74 -38
- package/locales/ro.json +72 -36
- package/locales/ru.json +72 -36
- package/locales/si.json +72 -36
- package/locales/sk.json +72 -36
- package/locales/sl.json +72 -36
- package/locales/sq.json +72 -36
- package/locales/sr-Latn.json +73 -37
- package/locales/sr.json +73 -37
- package/locales/sv.json +75 -39
- package/locales/sw.json +74 -38
- package/locales/ta.json +73 -37
- package/locales/te.json +72 -36
- package/locales/th.json +73 -37
- package/locales/tr.json +72 -36
- package/locales/uk.json +72 -36
- package/locales/ur.json +72 -36
- package/locales/uz.json +73 -37
- package/locales/vi.json +74 -38
- package/locales/zh-HK.json +72 -36
- package/locales/zh-TW.json +74 -38
- package/locales/zh.json +75 -39
- package/locales/zu.json +73 -37
- package/models/cpu_profile/CPUProfileDataModel.d.ts +9 -0
- package/models/cpu_profile/CPUProfileDataModel.js +9 -7
- package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
- package/models/cpu_profile/ProfileTreeModel.d.ts +3 -2
- package/models/cpu_profile/ProfileTreeModel.js +6 -7
- package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
- package/models/cpu_profile/cpu_profile-tsconfig.json +4 -3
- package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/EntityMapper.d.ts +1 -0
- package/models/trace/EntityMapper.js +10 -0
- package/models/trace/EntityMapper.js.map +1 -1
- package/models/trace/EventsSerializer.js +10 -2
- package/models/trace/EventsSerializer.js.map +1 -1
- package/models/trace/LanternComputationData.d.ts +1 -1
- package/models/trace/LanternComputationData.js +3 -8
- package/models/trace/LanternComputationData.js.map +1 -1
- package/models/trace/ModelImpl.d.ts +1 -0
- package/models/trace/ModelImpl.js +9 -6
- package/models/trace/ModelImpl.js.map +1 -1
- package/models/trace/Processor.js +23 -23
- package/models/trace/Processor.js.map +1 -1
- package/models/trace/Styles.js +13 -5
- package/models/trace/Styles.js.map +1 -1
- package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/extras/Initiators.d.ts +12 -0
- package/models/trace/extras/Initiators.js +47 -0
- package/models/trace/extras/Initiators.js.map +1 -0
- package/models/trace/extras/TraceTree.js +13 -5
- package/models/trace/extras/TraceTree.js.map +1 -1
- package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/extras/extras-tsconfig.json +11 -3
- package/models/trace/extras/extras.d.ts +0 -1
- package/models/trace/extras/extras.js +0 -1
- package/models/trace/extras/extras.js.map +1 -1
- package/models/trace/handlers/LargestImagePaintHandler.js +2 -2
- package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.js +1 -1
- package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
- package/models/trace/handlers/MetaHandler.d.ts +12 -1
- package/models/trace/handlers/MetaHandler.js +10 -1
- package/models/trace/handlers/MetaHandler.js.map +1 -1
- package/models/trace/handlers/NetworkRequestsHandler.d.ts +8 -1
- package/models/trace/handlers/NetworkRequestsHandler.js +22 -4
- package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
- package/models/trace/handlers/PageLoadMetricsHandler.d.ts +13 -3
- package/models/trace/handlers/PageLoadMetricsHandler.js +71 -27
- package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
- package/models/trace/handlers/SamplesHandler.js +59 -6
- package/models/trace/handlers/SamplesHandler.js.map +1 -1
- package/models/trace/handlers/ScriptsHandler.js +24 -0
- package/models/trace/handlers/ScriptsHandler.js.map +1 -1
- package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/handlers/handlers-tsconfig.json +13 -3
- package/models/trace/helpers/Network.js +1 -1
- package/models/trace/helpers/Network.js.map +1 -1
- package/models/trace/helpers/SamplesIntegrator.js +1 -8
- package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
- package/models/trace/helpers/Timing.d.ts +1 -1
- package/models/trace/helpers/Timing.js +9 -2
- package/models/trace/helpers/Timing.js.map +1 -1
- package/models/trace/helpers/Trace.d.ts +1 -0
- package/models/trace/helpers/Trace.js +12 -5
- package/models/trace/helpers/Trace.js.map +1 -1
- package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/helpers/helpers-tsconfig.json +7 -3
- package/models/trace/insights/CharacterSet.d.ts +49 -0
- package/models/trace/insights/CharacterSet.js +132 -0
- package/models/trace/insights/CharacterSet.js.map +1 -0
- package/models/trace/insights/Common.d.ts +2 -2
- package/models/trace/insights/Common.js +1 -6
- package/models/trace/insights/Common.js.map +1 -1
- package/models/trace/insights/ForcedReflow.d.ts +1 -1
- package/models/trace/insights/ForcedReflow.js +1 -1
- package/models/trace/insights/ForcedReflow.js.map +1 -1
- package/models/trace/insights/LCPBreakdown.d.ts +1 -1
- package/models/trace/insights/LCPBreakdown.js +2 -2
- package/models/trace/insights/LCPBreakdown.js.map +1 -1
- package/models/trace/insights/LCPDiscovery.d.ts +7 -3
- package/models/trace/insights/LCPDiscovery.js +16 -10
- package/models/trace/insights/LCPDiscovery.js.map +1 -1
- package/models/trace/insights/Models.d.ts +1 -0
- package/models/trace/insights/Models.js +1 -0
- package/models/trace/insights/Models.js.map +1 -1
- package/models/trace/insights/NetworkDependencyTree.js +4 -3
- package/models/trace/insights/NetworkDependencyTree.js.map +1 -1
- package/models/trace/insights/RenderBlocking.d.ts +2 -2
- package/models/trace/insights/RenderBlocking.js +6 -6
- package/models/trace/insights/RenderBlocking.js.map +1 -1
- package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/insights/insights-tsconfig.json +26 -3
- package/models/trace/insights/types.d.ts +15 -5
- package/models/trace/insights/types.js +1 -0
- package/models/trace/insights/types.js.map +1 -1
- package/models/trace/lantern/core/core-tsconfig.json +4 -3
- package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/graph/graph-tsconfig.json +4 -3
- package/models/trace/lantern/lantern-tsconfig.json +4 -3
- package/models/trace/lantern/metrics/FirstContentfulPaint.js +6 -6
- package/models/trace/lantern/metrics/FirstContentfulPaint.js.map +1 -1
- package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/metrics/metrics-tsconfig.json +4 -3
- package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/simulation/simulation-tsconfig.json +4 -3
- package/models/trace/lantern/types/Lantern.d.ts +7 -7
- package/models/trace/lantern/types/Lantern.js.map +1 -1
- package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/lantern/types/types-tsconfig.json +4 -3
- package/models/trace/trace-tsconfig.json +7 -3
- package/models/trace/types/Configuration.d.ts +1 -4
- package/models/trace/types/Configuration.js +0 -1
- package/models/trace/types/Configuration.js.map +1 -1
- package/models/trace/types/File.d.ts +8 -0
- package/models/trace/types/File.js.map +1 -1
- package/models/trace/types/TraceEvents.d.ts +97 -15
- package/models/trace/types/TraceEvents.js +44 -11
- package/models/trace/types/TraceEvents.js.map +1 -1
- package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +4 -3
- package/models/trace/types/types-tsconfig.json +10 -3
- package/package.json +1 -1
- package/test/test-trace-engine.mjs +8 -9
- package/.tmp/tsbuildinfo/models/trace/extras/polyfills.d.ts +0 -4
- package/.tmp/tsbuildinfo/models/trace/extras/polyfills.d.ts.map +0 -1
- package/core/platform/DOMUtilities.d.ts +0 -16
- package/core/platform/DOMUtilities.js +0 -123
- package/core/platform/DOMUtilities.js.map +0 -1
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Copyright 2026 The Chromium Authors
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
// import * as i18n from '../../../core/i18n/i18n.js';
|
|
5
|
+
import { InsightCategory, InsightKeys, InsightWarning, } from './types.js';
|
|
6
|
+
export const UIStrings = {
|
|
7
|
+
/**
|
|
8
|
+
* @description Title of an insight that checks whether the page declares a character encoding early enough.
|
|
9
|
+
*/
|
|
10
|
+
title: 'Declare a character encoding',
|
|
11
|
+
/**
|
|
12
|
+
* @description Description of an insight that checks whether the page has a proper character encoding declaration via HTTP header or early meta tag.
|
|
13
|
+
*/
|
|
14
|
+
description: 'A character encoding declaration is required. It can be done with a meta charset tag in the first 1024 bytes of the HTML or in the Content-Type HTTP response header. [Learn more about declaring the character encoding](https://developer.chrome.com/docs/insights/charset/).',
|
|
15
|
+
/**
|
|
16
|
+
* @description Text to tell the user that the charset is declared in the Content-Type HTTP response header.
|
|
17
|
+
*/
|
|
18
|
+
passingHttpHeader: 'Declares charset in HTTP header',
|
|
19
|
+
/**
|
|
20
|
+
* @description Text to tell the user that the charset is NOT declared in the Content-Type HTTP response header.
|
|
21
|
+
*/
|
|
22
|
+
failedHttpHeader: 'Does not declare charset in HTTP header',
|
|
23
|
+
/**
|
|
24
|
+
* @description Text to tell the user that a meta charset tag was found in the first 1024 bytes of the HTML.
|
|
25
|
+
*/
|
|
26
|
+
passingMetaCharsetEarly: 'Declares charset using a meta tag in the first 1024 bytes',
|
|
27
|
+
/**
|
|
28
|
+
* @description Text to tell the user that a meta charset tag was found, but too late in the HTML.
|
|
29
|
+
*/
|
|
30
|
+
failedMetaCharsetLate: 'Declares charset using a meta tag after the first 1024 bytes',
|
|
31
|
+
/**
|
|
32
|
+
* @description Text to tell the user that no meta charset tag was found in the HTML.
|
|
33
|
+
*/
|
|
34
|
+
failedMetaCharsetMissing: 'Does not declare charset using a meta tag',
|
|
35
|
+
/**
|
|
36
|
+
* @description Text to tell the user that trace data did not include the Blink signal for meta charset.
|
|
37
|
+
*/
|
|
38
|
+
failedMetaCharsetUnknown: 'Could not determine meta charset declaration from trace',
|
|
39
|
+
};
|
|
40
|
+
// const str_ = i18n.i18n.registerUIStrings('models/trace/insights/CharacterSet.ts', UIStrings);
|
|
41
|
+
export const i18nString = (i18nId, values) => ({i18nId, values}); // i18n.i18n.getLocalizedString.bind(undefined, str_);
|
|
42
|
+
const CHARSET_HTTP_REGEX = /charset\s*=\s*[a-zA-Z0-9\-_:.()]{2,}/i;
|
|
43
|
+
export function isCharacterSetInsight(model) {
|
|
44
|
+
return model.insightKey === InsightKeys.CHARACTER_SET;
|
|
45
|
+
}
|
|
46
|
+
function finalize(partialModel) {
|
|
47
|
+
let hasFailure = false;
|
|
48
|
+
if (partialModel.data) {
|
|
49
|
+
hasFailure = !partialModel.data.checklist.httpCharset.value && !partialModel.data.checklist.metaCharset.value;
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
insightKey: InsightKeys.CHARACTER_SET,
|
|
53
|
+
strings: UIStrings,
|
|
54
|
+
title: i18nString(UIStrings.title),
|
|
55
|
+
description: i18nString(UIStrings.description),
|
|
56
|
+
docs: 'https://developer.chrome.com/docs/insights/charset/',
|
|
57
|
+
category: InsightCategory.ALL,
|
|
58
|
+
state: hasFailure ? 'fail' : 'pass',
|
|
59
|
+
...partialModel,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function hasCharsetInContentType(request) {
|
|
63
|
+
if (!request.args.data.responseHeaders) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
for (const header of request.args.data.responseHeaders) {
|
|
67
|
+
if (header.name.toLowerCase() === 'content-type') {
|
|
68
|
+
return CHARSET_HTTP_REGEX.test(header.value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
function findMetaCharsetDisposition(data, context) {
|
|
74
|
+
if (!context.navigation) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return data.PageLoadMetrics.metaCharsetCheckEventsByNavigation.get(context.navigation)
|
|
78
|
+
?.at(-1)
|
|
79
|
+
?.args.data?.disposition;
|
|
80
|
+
}
|
|
81
|
+
function metaCharsetLabel(disposition) {
|
|
82
|
+
switch (disposition) {
|
|
83
|
+
case 'found-in-first-1024-bytes':
|
|
84
|
+
return i18nString(UIStrings.passingMetaCharsetEarly);
|
|
85
|
+
case 'found-after-first-1024-bytes':
|
|
86
|
+
return i18nString(UIStrings.failedMetaCharsetLate);
|
|
87
|
+
case 'not-found':
|
|
88
|
+
return i18nString(UIStrings.failedMetaCharsetMissing);
|
|
89
|
+
default:
|
|
90
|
+
return i18nString(UIStrings.failedMetaCharsetUnknown);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function generateInsight(data, context) {
|
|
94
|
+
if (!context.navigation) {
|
|
95
|
+
return finalize({});
|
|
96
|
+
}
|
|
97
|
+
const documentRequest = data.NetworkRequests.byId.get(context.navigationId);
|
|
98
|
+
if (!documentRequest) {
|
|
99
|
+
return finalize({ warnings: [InsightWarning.NO_DOCUMENT_REQUEST] });
|
|
100
|
+
}
|
|
101
|
+
const hasHttpCharset = hasCharsetInContentType(documentRequest);
|
|
102
|
+
const metaCharsetDisposition = findMetaCharsetDisposition(data, context);
|
|
103
|
+
const hasMetaCharsetInFirst1024Bytes = metaCharsetDisposition === 'found-in-first-1024-bytes';
|
|
104
|
+
return finalize({
|
|
105
|
+
relatedEvents: [documentRequest],
|
|
106
|
+
data: {
|
|
107
|
+
hasHttpCharset,
|
|
108
|
+
metaCharsetDisposition,
|
|
109
|
+
documentRequest,
|
|
110
|
+
checklist: {
|
|
111
|
+
httpCharset: {
|
|
112
|
+
label: hasHttpCharset ? i18nString(UIStrings.passingHttpHeader) : i18nString(UIStrings.failedHttpHeader),
|
|
113
|
+
value: hasHttpCharset,
|
|
114
|
+
},
|
|
115
|
+
metaCharset: {
|
|
116
|
+
label: metaCharsetLabel(metaCharsetDisposition),
|
|
117
|
+
value: hasMetaCharsetInFirst1024Bytes,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export function createOverlays(model) {
|
|
124
|
+
if (!model.data?.documentRequest) {
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
return [{
|
|
128
|
+
type: 'ENTRY_SELECTED',
|
|
129
|
+
entry: model.data.documentRequest,
|
|
130
|
+
}];
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=CharacterSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CharacterSet.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/CharacterSet.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAInD,OAAO,EAEL,eAAe,EACf,WAAW,EAGX,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,8BAA8B;IACrC;;OAEG;IACH,WAAW,EACP,iRAAiR;IACrR;;OAEG;IACH,iBAAiB,EAAE,iCAAiC;IACpD;;OAEG;IACH,gBAAgB,EAAE,yCAAyC;IAC3D;;OAEG;IACH,uBAAuB,EAAE,2DAA2D;IACpF;;OAEG;IACH,qBAAqB,EAAE,8DAA8D;IACrF;;OAEG;IAC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IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,QAAQ,CAAC,EAAC,QAAQ,EAAE,CAAC,cAAc,CAAC,mBAAmB,CAAC,EAAC,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,cAAc,GAAG,uBAAuB,CAAC,eAAe,CAAC,CAAC;IAChE,MAAM,sBAAsB,GAAG,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzE,MAAM,8BAA8B,GAAG,sBAAsB,KAAK,2BAA2B,CAAC;IAE9F,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,CAAC,eAAe,CAAC;QAChC,IAAI,EAAE;YACJ,cAAc;YACd,sBAAsB;YACtB,eAAe;YACf,SAAS,EAAE;gBACT,WAAW,EAAE;oBACX,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC;oBACxG,KAAK,EAAE,cAAc;iBACtB;gBACD,WAAW,EAAE;oBACX,KAAK,EAAE,gBAAgB,CAAC,sBAAsB,CAAC;oBAC/C,KAAK,EAAE,8BAA8B;iBACtC;aACF;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAA+B;IAC5D,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;QACjC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,CAAC;YACN,IAAI,EAAE,gBAAgB;YACtB,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,eAAe;SAClC,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2026 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport type * as Types from '../types/types.js';\n\nimport {\n type Checklist,\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type PartialInsightModel,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that checks whether the page declares a character encoding early enough.\n */\n title: 'Declare a character encoding',\n /**\n * @description Description of an insight that checks whether the page has a proper character encoding declaration via HTTP header or early meta tag.\n */\n description:\n 'A character encoding declaration is required. It can be done with a meta charset tag in the first 1024 bytes of the HTML or in the Content-Type HTTP response header. [Learn more about declaring the character encoding](https://developer.chrome.com/docs/insights/charset/).',\n /**\n * @description Text to tell the user that the charset is declared in the Content-Type HTTP response header.\n */\n passingHttpHeader: 'Declares charset in HTTP header',\n /**\n * @description Text to tell the user that the charset is NOT declared in the Content-Type HTTP response header.\n */\n failedHttpHeader: 'Does not declare charset in HTTP header',\n /**\n * @description Text to tell the user that a meta charset tag was found in the first 1024 bytes of the HTML.\n */\n passingMetaCharsetEarly: 'Declares charset using a meta tag in the first 1024 bytes',\n /**\n * @description Text to tell the user that a meta charset tag was found, but too late in the HTML.\n */\n failedMetaCharsetLate: 'Declares charset using a meta tag after the first 1024 bytes',\n /**\n * @description Text to tell the user that no meta charset tag was found in the HTML.\n */\n failedMetaCharsetMissing: 'Does not declare charset using a meta tag',\n /**\n * @description Text to tell the user that trace data did not include the Blink signal for meta charset.\n */\n failedMetaCharsetUnknown: 'Could not determine meta charset declaration from trace',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/CharacterSet.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nconst CHARSET_HTTP_REGEX = /charset\\s*=\\s*[a-zA-Z0-9\\-_:.()]{2,}/i;\n\nexport type CharacterSetInsightModel = InsightModel<typeof UIStrings, {\n data?: {\n hasHttpCharset: boolean,\n checklist: Checklist<'httpCharset'|'metaCharset'>,\n metaCharsetDisposition?: Types.Events.MetaCharsetDisposition,\n documentRequest?: Types.Events.SyntheticNetworkRequest,\n },\n}>;\n\nexport function isCharacterSetInsight(model: InsightModel): model is CharacterSetInsightModel {\n return model.insightKey === InsightKeys.CHARACTER_SET;\n}\n\nfunction finalize(partialModel: PartialInsightModel<CharacterSetInsightModel>): CharacterSetInsightModel {\n let hasFailure = false;\n if (partialModel.data) {\n hasFailure = !partialModel.data.checklist.httpCharset.value && !partialModel.data.checklist.metaCharset.value;\n }\n\n return {\n insightKey: InsightKeys.CHARACTER_SET,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/insights/charset/',\n category: InsightCategory.ALL,\n state: hasFailure ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction hasCharsetInContentType(request: Types.Events.SyntheticNetworkRequest): boolean {\n if (!request.args.data.responseHeaders) {\n return false;\n }\n for (const header of request.args.data.responseHeaders) {\n if (header.name.toLowerCase() === 'content-type') {\n return CHARSET_HTTP_REGEX.test(header.value);\n }\n }\n return false;\n}\n\nfunction findMetaCharsetDisposition(\n data: Handlers.Types.HandlerData,\n context: InsightSetContext,\n ): Types.Events.MetaCharsetDisposition|undefined {\n if (!context.navigation) {\n return undefined;\n }\n return data.PageLoadMetrics.metaCharsetCheckEventsByNavigation.get(context.navigation)\n ?.at(-1)\n ?.args.data?.disposition;\n}\n\nfunction metaCharsetLabel(disposition: Types.Events.MetaCharsetDisposition|undefined): ReturnType<typeof i18nString> {\n switch (disposition) {\n case 'found-in-first-1024-bytes':\n return i18nString(UIStrings.passingMetaCharsetEarly);\n case 'found-after-first-1024-bytes':\n return i18nString(UIStrings.failedMetaCharsetLate);\n case 'not-found':\n return i18nString(UIStrings.failedMetaCharsetMissing);\n default:\n return i18nString(UIStrings.failedMetaCharsetUnknown);\n }\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): CharacterSetInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const documentRequest = data.NetworkRequests.byId.get(context.navigationId);\n if (!documentRequest) {\n return finalize({warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n const hasHttpCharset = hasCharsetInContentType(documentRequest);\n const metaCharsetDisposition = findMetaCharsetDisposition(data, context);\n const hasMetaCharsetInFirst1024Bytes = metaCharsetDisposition === 'found-in-first-1024-bytes';\n\n return finalize({\n relatedEvents: [documentRequest],\n data: {\n hasHttpCharset,\n metaCharsetDisposition,\n documentRequest,\n checklist: {\n httpCharset: {\n label: hasHttpCharset ? i18nString(UIStrings.passingHttpHeader) : i18nString(UIStrings.failedHttpHeader),\n value: hasHttpCharset,\n },\n metaCharset: {\n label: metaCharsetLabel(metaCharsetDisposition),\n value: hasMetaCharsetInFirst1024Bytes,\n },\n },\n },\n });\n}\n\nexport function createOverlays(model: CharacterSetInsightModel): Types.Overlays.Overlay[] {\n if (!model.data?.documentRequest) {\n return [];\n }\n\n return [{\n type: 'ENTRY_SELECTED',\n entry: model.data.documentRequest,\n }];\n}\n"]}
|
|
@@ -3,10 +3,10 @@ import * as Protocol from '../../../generated/protocol.js';
|
|
|
3
3
|
import type * as Handlers from '../handlers/handlers.js';
|
|
4
4
|
import * as Types from '../types/types.js';
|
|
5
5
|
import { type InsightModel, type InsightModels, type InsightSet, type InsightSetContext, type MetricSavings } from './types.js';
|
|
6
|
-
export declare function getInsight<InsightName extends keyof InsightModels>(insightName: InsightName, insightSet: InsightSet): InsightModels[InsightName]
|
|
6
|
+
export declare function getInsight<InsightName extends keyof InsightModels>(insightName: InsightName, insightSet: InsightSet): InsightModels[InsightName];
|
|
7
7
|
export declare function getLCP(insightSet: InsightSet): {
|
|
8
8
|
value: Types.Timing.Micro;
|
|
9
|
-
event: Types.Events.
|
|
9
|
+
event: Types.Events.AnyLargestContentfulPaintCandidate;
|
|
10
10
|
} | null;
|
|
11
11
|
export declare function getINP(insightSet: InsightSet): {
|
|
12
12
|
value: Types.Timing.Micro;
|
|
@@ -7,12 +7,7 @@ import { getLogNormalScore } from './Statistics.js';
|
|
|
7
7
|
import { InsightKeys, } from './types.js';
|
|
8
8
|
const GRAPH_SAVINGS_PRECISION = 50;
|
|
9
9
|
export function getInsight(insightName, insightSet) {
|
|
10
|
-
|
|
11
|
-
if (insight instanceof Error) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
// For some reason typescript won't narrow the type by removing Error, so do it manually.
|
|
15
|
-
return insight;
|
|
10
|
+
return insightSet.model[insightName];
|
|
16
11
|
}
|
|
17
12
|
export function getLCP(insightSet) {
|
|
18
13
|
const insight = getInsight(InsightKeys.LCP_BREAKDOWN, insightSet);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Common.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAK7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,WAAW,GAMZ,MAAM,YAAY,CAAC;AAEpB,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAEnC,MAAM,UAAU,UAAU,CACtB,WAAwB,EAAE,UAAsB;IAClD,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC9C,IAAI,OAAO,YAAY,KAAK,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,yFAAyF;IACzF,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,UAAsB;IAE3C,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;IAClE,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,CAAC,M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AAO,IAAI,CAAC;IACd,CAAC;IAED,+CAA+C;IAC/C,8EAA8E;IAC9E,gFAAgF;IAChF,qBAAqB;IACrB,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CACrB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,WAAW,CAAC;QACjD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,mBAAmB,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CACzB,OAAqB,EAAE,gBAA+C;IACxE,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,CAAC;IAClD,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/F,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACxE,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Protocol from '../../../generated/protocol.js';\nimport type * as CrUXManager from '../../crux-manager/crux-manager.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport * as Types from '../types/types.js';\n\nimport {getLogNormalScore} from './Statistics.js';\nimport {\n InsightKeys,\n type InsightModel,\n type InsightModels,\n type InsightSet,\n type InsightSetContext,\n type MetricSavings,\n} from './types.js';\n\nconst GRAPH_SAVINGS_PRECISION = 50;\n\nexport function getInsight<InsightName extends keyof InsightModels>(\n insightName: InsightName, insightSet: InsightSet): InsightModels[InsightName]|null {\n const insight = insightSet.model[insightName];\n if (insight instanceof Error) {\n return null;\n }\n\n // For some reason typescript won't narrow the type by removing Error, so do it manually.\n return insight;\n}\n\nexport function getLCP(insightSet: InsightSet):\n {value: Types.Timing.Micro, event: Types.Events.LargestContentfulPaintCandidate}|null {\n const insight = getInsight(InsightKeys.LCP_BREAKDOWN, insightSet);\n if (!insight || !insight.lcpMs || !insight.lcpEvent) {\n return null;\n }\n\n const value = Helpers.Timing.milliToMicro(insight.lcpMs);\n return {value, event: insight.lcpEvent};\n}\n\nexport function getINP(insightSet: InsightSet):\n {value: Types.Timing.Micro, event: Types.Events.SyntheticInteractionPair}|null {\n const insight = getInsight(InsightKeys.INP_BREAKDOWN, insightSet);\n if (!insight?.longestInteractionEvent?.dur) {\n return null;\n }\n\n const value = insight.longestInteractionEvent.dur;\n return {value, event: insight.longestInteractionEvent};\n}\n\nexport function getCLS(insightSet: InsightSet): {value: number, worstClusterEvent: Types.Events.Event|null} {\n const insight = getInsight(InsightKeys.CLS_CULPRITS, insightSet);\n if (!insight) {\n // Unlike the other metrics, there is always a value for CLS even with no data.\n return {value: 0, worstClusterEvent: null};\n }\n\n // TODO(cjamcl): the CLS insight should be doing this for us.\n let maxScore = 0;\n let worstCluster;\n for (const cluster of insight.clusters) {\n if (cluster.clusterCumulativeScore > maxScore) {\n maxScore = cluster.clusterCumulativeScore;\n worstCluster = cluster;\n }\n }\n\n return {value: maxScore, worstClusterEvent: worstCluster ?? null};\n}\n\nexport function evaluateLCPMetricScore(value: Types.Timing.Milli): number {\n return getLogNormalScore({p10: 2500, median: 4000}, value);\n}\n\nexport function evaluateINPMetricScore(value: Types.Timing.Milli): number {\n return getLogNormalScore({p10: 200, median: 500}, value);\n}\n\nexport function evaluateCLSMetricScore(value: number): number {\n return getLogNormalScore({p10: 0.1, median: 0.25}, value);\n}\n\nexport interface CrUXFieldMetricTimingResult {\n value: Types.Timing.Micro;\n pageScope: CrUXManager.PageScope;\n}\nexport interface CrUXFieldMetricNumberResult {\n value: number;\n pageScope: CrUXManager.PageScope;\n}\nexport interface CrUXFieldMetricResults {\n fcp: CrUXFieldMetricTimingResult|null;\n lcp: CrUXFieldMetricTimingResult|null;\n inp: CrUXFieldMetricTimingResult|null;\n cls: CrUXFieldMetricNumberResult|null;\n lcpBreakdown: {\n ttfb: CrUXFieldMetricTimingResult|null,\n loadDelay: CrUXFieldMetricTimingResult|null,\n loadDuration: CrUXFieldMetricTimingResult|null,\n renderDelay: CrUXFieldMetricTimingResult|null,\n };\n}\n\nfunction getPageResult(\n cruxFieldData: CrUXManager.PageResult[], url: string, origin: string,\n scope: CrUXManager.Scope|null = null): CrUXManager.PageResult|undefined {\n return cruxFieldData.find(result => {\n const key = scope ? result[`${scope.pageScope}-${scope.deviceScope}`]?.record.key :\n (result['url-ALL'] || result['origin-ALL'])?.record.key;\n return (key?.url && key.url === url) || (key?.origin && key.origin === origin);\n });\n}\n\nfunction getMetricResult(\n pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricNumberResult|null {\n const scopes: Array<{pageScope: CrUXManager.PageScope, deviceScope: CrUXManager.DeviceScope}> = [];\n if (scope) {\n scopes.push(scope);\n } else {\n scopes.push({pageScope: 'url', deviceScope: 'ALL'});\n scopes.push({pageScope: 'origin', deviceScope: 'ALL'});\n }\n\n for (const scope of scopes) {\n const key = `${scope.pageScope}-${scope.deviceScope}` as const;\n let value = pageResult[key]?.record.metrics[name]?.percentiles?.p75;\n if (typeof value === 'string') {\n value = Number(value);\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n return {value, pageScope: scope.pageScope};\n }\n }\n\n return null;\n}\n\nfunction getMetricTimingResult(\n pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricTimingResult|null {\n const result = getMetricResult(pageResult, name, scope);\n if (result) {\n const valueMs = result.value as Types.Timing.Milli;\n return {value: Helpers.Timing.milliToMicro(valueMs), pageScope: result.pageScope};\n }\n\n return null;\n}\n\nexport function getFieldMetricsForInsightSet(\n insightSet: InsightSet, metadata: Types.File.MetaData|null,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricResults|null {\n const cruxFieldData = metadata?.cruxFieldData;\n if (!cruxFieldData) {\n return null;\n }\n\n const pageResult = getPageResult(cruxFieldData, insightSet.url.href, insightSet.url.origin, scope);\n if (!pageResult) {\n return null;\n }\n\n return {\n fcp: getMetricTimingResult(pageResult, 'first_contentful_paint', scope),\n lcp: getMetricTimingResult(pageResult, 'largest_contentful_paint', scope),\n inp: getMetricTimingResult(pageResult, 'interaction_to_next_paint', scope),\n cls: getMetricResult(pageResult, 'cumulative_layout_shift', scope),\n lcpBreakdown: {\n ttfb: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_time_to_first_byte', scope),\n loadDelay: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_resource_load_delay', scope),\n loadDuration: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_resource_load_duration', scope),\n renderDelay: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_element_render_delay', scope),\n }\n };\n}\n\nexport function calculateMetricWeightsForSorting(\n insightSet: InsightSet, metadata: Types.File.MetaData|null): {lcp: number, inp: number, cls: number} {\n const weights = {\n lcp: 1 / 3,\n inp: 1 / 3,\n cls: 1 / 3,\n };\n\n const cruxFieldData = metadata?.cruxFieldData;\n if (!cruxFieldData) {\n return weights;\n }\n\n const fieldMetrics = getFieldMetricsForInsightSet(insightSet, metadata);\n if (!fieldMetrics) {\n return weights;\n }\n\n const fieldLcp = fieldMetrics.lcp?.value ?? null;\n const fieldInp = fieldMetrics.inp?.value ?? null;\n const fieldCls = fieldMetrics.cls?.value ?? null;\n const fieldLcpScore = fieldLcp !== null ? evaluateLCPMetricScore(Helpers.Timing.microToMilli(fieldLcp)) : 0;\n const fieldInpScore = fieldInp !== null ? evaluateINPMetricScore(Helpers.Timing.microToMilli(fieldInp)) : 0;\n const fieldClsScore = fieldCls !== null ? evaluateCLSMetricScore(fieldCls) : 0;\n const fieldLcpScoreInverted = 1 - fieldLcpScore;\n const fieldInpScoreInverted = 1 - fieldInpScore;\n const fieldClsScoreInverted = 1 - fieldClsScore;\n const invertedSum = fieldLcpScoreInverted + fieldInpScoreInverted + fieldClsScoreInverted;\n if (!invertedSum) {\n return weights;\n }\n\n weights.lcp = fieldLcpScoreInverted / invertedSum;\n weights.inp = fieldInpScoreInverted / invertedSum;\n weights.cls = fieldClsScoreInverted / invertedSum;\n\n return weights;\n}\n\n/**\n * Simulates the provided graph before and after the byte savings from `wastedBytesByRequestId` are applied.\n */\nfunction estimateSavingsWithGraphs(\n wastedBytesByRequestId: Map<string, number>, simulator: Lantern.Simulation.Simulator,\n graph: Lantern.Graph.Node): Types.Timing.Milli {\n const simulationBeforeChanges = simulator.simulate(graph);\n\n const originalTransferSizes = new Map<string, number>();\n graph.traverse(node => {\n if (node.type !== 'network') {\n return;\n }\n const wastedBytes = wastedBytesByRequestId.get(node.request.requestId);\n if (!wastedBytes) {\n return;\n }\n\n const original = node.request.transferSize;\n originalTransferSizes.set(node.request.requestId, original);\n\n node.request.transferSize = Math.max(original - wastedBytes, 0);\n });\n\n const simulationAfterChanges = simulator.simulate(graph);\n\n // Restore the original transfer size after we've done our simulation\n graph.traverse(node => {\n if (node.type !== 'network') {\n return;\n }\n const originalTransferSize = originalTransferSizes.get(node.request.requestId);\n if (originalTransferSize === undefined) {\n return;\n }\n node.request.transferSize = originalTransferSize;\n });\n\n let savings = simulationBeforeChanges.timeInMs - simulationAfterChanges.timeInMs;\n savings = Math.round(savings / GRAPH_SAVINGS_PRECISION) * GRAPH_SAVINGS_PRECISION;\n return Types.Timing.Milli(savings);\n}\n\n/**\n * Estimates the FCP & LCP savings for wasted bytes in `wastedBytesByRequestId`.\n */\nexport function metricSavingsForWastedBytes(\n wastedBytesByRequestId: Map<string, number>, context: InsightSetContext): MetricSavings|undefined {\n if (!context.navigation || !context.lantern) {\n return;\n }\n\n if (!wastedBytesByRequestId.size) {\n return {FCP: Types.Timing.Milli(0), LCP: Types.Timing.Milli(0)};\n }\n\n const simulator = context.lantern.simulator;\n const fcpGraph = context.lantern.metrics.firstContentfulPaint.optimisticGraph;\n const lcpGraph = context.lantern.metrics.largestContentfulPaint.optimisticGraph;\n\n return {\n FCP: estimateSavingsWithGraphs(wastedBytesByRequestId, simulator, fcpGraph),\n LCP: estimateSavingsWithGraphs(wastedBytesByRequestId, simulator, lcpGraph),\n };\n}\n\n/**\n * Returns whether the network request was sent encoded.\n */\nexport function isRequestCompressed(request: Types.Events.SyntheticNetworkRequest): boolean {\n if (!request.args.data.responseHeaders) {\n return false;\n }\n\n // FYI: In Lighthouse, older devtools logs (like our test fixtures) seems to be\n // lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i, /^x-content-encoding-over-network$/i,\n /^x-original-content-encoding$/i, // Lightrider.\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n return request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n}\n\nexport function isRequestServedFromBrowserCache(request: Types.Events.SyntheticNetworkRequest): boolean {\n if (!request.args.data.responseHeaders || request.args.data.failed) {\n return false;\n }\n\n // Not Modified?\n if (request.args.data.statusCode === 304) {\n return true;\n }\n\n // TODO: for some reason ResourceReceiveResponse events never show a 304 status\n // code, so the above is never gonna work. For now, fall back to a dirty check of\n // looking at the ratio of transfer size and resource size. If it's really small,\n // we certainly did not use the network to fetch it.\n\n const {transferSize, resourceSize} = getRequestSizes(request);\n const ratio = resourceSize ? transferSize / resourceSize : 0;\n if (ratio < 0.01) {\n return true;\n }\n\n return false;\n}\n\nfunction getRequestSizes(request: Types.Events.SyntheticNetworkRequest): {resourceSize: number, transferSize: number} {\n const resourceSize = request.args.data.decodedBodyLength;\n const transferSize = request.args.data.encodedDataLength;\n return {resourceSize, transferSize};\n}\n\n/**\n * Estimates the number of bytes the content of this network record would have consumed on the network based on the\n * uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable,\n * minus the size of the response headers.\n *\n * @param totalBytes Uncompressed size of the resource\n */\nexport function estimateCompressedContentSize(\n request: Types.Events.SyntheticNetworkRequest|undefined, totalBytes: number,\n resourceType: Protocol.Network.ResourceType): number {\n if (!request || isRequestServedFromBrowserCache(request)) {\n // We don't know how many bytes this asset used on the network, but we can guess it was\n // roughly the size of the content gzipped.\n // See https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/optimize-encoding-and-transfer for specific CSS/Script examples\n // See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for fallback multipliers\n switch (resourceType) {\n case 'Stylesheet':\n // Stylesheets tend to compress extremely well.\n return Math.round(totalBytes * 0.2);\n case 'Script':\n case 'Document':\n // Scripts and HTML compress fairly well too.\n return Math.round(totalBytes * 0.33);\n default:\n // Otherwise we'll just fallback to the average savings in HTTPArchive\n return Math.round(totalBytes * 0.5);\n }\n }\n\n // Get the size of the response body on the network.\n const {transferSize, resourceSize} = getRequestSizes(request);\n let contentTransferSize = transferSize;\n if (!isRequestCompressed(request)) {\n // This is not compressed, so we can use resourceSize directly.\n // This would be equivalent to transfer size minus headers transfer size, but transfer size\n // may also include bytes for SSL connection etc.\n contentTransferSize = resourceSize;\n }\n // TODO(cjamcl): Get \"responseHeadersTransferSize\" in Network handler.\n // else if (request.responseHeadersTransferSize) {\n // // Subtract the size of the encoded headers.\n // contentTransferSize =\n // Math.max(0, contentTransferSize - request.responseHeadersTransferSize);\n // }\n\n if (request.args.data.resourceType === resourceType) {\n // This was a regular standalone asset, just use the transfer size.\n return contentTransferSize;\n }\n\n // This was an asset that was inlined in a different resource type (e.g. HTML document).\n // Use the compression ratio of the resource to estimate the total transferred bytes.\n // Get the compression ratio, if it's an invalid number, assume no compression.\n const compressionRatio = Number.isFinite(resourceSize) && resourceSize > 0 ? (contentTransferSize / resourceSize) : 1;\n return Math.round(totalBytes * compressionRatio);\n}\n\n/**\n * Utility function to estimate the ratio of the compression of a script.\n * This excludes the size of the response headers.\n */\nexport function estimateCompressionRatioForScript(script: Handlers.ModelHandlers.Scripts.Script): number {\n if (!script.request) {\n // Can't find request, so just use 1.\n return 1;\n }\n\n const request = script.request;\n const contentLength = request.args.data.decodedBodyLength ?? script.content?.length ?? 0;\n const compressedSize = estimateCompressedContentSize(request, contentLength, Protocol.Network.ResourceType.Script);\n if (contentLength === 0 || compressedSize === 0) {\n return 1;\n }\n\n const compressionRatio = compressedSize / contentLength;\n return compressionRatio;\n}\n\nexport function calculateDocFirstByteTs(docRequest: Types.Events.SyntheticNetworkRequest): Types.Timing.Micro|null {\n if (docRequest.args.data.protocol === 'file') {\n // file: requests do not have timings\n return docRequest.ts;\n }\n\n const timing = docRequest.args.data.timing;\n if (!timing) {\n // Older traces do not have timings.\n return null;\n }\n\n // Time that first byte (headers) are received.\n // For older traces, receiveHeadersStart can be missing (ex: web.dev.json.gz).\n // In that case use the headers end timing, which should be pretty close to when\n // the headers start.\n return Types.Timing.Micro(\n Helpers.Timing.secondsToMicro(timing.requestTime) +\n Helpers.Timing.milliToMicro(timing.receiveHeadersStart ?? timing.receiveHeadersEnd));\n}\n\n/**\n * Calculates the trace bounds for the given insight that are relevant.\n *\n * Uses the insight's overlays to determine the relevant trace bounds. If there are\n * no overlays, falls back to the insight set's navigation bounds.\n */\nexport function insightBounds(\n insight: InsightModel, insightSetBounds: Types.Timing.TraceWindowMicro): Types.Timing.TraceWindowMicro {\n const overlays = insight.createOverlays?.() ?? [];\n const windows = overlays.map(Helpers.Timing.traceWindowFromOverlay).filter(bounds => !!bounds);\n const overlaysBounds = Helpers.Timing.combineTraceWindowsMicro(windows);\n if (overlaysBounds) {\n return overlaysBounds;\n }\n\n return insightSetBounds;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Common.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Common.ts"],"names":[],"mappings":"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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC/F,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACxE,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Protocol from '../../../generated/protocol.js';\nimport type * as CrUXManager from '../../crux-manager/crux-manager.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport * as Types from '../types/types.js';\n\nimport {getLogNormalScore} from './Statistics.js';\nimport {\n InsightKeys,\n type InsightModel,\n type InsightModels,\n type InsightSet,\n type InsightSetContext,\n type MetricSavings,\n} from './types.js';\n\nconst GRAPH_SAVINGS_PRECISION = 50;\n\nexport function getInsight<InsightName extends keyof InsightModels>(\n insightName: InsightName, insightSet: InsightSet): InsightModels[InsightName] {\n return insightSet.model[insightName];\n}\n\nexport function getLCP(insightSet: InsightSet):\n {value: Types.Timing.Micro, event: Types.Events.AnyLargestContentfulPaintCandidate}|null {\n const insight = getInsight(InsightKeys.LCP_BREAKDOWN, insightSet);\n if (!insight || !insight.lcpMs || !insight.lcpEvent) {\n return null;\n }\n\n const value = Helpers.Timing.milliToMicro(insight.lcpMs);\n return {value, event: insight.lcpEvent};\n}\n\nexport function getINP(insightSet: InsightSet):\n {value: Types.Timing.Micro, event: Types.Events.SyntheticInteractionPair}|null {\n const insight = getInsight(InsightKeys.INP_BREAKDOWN, insightSet);\n if (!insight?.longestInteractionEvent?.dur) {\n return null;\n }\n\n const value = insight.longestInteractionEvent.dur;\n return {value, event: insight.longestInteractionEvent};\n}\n\nexport function getCLS(insightSet: InsightSet): {value: number, worstClusterEvent: Types.Events.Event|null} {\n const insight = getInsight(InsightKeys.CLS_CULPRITS, insightSet);\n if (!insight) {\n // Unlike the other metrics, there is always a value for CLS even with no data.\n return {value: 0, worstClusterEvent: null};\n }\n\n // TODO(cjamcl): the CLS insight should be doing this for us.\n let maxScore = 0;\n let worstCluster;\n for (const cluster of insight.clusters) {\n if (cluster.clusterCumulativeScore > maxScore) {\n maxScore = cluster.clusterCumulativeScore;\n worstCluster = cluster;\n }\n }\n\n return {value: maxScore, worstClusterEvent: worstCluster ?? null};\n}\n\nexport function evaluateLCPMetricScore(value: Types.Timing.Milli): number {\n return getLogNormalScore({p10: 2500, median: 4000}, value);\n}\n\nexport function evaluateINPMetricScore(value: Types.Timing.Milli): number {\n return getLogNormalScore({p10: 200, median: 500}, value);\n}\n\nexport function evaluateCLSMetricScore(value: number): number {\n return getLogNormalScore({p10: 0.1, median: 0.25}, value);\n}\n\nexport interface CrUXFieldMetricTimingResult {\n value: Types.Timing.Micro;\n pageScope: CrUXManager.PageScope;\n}\nexport interface CrUXFieldMetricNumberResult {\n value: number;\n pageScope: CrUXManager.PageScope;\n}\nexport interface CrUXFieldMetricResults {\n fcp: CrUXFieldMetricTimingResult|null;\n lcp: CrUXFieldMetricTimingResult|null;\n inp: CrUXFieldMetricTimingResult|null;\n cls: CrUXFieldMetricNumberResult|null;\n lcpBreakdown: {\n ttfb: CrUXFieldMetricTimingResult|null,\n loadDelay: CrUXFieldMetricTimingResult|null,\n loadDuration: CrUXFieldMetricTimingResult|null,\n renderDelay: CrUXFieldMetricTimingResult|null,\n };\n}\n\nfunction getPageResult(\n cruxFieldData: CrUXManager.PageResult[], url: string, origin: string,\n scope: CrUXManager.Scope|null = null): CrUXManager.PageResult|undefined {\n return cruxFieldData.find(result => {\n const key = scope ? result[`${scope.pageScope}-${scope.deviceScope}`]?.record.key :\n (result['url-ALL'] || result['origin-ALL'])?.record.key;\n return (key?.url && key.url === url) || (key?.origin && key.origin === origin);\n });\n}\n\nfunction getMetricResult(\n pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricNumberResult|null {\n const scopes: Array<{pageScope: CrUXManager.PageScope, deviceScope: CrUXManager.DeviceScope}> = [];\n if (scope) {\n scopes.push(scope);\n } else {\n scopes.push({pageScope: 'url', deviceScope: 'ALL'});\n scopes.push({pageScope: 'origin', deviceScope: 'ALL'});\n }\n\n for (const scope of scopes) {\n const key = `${scope.pageScope}-${scope.deviceScope}` as const;\n let value = pageResult[key]?.record.metrics[name]?.percentiles?.p75;\n if (typeof value === 'string') {\n value = Number(value);\n }\n if (typeof value === 'number' && Number.isFinite(value)) {\n return {value, pageScope: scope.pageScope};\n }\n }\n\n return null;\n}\n\nfunction getMetricTimingResult(\n pageResult: CrUXManager.PageResult, name: CrUXManager.StandardMetricNames,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricTimingResult|null {\n const result = getMetricResult(pageResult, name, scope);\n if (result) {\n const valueMs = result.value as Types.Timing.Milli;\n return {value: Helpers.Timing.milliToMicro(valueMs), pageScope: result.pageScope};\n }\n\n return null;\n}\n\nexport function getFieldMetricsForInsightSet(\n insightSet: InsightSet, metadata: Types.File.MetaData|null,\n scope: CrUXManager.Scope|null = null): CrUXFieldMetricResults|null {\n const cruxFieldData = metadata?.cruxFieldData;\n if (!cruxFieldData) {\n return null;\n }\n\n const pageResult = getPageResult(cruxFieldData, insightSet.url.href, insightSet.url.origin, scope);\n if (!pageResult) {\n return null;\n }\n\n return {\n fcp: getMetricTimingResult(pageResult, 'first_contentful_paint', scope),\n lcp: getMetricTimingResult(pageResult, 'largest_contentful_paint', scope),\n inp: getMetricTimingResult(pageResult, 'interaction_to_next_paint', scope),\n cls: getMetricResult(pageResult, 'cumulative_layout_shift', scope),\n lcpBreakdown: {\n ttfb: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_time_to_first_byte', scope),\n loadDelay: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_resource_load_delay', scope),\n loadDuration: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_resource_load_duration', scope),\n renderDelay: getMetricTimingResult(pageResult, 'largest_contentful_paint_image_element_render_delay', scope),\n }\n };\n}\n\nexport function calculateMetricWeightsForSorting(\n insightSet: InsightSet, metadata: Types.File.MetaData|null): {lcp: number, inp: number, cls: number} {\n const weights = {\n lcp: 1 / 3,\n inp: 1 / 3,\n cls: 1 / 3,\n };\n\n const cruxFieldData = metadata?.cruxFieldData;\n if (!cruxFieldData) {\n return weights;\n }\n\n const fieldMetrics = getFieldMetricsForInsightSet(insightSet, metadata);\n if (!fieldMetrics) {\n return weights;\n }\n\n const fieldLcp = fieldMetrics.lcp?.value ?? null;\n const fieldInp = fieldMetrics.inp?.value ?? null;\n const fieldCls = fieldMetrics.cls?.value ?? null;\n const fieldLcpScore = fieldLcp !== null ? evaluateLCPMetricScore(Helpers.Timing.microToMilli(fieldLcp)) : 0;\n const fieldInpScore = fieldInp !== null ? evaluateINPMetricScore(Helpers.Timing.microToMilli(fieldInp)) : 0;\n const fieldClsScore = fieldCls !== null ? evaluateCLSMetricScore(fieldCls) : 0;\n const fieldLcpScoreInverted = 1 - fieldLcpScore;\n const fieldInpScoreInverted = 1 - fieldInpScore;\n const fieldClsScoreInverted = 1 - fieldClsScore;\n const invertedSum = fieldLcpScoreInverted + fieldInpScoreInverted + fieldClsScoreInverted;\n if (!invertedSum) {\n return weights;\n }\n\n weights.lcp = fieldLcpScoreInverted / invertedSum;\n weights.inp = fieldInpScoreInverted / invertedSum;\n weights.cls = fieldClsScoreInverted / invertedSum;\n\n return weights;\n}\n\n/**\n * Simulates the provided graph before and after the byte savings from `wastedBytesByRequestId` are applied.\n */\nfunction estimateSavingsWithGraphs(\n wastedBytesByRequestId: Map<string, number>, simulator: Lantern.Simulation.Simulator,\n graph: Lantern.Graph.Node): Types.Timing.Milli {\n const simulationBeforeChanges = simulator.simulate(graph);\n\n const originalTransferSizes = new Map<string, number>();\n graph.traverse(node => {\n if (node.type !== 'network') {\n return;\n }\n const wastedBytes = wastedBytesByRequestId.get(node.request.requestId);\n if (!wastedBytes) {\n return;\n }\n\n const original = node.request.transferSize;\n originalTransferSizes.set(node.request.requestId, original);\n\n node.request.transferSize = Math.max(original - wastedBytes, 0);\n });\n\n const simulationAfterChanges = simulator.simulate(graph);\n\n // Restore the original transfer size after we've done our simulation\n graph.traverse(node => {\n if (node.type !== 'network') {\n return;\n }\n const originalTransferSize = originalTransferSizes.get(node.request.requestId);\n if (originalTransferSize === undefined) {\n return;\n }\n node.request.transferSize = originalTransferSize;\n });\n\n let savings = simulationBeforeChanges.timeInMs - simulationAfterChanges.timeInMs;\n savings = Math.round(savings / GRAPH_SAVINGS_PRECISION) * GRAPH_SAVINGS_PRECISION;\n return Types.Timing.Milli(savings);\n}\n\n/**\n * Estimates the FCP & LCP savings for wasted bytes in `wastedBytesByRequestId`.\n */\nexport function metricSavingsForWastedBytes(\n wastedBytesByRequestId: Map<string, number>, context: InsightSetContext): MetricSavings|undefined {\n if (!context.navigation || !context.lantern) {\n return;\n }\n\n if (!wastedBytesByRequestId.size) {\n return {FCP: Types.Timing.Milli(0), LCP: Types.Timing.Milli(0)};\n }\n\n const simulator = context.lantern.simulator;\n const fcpGraph = context.lantern.metrics.firstContentfulPaint.optimisticGraph;\n const lcpGraph = context.lantern.metrics.largestContentfulPaint.optimisticGraph;\n\n return {\n FCP: estimateSavingsWithGraphs(wastedBytesByRequestId, simulator, fcpGraph),\n LCP: estimateSavingsWithGraphs(wastedBytesByRequestId, simulator, lcpGraph),\n };\n}\n\n/**\n * Returns whether the network request was sent encoded.\n */\nexport function isRequestCompressed(request: Types.Events.SyntheticNetworkRequest): boolean {\n if (!request.args.data.responseHeaders) {\n return false;\n }\n\n // FYI: In Lighthouse, older devtools logs (like our test fixtures) seems to be\n // lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i, /^x-content-encoding-over-network$/i,\n /^x-original-content-encoding$/i, // Lightrider.\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n return request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n}\n\nexport function isRequestServedFromBrowserCache(request: Types.Events.SyntheticNetworkRequest): boolean {\n if (!request.args.data.responseHeaders || request.args.data.failed) {\n return false;\n }\n\n // Not Modified?\n if (request.args.data.statusCode === 304) {\n return true;\n }\n\n // TODO: for some reason ResourceReceiveResponse events never show a 304 status\n // code, so the above is never gonna work. For now, fall back to a dirty check of\n // looking at the ratio of transfer size and resource size. If it's really small,\n // we certainly did not use the network to fetch it.\n\n const {transferSize, resourceSize} = getRequestSizes(request);\n const ratio = resourceSize ? transferSize / resourceSize : 0;\n if (ratio < 0.01) {\n return true;\n }\n\n return false;\n}\n\nfunction getRequestSizes(request: Types.Events.SyntheticNetworkRequest): {resourceSize: number, transferSize: number} {\n const resourceSize = request.args.data.decodedBodyLength;\n const transferSize = request.args.data.encodedDataLength;\n return {resourceSize, transferSize};\n}\n\n/**\n * Estimates the number of bytes the content of this network record would have consumed on the network based on the\n * uncompressed size (totalBytes). Uses the actual transfer size from the network record if applicable,\n * minus the size of the response headers.\n *\n * @param totalBytes Uncompressed size of the resource\n */\nexport function estimateCompressedContentSize(\n request: Types.Events.SyntheticNetworkRequest|undefined, totalBytes: number,\n resourceType: Protocol.Network.ResourceType): number {\n if (!request || isRequestServedFromBrowserCache(request)) {\n // We don't know how many bytes this asset used on the network, but we can guess it was\n // roughly the size of the content gzipped.\n // See https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/optimize-encoding-and-transfer for specific CSS/Script examples\n // See https://discuss.httparchive.org/t/file-size-and-compression-savings/145 for fallback multipliers\n switch (resourceType) {\n case 'Stylesheet':\n // Stylesheets tend to compress extremely well.\n return Math.round(totalBytes * 0.2);\n case 'Script':\n case 'Document':\n // Scripts and HTML compress fairly well too.\n return Math.round(totalBytes * 0.33);\n default:\n // Otherwise we'll just fallback to the average savings in HTTPArchive\n return Math.round(totalBytes * 0.5);\n }\n }\n\n // Get the size of the response body on the network.\n const {transferSize, resourceSize} = getRequestSizes(request);\n let contentTransferSize = transferSize;\n if (!isRequestCompressed(request)) {\n // This is not compressed, so we can use resourceSize directly.\n // This would be equivalent to transfer size minus headers transfer size, but transfer size\n // may also include bytes for SSL connection etc.\n contentTransferSize = resourceSize;\n }\n // TODO(cjamcl): Get \"responseHeadersTransferSize\" in Network handler.\n // else if (request.responseHeadersTransferSize) {\n // // Subtract the size of the encoded headers.\n // contentTransferSize =\n // Math.max(0, contentTransferSize - request.responseHeadersTransferSize);\n // }\n\n if (request.args.data.resourceType === resourceType) {\n // This was a regular standalone asset, just use the transfer size.\n return contentTransferSize;\n }\n\n // This was an asset that was inlined in a different resource type (e.g. HTML document).\n // Use the compression ratio of the resource to estimate the total transferred bytes.\n // Get the compression ratio, if it's an invalid number, assume no compression.\n const compressionRatio = Number.isFinite(resourceSize) && resourceSize > 0 ? (contentTransferSize / resourceSize) : 1;\n return Math.round(totalBytes * compressionRatio);\n}\n\n/**\n * Utility function to estimate the ratio of the compression of a script.\n * This excludes the size of the response headers.\n */\nexport function estimateCompressionRatioForScript(script: Handlers.ModelHandlers.Scripts.Script): number {\n if (!script.request) {\n // Can't find request, so just use 1.\n return 1;\n }\n\n const request = script.request;\n const contentLength = request.args.data.decodedBodyLength ?? script.content?.length ?? 0;\n const compressedSize = estimateCompressedContentSize(request, contentLength, Protocol.Network.ResourceType.Script);\n if (contentLength === 0 || compressedSize === 0) {\n return 1;\n }\n\n const compressionRatio = compressedSize / contentLength;\n return compressionRatio;\n}\n\nexport function calculateDocFirstByteTs(docRequest: Types.Events.SyntheticNetworkRequest): Types.Timing.Micro|null {\n if (docRequest.args.data.protocol === 'file') {\n // file: requests do not have timings\n return docRequest.ts;\n }\n\n const timing = docRequest.args.data.timing;\n if (!timing) {\n // Older traces do not have timings.\n return null;\n }\n\n // Time that first byte (headers) are received.\n // For older traces, receiveHeadersStart can be missing (ex: web.dev.json.gz).\n // In that case use the headers end timing, which should be pretty close to when\n // the headers start.\n return Types.Timing.Micro(\n Helpers.Timing.secondsToMicro(timing.requestTime) +\n Helpers.Timing.milliToMicro(timing.receiveHeadersStart ?? timing.receiveHeadersEnd));\n}\n\n/**\n * Calculates the trace bounds for the given insight that are relevant.\n *\n * Uses the insight's overlays to determine the relevant trace bounds. If there are\n * no overlays, falls back to the insight set's navigation bounds.\n */\nexport function insightBounds(\n insight: InsightModel, insightSetBounds: Types.Timing.TraceWindowMicro): Types.Timing.TraceWindowMicro {\n const overlays = insight.createOverlays?.() ?? [];\n const windows = overlays.map(Helpers.Timing.traceWindowFromOverlay).filter(bounds => !!bounds);\n const overlaysBounds = Helpers.Timing.combineTraceWindowsMicro(windows);\n if (overlaysBounds) {\n return overlaysBounds;\n }\n\n return insightSetBounds;\n}\n"]}
|
|
@@ -15,7 +15,7 @@ export declare const UIStrings: {
|
|
|
15
15
|
/**
|
|
16
16
|
* @description Title of a list to provide related stack trace data
|
|
17
17
|
*/
|
|
18
|
-
readonly
|
|
18
|
+
readonly reflowCallFrames: "Call frames that trigger reflow";
|
|
19
19
|
/**
|
|
20
20
|
* @description Text to describe the top time-consuming function call
|
|
21
21
|
*/
|
|
@@ -19,7 +19,7 @@ export const UIStrings = {
|
|
|
19
19
|
/**
|
|
20
20
|
* @description Title of a list to provide related stack trace data
|
|
21
21
|
*/
|
|
22
|
-
|
|
22
|
+
reflowCallFrames: 'Call frames that trigger reflow',
|
|
23
23
|
/**
|
|
24
24
|
* @description Text to describe the top time-consuming function call
|
|
25
25
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ForcedReflow.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ForcedReflow.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAE/D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;QACd,aAAa,EAAE,MAAM;QACrB,wBAAwB;QACxB,sBAAsB,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;KACtD,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAA+B;IAC5D,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,iBAAiB,GAAG,CAAC,GAAG,KAAK,CAAC,sBAAsB,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IACzG,OAAO;QACL,GAAG,sBAAsB,CAAC,KAAK,CAAC,wBAAwB,CAAC,0BAA0B,EAAE,MAAM,CAAC;QAC5F,GAAG,sBAAsB,CAAC,iBAAiB,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAClC,MAA4B,EAAE,gBAAgC,OAAO;IACvE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACJ,IAAI,EAAE,eAAe;QACrB,KAAK,EAAE,CAAC;QACR,aAAa;KACd,CAAC,CAAC,CAAC;AACxB,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Extras from '../extras/extras.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that provides details about Forced reflow.\n */\n title: 'Forced reflow',\n /**\n * @description Text to describe the forced reflow.\n */\n description:\n 'A forced reflow occurs when JavaScript queries geometric properties (such as `offsetWidth`) after styles have been invalidated by a change to the DOM state. This can result in poor performance. Learn more about [forced reflows](https://developer.chrome.com/docs/performance/insights/forced-reflow) and possible mitigations.',\n /**\n * @description Title of a list to provide related stack trace data\n */\n relatedStackTrace: 'Stack trace',\n /**\n * @description Text to describe the top time-consuming function call\n */\n topTimeConsumingFunctionCall: 'Top function call',\n /**\n * @description Text to describe the total reflow time\n */\n totalReflowTime: 'Total reflow time',\n /**\n * @description Text to describe CPU processor tasks that could not be attributed to any specific source code.\n */\n unattributed: '[unattributed]',\n /**\n * @description Text for the name of anonymous functions\n */\n anonymous: '(anonymous)',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/ForcedReflow.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type ForcedReflowInsightModel = InsightModel<typeof UIStrings, {\n topLevelFunctionCallData: ForcedReflowAggregatedData | undefined,\n aggregatedBottomUpData: BottomUpCallStack[],\n}>;\n\nexport interface BottomUpCallStack {\n /**\n * `null` indicates that this data is for unattributed force reflows.\n */\n bottomUpData: Types.Events.CallFrame|Protocol.Runtime.CallFrame|null;\n totalTime: number;\n relatedEvents: Types.Events.Event[];\n}\n\nexport interface ForcedReflowAggregatedData {\n topLevelFunctionCall: Types.Events.CallFrame|Protocol.Runtime.CallFrame;\n totalReflowTime: number;\n topLevelFunctionCallEvents: Types.Events.Event[];\n}\n\nfunction getCallFrameId(callFrame: Types.Events.CallFrame|Protocol.Runtime.CallFrame): string {\n return callFrame.scriptId + ':' + callFrame.lineNumber + ':' + callFrame.columnNumber;\n}\n\nfunction getLargestTopLevelFunctionData(\n forcedReflowEvents: Types.Events.Event[], traceParsedData: Handlers.Types.HandlerData): ForcedReflowAggregatedData|\n undefined {\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n if (forcedReflowEvents.length === 0) {\n return;\n }\n\n for (const event of forcedReflowEvents) {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(event);\n if (!traceNode) {\n continue;\n }\n\n let node = traceNode.parent;\n let topLevelFunctionCall;\n let topLevelFunctionCallEvent: Types.Events.Event|undefined;\n while (node) {\n const eventData = node.entry;\n if (Types.Events.isProfileCall(eventData)) {\n topLevelFunctionCall = eventData.callFrame;\n topLevelFunctionCallEvent = eventData;\n } else {\n // We have finished searching bottom up data\n if (Types.Events.isFunctionCall(eventData) && eventData.args.data &&\n Types.Events.objectIsCallFrame(eventData.args.data)) {\n topLevelFunctionCall = eventData.args.data;\n topLevelFunctionCallEvent = eventData;\n }\n break;\n }\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent) {\n continue;\n }\n\n const aggregatedDataId = getCallFrameId(topLevelFunctionCall);\n const aggregatedData =\n Platform.MapUtilities.getWithDefault(dataByTopLevelFunction, aggregatedDataId, () => ({\n topLevelFunctionCall,\n totalReflowTime: 0,\n topLevelFunctionCallEvents: [],\n }));\n aggregatedData.totalReflowTime += (event.dur ?? 0);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n\n let topTimeConsumingData: ForcedReflowAggregatedData|undefined = undefined;\n dataByTopLevelFunction.forEach(data => {\n if (!topTimeConsumingData || data.totalReflowTime > topTimeConsumingData.totalReflowTime) {\n topTimeConsumingData = data;\n }\n });\n\n return topTimeConsumingData;\n}\n\nfunction finalize(partialModel: PartialInsightModel<ForcedReflowInsightModel>): ForcedReflowInsightModel {\n return {\n insightKey: InsightKeys.FORCED_REFLOW,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/forced-reflow',\n category: InsightCategory.ALL,\n state: partialModel.aggregatedBottomUpData.length !== 0 ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction getBottomCallFrameForEvent(event: Types.Events.Event, traceParsedData: Handlers.Types.HandlerData):\n Types.Events.CallFrame|Protocol.Runtime.CallFrame|null {\n const profileStackTrace = Extras.StackTraceForEvent.get(event, traceParsedData);\n const eventTopCallFrame = Helpers.Trace.getStackTraceTopCallFrameInEventPayload(event);\n\n return profileStackTrace?.callFrames[0] ?? eventTopCallFrame ?? null;\n}\n\nexport function isForcedReflowInsight(model: InsightModel): model is ForcedReflowInsightModel {\n return model.insightKey === InsightKeys.FORCED_REFLOW;\n}\n\nexport function generateInsight(\n traceParsedData: Handlers.Types.HandlerData, context: InsightSetContext): ForcedReflowInsightModel {\n const isWithinContext = (event: Types.Events.Event): boolean => {\n const frameId = Helpers.Trace.frameIDForEvent(event);\n if (frameId !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n };\n\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const events = traceParsedData.Warnings.perWarning.get('FORCED_REFLOW')?.filter(isWithinContext) ?? [];\n for (const event of events) {\n const bottomCallFrame = getBottomCallFrameForEvent(event, traceParsedData);\n const bottomCallId = bottomCallFrame ? getCallFrameId(bottomCallFrame) : 'UNATTRIBUTED';\n const bottomUpData =\n Platform.MapUtilities.getWithDefault(bottomUpDataMap, bottomCallId, () => ({\n bottomUpData: bottomCallFrame,\n totalTime: 0,\n relatedEvents: [],\n }));\n bottomUpData.totalTime += event.dur ?? 0;\n bottomUpData.relatedEvents.push(event);\n }\n\n const topLevelFunctionCallData = getLargestTopLevelFunctionData(events, traceParsedData);\n\n return finalize({\n relatedEvents: events,\n topLevelFunctionCallData,\n aggregatedBottomUpData: [...bottomUpDataMap.values()],\n });\n}\n\nexport function createOverlays(model: ForcedReflowInsightModel): Types.Overlays.Overlay[] {\n if (!model.topLevelFunctionCallData) {\n return [];\n }\n\n const allBottomUpEvents = [...model.aggregatedBottomUpData.values().flatMap(data => data.relatedEvents)];\n return [\n ...createOverlayForEvents(model.topLevelFunctionCallData.topLevelFunctionCallEvents, 'INFO'),\n ...createOverlayForEvents(allBottomUpEvents),\n ];\n}\n\nexport function createOverlayForEvents(\n events: Types.Events.Event[], outlineReason: 'ERROR'|'INFO' = 'ERROR'): Types.Overlays.Overlay[] {\n return events.map(e => ({\n type: 'ENTRY_OUTLINE',\n entry: e,\n outlineReason,\n }));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ForcedReflow.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ForcedReflow.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAE/D,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAE9C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EACf,WAAW,GAIZ,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,eAAe;IACtB;;OAEG;IACH,WAAW,EACP,qUAAqU;IACzU;;OAEG;IACH,gBAAgB,EAAE,iCAAiC;IACnD;;OAEG;IACH,4BAA4B,EAAE,mBAAmB;IACjD;;OAEG;IACH,eAAe,EAAE,mBAAmB;IACpC;;OAEG;IACH,YAAY,EAAE,gBAAgB;IAC9B;;OAEG;IACH,SAAS,EAAE,aAAa;CAChB,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;AAC7F,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAsB7E,SAAS,cAAc,CAAC,SAA4D;IAClF,OAAO,SAAS,CAAC,QAAQ,GAAG,GAAG,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copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Extras from '../extras/extras.js';\nimport type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that provides details about Forced reflow.\n */\n title: 'Forced reflow',\n /**\n * @description Text to describe the forced reflow.\n */\n description:\n 'A forced reflow occurs when JavaScript queries geometric properties (such as `offsetWidth`) after styles have been invalidated by a change to the DOM state. This can result in poor performance. Learn more about [forced reflows](https://developer.chrome.com/docs/performance/insights/forced-reflow) and possible mitigations.',\n /**\n * @description Title of a list to provide related stack trace data\n */\n reflowCallFrames: 'Call frames that trigger reflow',\n /**\n * @description Text to describe the top time-consuming function call\n */\n topTimeConsumingFunctionCall: 'Top function call',\n /**\n * @description Text to describe the total reflow time\n */\n totalReflowTime: 'Total reflow time',\n /**\n * @description Text to describe CPU processor tasks that could not be attributed to any specific source code.\n */\n unattributed: '[unattributed]',\n /**\n * @description Text for the name of anonymous functions\n */\n anonymous: '(anonymous)',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/ForcedReflow.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type ForcedReflowInsightModel = InsightModel<typeof UIStrings, {\n topLevelFunctionCallData: ForcedReflowAggregatedData | undefined,\n aggregatedBottomUpData: BottomUpCallStack[],\n}>;\n\nexport interface BottomUpCallStack {\n /**\n * `null` indicates that this data is for unattributed force reflows.\n */\n bottomUpData: Types.Events.CallFrame|Protocol.Runtime.CallFrame|null;\n totalTime: number;\n relatedEvents: Types.Events.Event[];\n}\n\nexport interface ForcedReflowAggregatedData {\n topLevelFunctionCall: Types.Events.CallFrame|Protocol.Runtime.CallFrame;\n totalReflowTime: number;\n topLevelFunctionCallEvents: Types.Events.Event[];\n}\n\nfunction getCallFrameId(callFrame: Types.Events.CallFrame|Protocol.Runtime.CallFrame): string {\n return callFrame.scriptId + ':' + callFrame.lineNumber + ':' + callFrame.columnNumber;\n}\n\nfunction getLargestTopLevelFunctionData(\n forcedReflowEvents: Types.Events.Event[], traceParsedData: Handlers.Types.HandlerData): ForcedReflowAggregatedData|\n undefined {\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n if (forcedReflowEvents.length === 0) {\n return;\n }\n\n for (const event of forcedReflowEvents) {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(event);\n if (!traceNode) {\n continue;\n }\n\n let node = traceNode.parent;\n let topLevelFunctionCall;\n let topLevelFunctionCallEvent: Types.Events.Event|undefined;\n while (node) {\n const eventData = node.entry;\n if (Types.Events.isProfileCall(eventData)) {\n topLevelFunctionCall = eventData.callFrame;\n topLevelFunctionCallEvent = eventData;\n } else {\n // We have finished searching bottom up data\n if (Types.Events.isFunctionCall(eventData) && eventData.args.data &&\n Types.Events.objectIsCallFrame(eventData.args.data)) {\n topLevelFunctionCall = eventData.args.data;\n topLevelFunctionCallEvent = eventData;\n }\n break;\n }\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent) {\n continue;\n }\n\n const aggregatedDataId = getCallFrameId(topLevelFunctionCall);\n const aggregatedData =\n Platform.MapUtilities.getWithDefault(dataByTopLevelFunction, aggregatedDataId, () => ({\n topLevelFunctionCall,\n totalReflowTime: 0,\n topLevelFunctionCallEvents: [],\n }));\n aggregatedData.totalReflowTime += (event.dur ?? 0);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n\n let topTimeConsumingData: ForcedReflowAggregatedData|undefined = undefined;\n dataByTopLevelFunction.forEach(data => {\n if (!topTimeConsumingData || data.totalReflowTime > topTimeConsumingData.totalReflowTime) {\n topTimeConsumingData = data;\n }\n });\n\n return topTimeConsumingData;\n}\n\nfunction finalize(partialModel: PartialInsightModel<ForcedReflowInsightModel>): ForcedReflowInsightModel {\n return {\n insightKey: InsightKeys.FORCED_REFLOW,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/forced-reflow',\n category: InsightCategory.ALL,\n state: partialModel.aggregatedBottomUpData.length !== 0 ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nfunction getBottomCallFrameForEvent(event: Types.Events.Event, traceParsedData: Handlers.Types.HandlerData):\n Types.Events.CallFrame|Protocol.Runtime.CallFrame|null {\n const profileStackTrace = Extras.StackTraceForEvent.get(event, traceParsedData);\n const eventTopCallFrame = Helpers.Trace.getStackTraceTopCallFrameInEventPayload(event);\n\n return profileStackTrace?.callFrames[0] ?? eventTopCallFrame ?? null;\n}\n\nexport function isForcedReflowInsight(model: InsightModel): model is ForcedReflowInsightModel {\n return model.insightKey === InsightKeys.FORCED_REFLOW;\n}\n\nexport function generateInsight(\n traceParsedData: Handlers.Types.HandlerData, context: InsightSetContext): ForcedReflowInsightModel {\n const isWithinContext = (event: Types.Events.Event): boolean => {\n const frameId = Helpers.Trace.frameIDForEvent(event);\n if (frameId !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n };\n\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const events = traceParsedData.Warnings.perWarning.get('FORCED_REFLOW')?.filter(isWithinContext) ?? [];\n for (const event of events) {\n const bottomCallFrame = getBottomCallFrameForEvent(event, traceParsedData);\n const bottomCallId = bottomCallFrame ? getCallFrameId(bottomCallFrame) : 'UNATTRIBUTED';\n const bottomUpData =\n Platform.MapUtilities.getWithDefault(bottomUpDataMap, bottomCallId, () => ({\n bottomUpData: bottomCallFrame,\n totalTime: 0,\n relatedEvents: [],\n }));\n bottomUpData.totalTime += event.dur ?? 0;\n bottomUpData.relatedEvents.push(event);\n }\n\n const topLevelFunctionCallData = getLargestTopLevelFunctionData(events, traceParsedData);\n\n return finalize({\n relatedEvents: events,\n topLevelFunctionCallData,\n aggregatedBottomUpData: [...bottomUpDataMap.values()],\n });\n}\n\nexport function createOverlays(model: ForcedReflowInsightModel): Types.Overlays.Overlay[] {\n if (!model.topLevelFunctionCallData) {\n return [];\n }\n\n const allBottomUpEvents = [...model.aggregatedBottomUpData.values().flatMap(data => data.relatedEvents)];\n return [\n ...createOverlayForEvents(model.topLevelFunctionCallData.topLevelFunctionCallEvents, 'INFO'),\n ...createOverlayForEvents(allBottomUpEvents),\n ];\n}\n\nexport function createOverlayForEvents(\n events: Types.Events.Event[], outlineReason: 'ERROR'|'INFO' = 'ERROR'): Types.Overlays.Overlay[] {\n return events.map(e => ({\n type: 'ENTRY_OUTLINE',\n entry: e,\n outlineReason,\n }));\n}\n"]}
|
|
@@ -75,7 +75,7 @@ export declare function isLCPBreakdownInsight(model: InsightModel): model is LCP
|
|
|
75
75
|
export type LCPBreakdownInsightModel = InsightModel<typeof UIStrings, {
|
|
76
76
|
lcpMs?: Types.Timing.Milli;
|
|
77
77
|
lcpTs?: Types.Timing.Milli;
|
|
78
|
-
lcpEvent?: Types.Events.
|
|
78
|
+
lcpEvent?: Types.Events.AnyLargestContentfulPaintCandidate;
|
|
79
79
|
/** The network request for the LCP image, if there was one. */
|
|
80
80
|
lcpRequest?: Types.Events.SyntheticNetworkRequest;
|
|
81
81
|
subparts?: LCPSubparts;
|
|
@@ -155,13 +155,13 @@ export function generateInsight(data, context) {
|
|
|
155
155
|
if (!frameMetrics) {
|
|
156
156
|
throw new Error('no frame metrics');
|
|
157
157
|
}
|
|
158
|
-
const navMetrics = frameMetrics.get(context.
|
|
158
|
+
const navMetrics = frameMetrics.get(context.navigation);
|
|
159
159
|
if (!navMetrics) {
|
|
160
160
|
throw new Error('no navigation metrics');
|
|
161
161
|
}
|
|
162
162
|
const metricScore = navMetrics.get(Handlers.ModelHandlers.PageLoadMetrics.MetricName.LCP);
|
|
163
163
|
const lcpEvent = metricScore?.event;
|
|
164
|
-
if (!lcpEvent || !Types.Events.
|
|
164
|
+
if (!lcpEvent || !Types.Events.isAnyLargestContentfulPaintCandidate(lcpEvent)) {
|
|
165
165
|
return finalize({ warnings: [InsightWarning.NO_LCP] });
|
|
166
166
|
}
|
|
167
167
|
// This helps calculate the subparts.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LCPBreakdown.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/LCPBreakdown.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,eAAe,EACf,WAAW,EAGX,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,eAAe;IACtB;;;OAGG;IACH,WAAW,EACP,sNAAsN;IAC1N;;OAEG;IACH,eAAe,EAAE,oBAAoB;IACrC;;OAEG;IACH,iBAAiB,EAAE,qBAAqB;IACxC;;OAEG;IACH,oBAAoB,EAAE,wBAAwB;IAC9C;;OAEG;IACH,kBAAkB,EAAE,sBAAsB;IAC1C;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,QAAQ,EAAE,UAAU;IACpB;;OAEG;IACH,aAAa,EAAE,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,iBAAiB;CAChB,CAAC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G,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,KAAK;QACL,KAAK;QACL,QAAQ;QACR,UAAU;QACV,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,IAAI,SAAS;KAC/F,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAA+B;IAC5D,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAA6B;QACzC;YACE,IAAI,EAAE,oBAAoB;YAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;iBACxB,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;SACxG;KACF,CAAC;IACF,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,EAAC,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Common from '../../../core/common/common.js';\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {calculateDocFirstByteTs} from './Common.js';\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type PartialInsightModel,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that provides details about the LCP metric, broken down by parts.\n */\n title: 'LCP breakdown',\n /**\n * @description Description of a DevTools insight that presents a breakdown for the LCP metric by subparts.\n * This is displayed after a user expands the section to see more. No character length limits.\n */\n description:\n '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.',\n /**\n * @description Time to first byte title for the Largest Contentful Paint's subparts timespan breakdown.\n */\n timeToFirstByte: 'Time to first byte',\n /**\n * @description Resource load delay title for the Largest Contentful Paint subparts timespan breakdown.\n */\n resourceLoadDelay: 'Resource load delay',\n /**\n * @description Resource load duration title for the Largest Contentful Paint subparts timespan breakdown.\n */\n resourceLoadDuration: 'Resource load duration',\n /**\n * @description Element render delay title for the Largest Contentful Paint subparts timespan breakdown.\n */\n elementRenderDelay: 'Element render delay',\n /**\n * @description Label used for the subpart (section) of a larger duration.\n */\n subpart: 'Subpart',\n /**\n * @description Label used for the duration a single subpart (section) takes up of a larger duration.\n */\n duration: 'Duration',\n /**\n * @description Label used for the duration a single subpart (section) takes up of a larger duration. The value will be the 75th percentile of aggregate data. \"Field\" means that the data was collected from real users in the field as opposed to the developers local environment. \"Field\" is synonymous with \"Real user data\".\n */\n fieldDuration: 'Field p75',\n /**\n * @description Text status indicating that the the Largest Contentful Paint (LCP) metric timing was not found. \"LCP\" is an acronym and should not be translated.\n */\n noLcp: 'No LCP detected',\n} as const;\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/LCPBreakdown.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n/** A TraceWindow plus its UIString. **/\nexport type Subpart = Types.Timing.TraceWindowMicro&{label: Common.UIString.LocalizedString};\ninterface LCPSubparts {\n /**\n * The time between when the user initiates loading the page until when\n * the browser receives the first byte of the html response.\n */\n ttfb: Subpart;\n /**\n * The time between ttfb and the LCP request request being started.\n * For a text LCP, this is undefined given no request is loaded.\n */\n loadDelay?: Subpart;\n /**\n * The time it takes to load the LCP request.\n */\n loadDuration?: Subpart;\n /**\n * The time between when the LCP request finishes loading and when\n * the LCP element is rendered.\n */\n renderDelay: Subpart;\n}\n\nexport function isLCPBreakdownInsight(model: InsightModel): model is LCPBreakdownInsightModel {\n return model.insightKey === 'LCPBreakdown';\n}\nexport type LCPBreakdownInsightModel = InsightModel<typeof UIStrings, {\n lcpMs?: Types.Timing.Milli,\n lcpTs?: Types.Timing.Milli,\n lcpEvent?: Types.Events.LargestContentfulPaintCandidate,\n /** The network request for the LCP image, if there was one. */\n lcpRequest?: Types.Events.SyntheticNetworkRequest,\n subparts?: LCPSubparts,\n}>;\n\nfunction anyValuesNaN(...values: number[]): boolean {\n return values.some(v => Number.isNaN(v));\n}\n/**\n * Calculates the 2–4 subparts of an LCP as bounds.\n * Will return `null` if any required values were missing. We don't ever expect\n * them to be missing on newer traces, but old trace files may lack some of the\n * data we rely on, so we want to handle that case.\n */\nfunction determineSubparts(\n nav: Types.Events.NavigationStart, docRequest: Types.Events.SyntheticNetworkRequest,\n lcpEvent: Types.Events.LargestContentfulPaintCandidate,\n lcpRequest: Types.Events.SyntheticNetworkRequest|undefined): LCPSubparts|null {\n const firstDocByteTs = calculateDocFirstByteTs(docRequest);\n if (firstDocByteTs === null) {\n return null;\n }\n\n const ttfb = Helpers.Timing.traceWindowFromMicroSeconds(nav.ts, firstDocByteTs) as Subpart;\n ttfb.label = i18nString(UIStrings.timeToFirstByte);\n\n let renderDelay = Helpers.Timing.traceWindowFromMicroSeconds(ttfb.max, lcpEvent.ts) as Subpart;\n renderDelay.label = i18nString(UIStrings.elementRenderDelay);\n\n // If the LCP is text, we don't have a request, so just 2 subparts.\n if (!lcpRequest) {\n /**\n * Text LCP. 2 subparts, thus 3 timestamps\n *\n * | ttfb | renderDelay |\n * ^ lcpEvent.ts\n * ^ firstDocByteTs\n * ^ navStartTs\n */\n if (anyValuesNaN(ttfb.range, renderDelay.range)) {\n return null;\n }\n return {ttfb, renderDelay};\n }\n\n /**\n * Image LCP. 4 subparts means 5 timestamps\n *\n * | ttfb | loadDelay | loadTime | renderDelay |\n * ^ lcpEvent.ts\n * ^ lcpReqEndTs\n * ^ lcpStartTs\n * ^ ttfbTs\n * ^ navStartTs\n */\n const lcpStartTs = lcpRequest.ts;\n const lcpReqEndTs = lcpRequest.args.data.syntheticData.finishTime;\n\n const loadDelay = Helpers.Timing.traceWindowFromMicroSeconds(ttfb.max, lcpStartTs) as Subpart;\n const loadDuration = Helpers.Timing.traceWindowFromMicroSeconds(lcpStartTs, lcpReqEndTs) as Subpart;\n renderDelay = Helpers.Timing.traceWindowFromMicroSeconds(lcpReqEndTs, lcpEvent.ts) as Subpart;\n loadDelay.label = i18nString(UIStrings.resourceLoadDelay);\n loadDuration.label = i18nString(UIStrings.resourceLoadDuration);\n renderDelay.label = i18nString(UIStrings.elementRenderDelay);\n if (anyValuesNaN(ttfb.range, loadDelay.range, loadDuration.range, renderDelay.range)) {\n return null;\n }\n\n return {\n ttfb,\n loadDelay,\n loadDuration,\n renderDelay,\n };\n}\n\nfunction finalize(partialModel: PartialInsightModel<LCPBreakdownInsightModel>): LCPBreakdownInsightModel {\n const relatedEvents = [];\n if (partialModel.lcpEvent) {\n relatedEvents.push(partialModel.lcpEvent);\n }\n if (partialModel.lcpRequest) {\n relatedEvents.push(partialModel.lcpRequest);\n }\n\n let state: LCPBreakdownInsightModel['state'] = 'pass';\n if (partialModel.lcpMs !== undefined) {\n const classification = Handlers.ModelHandlers.PageLoadMetrics.scoreClassificationForLargestContentfulPaint(\n Helpers.Timing.milliToMicro(partialModel.lcpMs));\n if (classification === Handlers.ModelHandlers.PageLoadMetrics.ScoreClassification.GOOD) {\n state = 'informative';\n } else {\n state = 'fail';\n }\n }\n\n return {\n insightKey: InsightKeys.LCP_BREAKDOWN,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/lcp-breakdown',\n category: InsightCategory.LCP,\n state,\n ...partialModel,\n relatedEvents,\n };\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): LCPBreakdownInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const networkRequests = data.NetworkRequests;\n\n const frameMetrics = data.PageLoadMetrics.metricScoresByFrameId.get(context.frameId);\n if (!frameMetrics) {\n throw new Error('no frame metrics');\n }\n\n const navMetrics = frameMetrics.get(context.navigationId);\n if (!navMetrics) {\n throw new Error('no navigation metrics');\n }\n const metricScore = navMetrics.get(Handlers.ModelHandlers.PageLoadMetrics.MetricName.LCP);\n const lcpEvent = metricScore?.event;\n if (!lcpEvent || !Types.Events.isLargestContentfulPaintCandidate(lcpEvent)) {\n return finalize({warnings: [InsightWarning.NO_LCP]});\n }\n\n // This helps calculate the subparts.\n const lcpMs = Helpers.Timing.microToMilli(metricScore.timing);\n // This helps position things on the timeline's UI accurately for a trace.\n const lcpTs = metricScore.event?.ts ? Helpers.Timing.microToMilli(metricScore.event?.ts) : undefined;\n const lcpRequest = data.LargestImagePaint.lcpRequestByNavigationId.get(context.navigationId);\n\n const docRequest = networkRequests.byId.get(context.navigationId);\n if (!docRequest) {\n return finalize({lcpMs, lcpTs, lcpEvent, lcpRequest, warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n return finalize({\n lcpMs,\n lcpTs,\n lcpEvent,\n lcpRequest,\n subparts: determineSubparts(context.navigation, docRequest, lcpEvent, lcpRequest) ?? undefined,\n });\n}\n\nexport function createOverlays(model: LCPBreakdownInsightModel): Types.Overlays.Overlay[] {\n if (!model.subparts || !model.lcpTs) {\n return [];\n }\n\n const overlays: Types.Overlays.Overlay[] = [\n {\n type: 'TIMESPAN_BREAKDOWN',\n sections: Object.values(model.subparts)\n .map((subpart: Subpart) => ({bounds: subpart, label: subpart.label, showDuration: true})),\n },\n ];\n if (model.lcpRequest) {\n overlays.push({type: 'ENTRY_OUTLINE', entry: model.lcpRequest, outlineReason: 'INFO'});\n }\n\n return overlays;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"LCPBreakdown.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/LCPBreakdown.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,uBAAuB,EAAC,MAAM,aAAa,CAAC;AACpD,OAAO,EACL,eAAe,EACf,WAAW,EAGX,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,eAAe;IACtB;;;OAGG;IACH,WAAW,EACP,sNAAsN;IAC1N;;OAEG;IACH,eAAe,EAAE,oBAAoB;IACrC;;OAEG;IACH,iBAAiB,EAAE,qBAAqB;IACxC;;OAEG;IACH,oBAAoB,EAAE,wBAAwB;IAC9C;;OAEG;IACH,kBAAkB,EAAE,sBAAsB;IAC1C;;OAEG;IACH,OAAO,EAAE,SAAS;IAClB;;OAEG;IACH,QAAQ,EAAE,UAAU;IACpB;;OAEG;IACH,aAAa,EAAE,WAAW;IAC1B;;OAEG;IACH,KAAK,EAAE,iBAAiB;CAChB,CAAC;AACX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,uCAAuC,EAAE,SAAS,CAAC,CAAC;AAC7F,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AA0B7E,MAAM,UAAU,qBAAqB,CAAC,KAAmB;IACvD,OAAO,KAAK,CAAC,UAAU,KAAK,cAAc,CAAC;AAC7C,CAAC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,EAAE,CAAC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAA6B;QACzC;YACE,IAAI,EAAE,oBAAoB;YAC1B,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;iBACxB,GAAG,CAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,EAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAC,CAAC,CAAC;SACxG;KACF,CAAC;IACF,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACrB,QAAQ,CAAC,IAAI,CAAC,EAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,aAAa,EAAE,MAAM,EAAC,CAAC,CAAC;IACzF,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport type * as Common from '../../../core/common/common.js';\nimport * as i18n from '../../../core/i18n/i18n.js';\nimport * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {calculateDocFirstByteTs} from './Common.js';\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type PartialInsightModel,\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that provides details about the LCP metric, broken down by parts.\n */\n title: 'LCP breakdown',\n /**\n * @description Description of a DevTools insight that presents a breakdown for the LCP metric by subparts.\n * This is displayed after a user expands the section to see more. No character length limits.\n */\n description:\n '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.',\n /**\n * @description Time to first byte title for the Largest Contentful Paint's subparts timespan breakdown.\n */\n timeToFirstByte: 'Time to first byte',\n /**\n * @description Resource load delay title for the Largest Contentful Paint subparts timespan breakdown.\n */\n resourceLoadDelay: 'Resource load delay',\n /**\n * @description Resource load duration title for the Largest Contentful Paint subparts timespan breakdown.\n */\n resourceLoadDuration: 'Resource load duration',\n /**\n * @description Element render delay title for the Largest Contentful Paint subparts timespan breakdown.\n */\n elementRenderDelay: 'Element render delay',\n /**\n * @description Label used for the subpart (section) of a larger duration.\n */\n subpart: 'Subpart',\n /**\n * @description Label used for the duration a single subpart (section) takes up of a larger duration.\n */\n duration: 'Duration',\n /**\n * @description Label used for the duration a single subpart (section) takes up of a larger duration. The value will be the 75th percentile of aggregate data. \"Field\" means that the data was collected from real users in the field as opposed to the developers local environment. \"Field\" is synonymous with \"Real user data\".\n */\n fieldDuration: 'Field p75',\n /**\n * @description Text status indicating that the the Largest Contentful Paint (LCP) metric timing was not found. \"LCP\" is an acronym and should not be translated.\n */\n noLcp: 'No LCP detected',\n} as const;\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/LCPBreakdown.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n/** A TraceWindow plus its UIString. **/\nexport type Subpart = Types.Timing.TraceWindowMicro&{label: Common.UIString.LocalizedString};\ninterface LCPSubparts {\n /**\n * The time between when the user initiates loading the page until when\n * the browser receives the first byte of the html response.\n */\n ttfb: Subpart;\n /**\n * The time between ttfb and the LCP request request being started.\n * For a text LCP, this is undefined given no request is loaded.\n */\n loadDelay?: Subpart;\n /**\n * The time it takes to load the LCP request.\n */\n loadDuration?: Subpart;\n /**\n * The time between when the LCP request finishes loading and when\n * the LCP element is rendered.\n */\n renderDelay: Subpart;\n}\n\nexport function isLCPBreakdownInsight(model: InsightModel): model is LCPBreakdownInsightModel {\n return model.insightKey === 'LCPBreakdown';\n}\nexport type LCPBreakdownInsightModel = InsightModel<typeof UIStrings, {\n lcpMs?: Types.Timing.Milli,\n lcpTs?: Types.Timing.Milli,\n lcpEvent?: Types.Events.AnyLargestContentfulPaintCandidate,\n /** The network request for the LCP image, if there was one. */\n lcpRequest?: Types.Events.SyntheticNetworkRequest,\n subparts?: LCPSubparts,\n}>;\n\nfunction anyValuesNaN(...values: number[]): boolean {\n return values.some(v => Number.isNaN(v));\n}\n/**\n * Calculates the 2–4 subparts of an LCP as bounds.\n * Will return `null` if any required values were missing. We don't ever expect\n * them to be missing on newer traces, but old trace files may lack some of the\n * data we rely on, so we want to handle that case.\n */\nfunction determineSubparts(\n nav: Types.Events.NavigationStart, docRequest: Types.Events.SyntheticNetworkRequest,\n lcpEvent: Types.Events.AnyLargestContentfulPaintCandidate,\n lcpRequest: Types.Events.SyntheticNetworkRequest|undefined): LCPSubparts|null {\n const firstDocByteTs = calculateDocFirstByteTs(docRequest);\n if (firstDocByteTs === null) {\n return null;\n }\n\n const ttfb = Helpers.Timing.traceWindowFromMicroSeconds(nav.ts, firstDocByteTs) as Subpart;\n ttfb.label = i18nString(UIStrings.timeToFirstByte);\n\n let renderDelay = Helpers.Timing.traceWindowFromMicroSeconds(ttfb.max, lcpEvent.ts) as Subpart;\n renderDelay.label = i18nString(UIStrings.elementRenderDelay);\n\n // If the LCP is text, we don't have a request, so just 2 subparts.\n if (!lcpRequest) {\n /**\n * Text LCP. 2 subparts, thus 3 timestamps\n *\n * | ttfb | renderDelay |\n * ^ lcpEvent.ts\n * ^ firstDocByteTs\n * ^ navStartTs\n */\n if (anyValuesNaN(ttfb.range, renderDelay.range)) {\n return null;\n }\n return {ttfb, renderDelay};\n }\n\n /**\n * Image LCP. 4 subparts means 5 timestamps\n *\n * | ttfb | loadDelay | loadTime | renderDelay |\n * ^ lcpEvent.ts\n * ^ lcpReqEndTs\n * ^ lcpStartTs\n * ^ ttfbTs\n * ^ navStartTs\n */\n const lcpStartTs = lcpRequest.ts;\n const lcpReqEndTs = lcpRequest.args.data.syntheticData.finishTime;\n\n const loadDelay = Helpers.Timing.traceWindowFromMicroSeconds(ttfb.max, lcpStartTs) as Subpart;\n const loadDuration = Helpers.Timing.traceWindowFromMicroSeconds(lcpStartTs, lcpReqEndTs) as Subpart;\n renderDelay = Helpers.Timing.traceWindowFromMicroSeconds(lcpReqEndTs, lcpEvent.ts) as Subpart;\n loadDelay.label = i18nString(UIStrings.resourceLoadDelay);\n loadDuration.label = i18nString(UIStrings.resourceLoadDuration);\n renderDelay.label = i18nString(UIStrings.elementRenderDelay);\n if (anyValuesNaN(ttfb.range, loadDelay.range, loadDuration.range, renderDelay.range)) {\n return null;\n }\n\n return {\n ttfb,\n loadDelay,\n loadDuration,\n renderDelay,\n };\n}\n\nfunction finalize(partialModel: PartialInsightModel<LCPBreakdownInsightModel>): LCPBreakdownInsightModel {\n const relatedEvents = [];\n if (partialModel.lcpEvent) {\n relatedEvents.push(partialModel.lcpEvent);\n }\n if (partialModel.lcpRequest) {\n relatedEvents.push(partialModel.lcpRequest);\n }\n\n let state: LCPBreakdownInsightModel['state'] = 'pass';\n if (partialModel.lcpMs !== undefined) {\n const classification = Handlers.ModelHandlers.PageLoadMetrics.scoreClassificationForLargestContentfulPaint(\n Helpers.Timing.milliToMicro(partialModel.lcpMs));\n if (classification === Handlers.ModelHandlers.PageLoadMetrics.ScoreClassification.GOOD) {\n state = 'informative';\n } else {\n state = 'fail';\n }\n }\n\n return {\n insightKey: InsightKeys.LCP_BREAKDOWN,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n docs: 'https://developer.chrome.com/docs/performance/insights/lcp-breakdown',\n category: InsightCategory.LCP,\n state,\n ...partialModel,\n relatedEvents,\n };\n}\n\nexport function generateInsight(\n data: Handlers.Types.HandlerData, context: InsightSetContext): LCPBreakdownInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const networkRequests = data.NetworkRequests;\n\n const frameMetrics = data.PageLoadMetrics.metricScoresByFrameId.get(context.frameId);\n if (!frameMetrics) {\n throw new Error('no frame metrics');\n }\n\n const navMetrics = frameMetrics.get(context.navigation);\n if (!navMetrics) {\n throw new Error('no navigation metrics');\n }\n const metricScore = navMetrics.get(Handlers.ModelHandlers.PageLoadMetrics.MetricName.LCP);\n const lcpEvent = metricScore?.event;\n if (!lcpEvent || !Types.Events.isAnyLargestContentfulPaintCandidate(lcpEvent)) {\n return finalize({warnings: [InsightWarning.NO_LCP]});\n }\n\n // This helps calculate the subparts.\n const lcpMs = Helpers.Timing.microToMilli(metricScore.timing);\n // This helps position things on the timeline's UI accurately for a trace.\n const lcpTs = metricScore.event?.ts ? Helpers.Timing.microToMilli(metricScore.event?.ts) : undefined;\n const lcpRequest = data.LargestImagePaint.lcpRequestByNavigationId.get(context.navigationId);\n\n const docRequest = networkRequests.byId.get(context.navigationId);\n if (!docRequest) {\n return finalize({lcpMs, lcpTs, lcpEvent, lcpRequest, warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n return finalize({\n lcpMs,\n lcpTs,\n lcpEvent,\n lcpRequest,\n subparts: determineSubparts(context.navigation, docRequest, lcpEvent, lcpRequest) ?? undefined,\n });\n}\n\nexport function createOverlays(model: LCPBreakdownInsightModel): Types.Overlays.Overlay[] {\n if (!model.subparts || !model.lcpTs) {\n return [];\n }\n\n const overlays: Types.Overlays.Overlay[] = [\n {\n type: 'TIMESPAN_BREAKDOWN',\n sections: Object.values(model.subparts)\n .map((subpart: Subpart) => ({bounds: subpart, label: subpart.label, showDuration: true})),\n },\n ];\n if (model.lcpRequest) {\n overlays.push({type: 'ENTRY_OUTLINE', entry: model.lcpRequest, outlineReason: 'INFO'});\n }\n\n return overlays;\n}\n"]}
|
|
@@ -23,14 +23,18 @@ export declare const UIStrings: {
|
|
|
23
23
|
* @description Text to tell the user that a fetchpriority property value of "high" should be applied to the LCP request.
|
|
24
24
|
*/
|
|
25
25
|
readonly fetchPriorityShouldBeApplied: "fetchpriority=high should be applied";
|
|
26
|
+
/**
|
|
27
|
+
* @description Text to tell the user that a fetchpriority property value of "high" should be applied to the preload request that loads the LCP image.
|
|
28
|
+
*/
|
|
29
|
+
readonly fetchPriorityShouldBeAppliedToImagePreload: "fetchpriority=high should be applied to the image preload request";
|
|
26
30
|
/**
|
|
27
31
|
* @description Text to tell the user that the LCP request is discoverable in the initial document.
|
|
28
32
|
*/
|
|
29
33
|
readonly requestDiscoverable: "Request is discoverable in initial document";
|
|
30
34
|
/**
|
|
31
|
-
* @description Text to tell the user that
|
|
35
|
+
* @description Text to tell the user that LCP resources should avoid using loading=lazy.
|
|
32
36
|
*/
|
|
33
|
-
readonly lazyLoadNotApplied: "
|
|
37
|
+
readonly lazyLoadNotApplied: "LCP resources should not use loading=lazy";
|
|
34
38
|
/**
|
|
35
39
|
* @description Text status indicating that the the Largest Contentful Paint (LCP) metric timing was not found. "LCP" is an acronym and should not be translated.
|
|
36
40
|
*/
|
|
@@ -43,7 +47,7 @@ export declare const UIStrings: {
|
|
|
43
47
|
export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
|
|
44
48
|
export declare function isLCPDiscoveryInsight(model: InsightModel): model is LCPDiscoveryInsightModel;
|
|
45
49
|
export type LCPDiscoveryInsightModel = InsightModel<typeof UIStrings, {
|
|
46
|
-
lcpEvent?: Types.Events.
|
|
50
|
+
lcpEvent?: Types.Events.AnyLargestContentfulPaintCandidate;
|
|
47
51
|
/** The network request for the LCP image, if there was one. */
|
|
48
52
|
lcpRequest?: Types.Events.SyntheticNetworkRequest;
|
|
49
53
|
earliestDiscoveryTimeTs?: Types.Timing.Micro;
|