@paulirish/trace_engine 0.0.44 → 0.0.45

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.
Files changed (272) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/core/platform/ArrayUtilities.d.ts +1 -1
  3. package/core/platform/ArrayUtilities.js.map +1 -1
  4. package/core/platform/DOMUtilities.js +1 -1
  5. package/core/platform/DOMUtilities.js.map +1 -1
  6. package/core/platform/MimeType.js.map +1 -1
  7. package/core/platform/NumberUtilities.js.map +1 -1
  8. package/core/platform/ServerTiming.d.ts +2 -2
  9. package/core/platform/ServerTiming.js.map +1 -1
  10. package/core/platform/StringUtilities.js +1 -1
  11. package/core/platform/StringUtilities.js.map +1 -1
  12. package/core/platform/Timing.d.ts +0 -1
  13. package/core/platform/Timing.js +0 -3
  14. package/core/platform/Timing.js.map +1 -1
  15. package/core/platform/TypedArrayUtilities.js +3 -2
  16. package/core/platform/TypedArrayUtilities.js.map +1 -1
  17. package/generated/protocol.d.ts +71 -4
  18. package/locales/af.json +184 -1
  19. package/locales/am.json +184 -1
  20. package/locales/ar.json +184 -1
  21. package/locales/as.json +184 -1
  22. package/locales/az.json +184 -1
  23. package/locales/be.json +184 -1
  24. package/locales/bg.json +184 -1
  25. package/locales/bn.json +184 -1
  26. package/locales/bs.json +184 -1
  27. package/locales/ca.json +184 -1
  28. package/locales/cs.json +184 -1
  29. package/locales/cy.json +184 -1
  30. package/locales/da.json +184 -1
  31. package/locales/de.json +184 -1
  32. package/locales/el.json +184 -1
  33. package/locales/en-GB.json +184 -1
  34. package/locales/en-US.json +201 -15
  35. package/locales/en-XL.json +201 -15
  36. package/locales/es-419.json +184 -1
  37. package/locales/es.json +184 -1
  38. package/locales/et.json +184 -1
  39. package/locales/eu.json +184 -1
  40. package/locales/fa.json +184 -1
  41. package/locales/fi.json +184 -1
  42. package/locales/fil.json +184 -1
  43. package/locales/fr-CA.json +184 -1
  44. package/locales/fr.json +184 -1
  45. package/locales/gl.json +184 -1
  46. package/locales/gu.json +184 -1
  47. package/locales/he.json +185 -2
  48. package/locales/hi.json +184 -1
  49. package/locales/hr.json +184 -1
  50. package/locales/hu.json +184 -1
  51. package/locales/hy.json +184 -1
  52. package/locales/id.json +184 -1
  53. package/locales/is.json +184 -1
  54. package/locales/it.json +184 -1
  55. package/locales/ja.json +184 -1
  56. package/locales/ka.json +184 -1
  57. package/locales/kk.json +184 -1
  58. package/locales/km.json +184 -1
  59. package/locales/kn.json +184 -1
  60. package/locales/ko.json +184 -1
  61. package/locales/ky.json +184 -1
  62. package/locales/lo.json +184 -1
  63. package/locales/lt.json +184 -1
  64. package/locales/lv.json +184 -1
  65. package/locales/mk.json +184 -1
  66. package/locales/ml.json +184 -1
  67. package/locales/mn.json +184 -1
  68. package/locales/mr.json +184 -1
  69. package/locales/ms.json +184 -1
  70. package/locales/my.json +184 -1
  71. package/locales/ne.json +184 -1
  72. package/locales/nl.json +184 -1
  73. package/locales/no.json +184 -1
  74. package/locales/or.json +184 -1
  75. package/locales/pa.json +184 -1
  76. package/locales/pl.json +184 -1
  77. package/locales/pt-PT.json +184 -1
  78. package/locales/pt.json +184 -1
  79. package/locales/ro.json +184 -1
  80. package/locales/ru.json +184 -1
  81. package/locales/si.json +184 -1
  82. package/locales/sk.json +184 -1
  83. package/locales/sl.json +184 -1
  84. package/locales/sq.json +184 -1
  85. package/locales/sr-Latn.json +184 -1
  86. package/locales/sr.json +184 -1
  87. package/locales/sv.json +184 -1
  88. package/locales/sw.json +184 -1
  89. package/locales/ta.json +184 -1
  90. package/locales/te.json +184 -1
  91. package/locales/th.json +184 -1
  92. package/locales/tr.json +184 -1
  93. package/locales/uk.json +184 -1
  94. package/locales/ur.json +184 -1
  95. package/locales/uz.json +184 -1
  96. package/locales/vi.json +184 -1
  97. package/locales/zh-HK.json +184 -1
  98. package/locales/zh-TW.json +184 -1
  99. package/locales/zh.json +184 -1
  100. package/locales/zu.json +184 -1
  101. package/models/cpu_profile/CPUProfileDataModel.js +10 -10
  102. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  103. package/models/trace/LanternComputationData.js.map +1 -1
  104. package/models/trace/ModelImpl.d.ts +1 -0
  105. package/models/trace/ModelImpl.js +1 -0
  106. package/models/trace/ModelImpl.js.map +1 -1
  107. package/models/trace/Processor.js +16 -11
  108. package/models/trace/Processor.js.map +1 -1
  109. package/models/trace/extras/FetchNodes.d.ts +1 -1
  110. package/models/trace/extras/FetchNodes.js +3 -3
  111. package/models/trace/extras/FetchNodes.js.map +1 -1
  112. package/models/trace/extras/ScriptDuplication.d.ts +34 -0
  113. package/models/trace/extras/ScriptDuplication.js +178 -0
  114. package/models/trace/extras/ScriptDuplication.js.map +1 -0
  115. package/models/trace/extras/StackTraceForEvent.js +25 -44
  116. package/models/trace/extras/StackTraceForEvent.js.map +1 -1
  117. package/models/trace/extras/ThirdParties.js +1 -0
  118. package/models/trace/extras/ThirdParties.js.map +1 -1
  119. package/models/trace/extras/TraceTree.d.ts +5 -2
  120. package/models/trace/extras/TraceTree.js +47 -17
  121. package/models/trace/extras/TraceTree.js.map +1 -1
  122. package/models/trace/extras/extras-tsconfig.json +1 -1
  123. package/models/trace/extras/extras.d.ts +1 -0
  124. package/models/trace/extras/extras.js +1 -0
  125. package/models/trace/extras/extras.js.map +1 -1
  126. package/models/trace/handlers/AnimationFramesHandler.js.map +1 -1
  127. package/models/trace/handlers/AsyncJSCallsHandler.js.map +1 -1
  128. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -1
  129. package/models/trace/handlers/ExtensionTraceDataHandler.d.ts +1 -1
  130. package/models/trace/handlers/ExtensionTraceDataHandler.js +2 -1
  131. package/models/trace/handlers/ExtensionTraceDataHandler.js.map +1 -1
  132. package/models/trace/handlers/FramesHandler.js.map +1 -1
  133. package/models/trace/handlers/ImagePaintingHandler.js +1 -1
  134. package/models/trace/handlers/ImagePaintingHandler.js.map +1 -1
  135. package/models/trace/handlers/InitiatorsHandler.js.map +1 -1
  136. package/models/trace/handlers/InvalidationsHandler.js.map +1 -1
  137. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -1
  138. package/models/trace/handlers/MetaHandler.d.ts +2 -2
  139. package/models/trace/handlers/MetaHandler.js +4 -6
  140. package/models/trace/handlers/MetaHandler.js.map +1 -1
  141. package/models/trace/handlers/ModelHandlers.d.ts +1 -0
  142. package/models/trace/handlers/ModelHandlers.js +1 -0
  143. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  144. package/models/trace/handlers/NetworkRequestsHandler.d.ts +9 -0
  145. package/models/trace/handlers/NetworkRequestsHandler.js +6 -6
  146. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  147. package/models/trace/handlers/PageLoadMetricsHandler.js +1 -1
  148. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -1
  149. package/models/trace/handlers/RendererHandler.js +3 -4
  150. package/models/trace/handlers/RendererHandler.js.map +1 -1
  151. package/models/trace/handlers/ScriptsHandler.d.ts +22 -0
  152. package/models/trace/handlers/ScriptsHandler.js +116 -0
  153. package/models/trace/handlers/ScriptsHandler.js.map +1 -0
  154. package/models/trace/handlers/UserTimingsHandler.d.ts +5 -0
  155. package/models/trace/handlers/UserTimingsHandler.js +16 -0
  156. package/models/trace/handlers/UserTimingsHandler.js.map +1 -1
  157. package/models/trace/handlers/WorkersHandler.js.map +1 -1
  158. package/models/trace/handlers/handlers-tsconfig.json +1 -0
  159. package/models/trace/handlers/helpers.d.ts +5 -1
  160. package/models/trace/handlers/helpers.js +28 -4
  161. package/models/trace/handlers/helpers.js.map +1 -1
  162. package/models/trace/helpers/Network.d.ts +1 -0
  163. package/models/trace/helpers/Network.js +8 -3
  164. package/models/trace/helpers/Network.js.map +1 -1
  165. package/models/trace/helpers/SamplesIntegrator.d.ts +8 -1
  166. package/models/trace/helpers/SamplesIntegrator.js +42 -2
  167. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  168. package/models/trace/helpers/Timing.js.map +1 -1
  169. package/models/trace/helpers/Trace.d.ts +7 -10
  170. package/models/trace/helpers/Trace.js +25 -10
  171. package/models/trace/helpers/Trace.js.map +1 -1
  172. package/models/trace/insights/CLSCulprits.d.ts +12 -12
  173. package/models/trace/insights/CLSCulprits.js +15 -4
  174. package/models/trace/insights/CLSCulprits.js.map +1 -1
  175. package/models/trace/insights/Common.d.ts +7 -1
  176. package/models/trace/insights/Common.js +9 -3
  177. package/models/trace/insights/Common.js.map +1 -1
  178. package/models/trace/insights/DOMSize.d.ts +8 -8
  179. package/models/trace/insights/DOMSize.js +2 -1
  180. package/models/trace/insights/DOMSize.js.map +1 -1
  181. package/models/trace/insights/DocumentLatency.d.ts +11 -11
  182. package/models/trace/insights/DocumentLatency.js +2 -1
  183. package/models/trace/insights/DocumentLatency.js.map +1 -1
  184. package/models/trace/insights/DuplicateJavaScript.d.ts +18 -0
  185. package/models/trace/insights/DuplicateJavaScript.js +49 -0
  186. package/models/trace/insights/DuplicateJavaScript.js.map +1 -0
  187. package/models/trace/insights/FontDisplay.d.ts +4 -4
  188. package/models/trace/insights/FontDisplay.js +2 -1
  189. package/models/trace/insights/FontDisplay.js.map +1 -1
  190. package/models/trace/insights/ForcedReflow.d.ts +5 -5
  191. package/models/trace/insights/ForcedReflow.js +4 -1
  192. package/models/trace/insights/ForcedReflow.js.map +1 -1
  193. package/models/trace/insights/ImageDelivery.d.ts +19 -15
  194. package/models/trace/insights/ImageDelivery.js +26 -20
  195. package/models/trace/insights/ImageDelivery.js.map +1 -1
  196. package/models/trace/insights/InteractionToNextPaint.d.ts +8 -8
  197. package/models/trace/insights/InteractionToNextPaint.js +3 -2
  198. package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
  199. package/models/trace/insights/LCPDiscovery.d.ts +9 -9
  200. package/models/trace/insights/LCPDiscovery.js +6 -3
  201. package/models/trace/insights/LCPDiscovery.js.map +1 -1
  202. package/models/trace/insights/LCPPhases.d.ts +15 -10
  203. package/models/trace/insights/LCPPhases.js +11 -4
  204. package/models/trace/insights/LCPPhases.js.map +1 -1
  205. package/models/trace/insights/Models.d.ts +2 -1
  206. package/models/trace/insights/Models.js +2 -1
  207. package/models/trace/insights/Models.js.map +1 -1
  208. package/models/trace/insights/NetworkDependencyTree.d.ts +33 -0
  209. package/models/trace/insights/NetworkDependencyTree.js +141 -0
  210. package/models/trace/insights/NetworkDependencyTree.js.map +1 -0
  211. package/models/trace/insights/RenderBlocking.d.ts +5 -5
  212. package/models/trace/insights/RenderBlocking.js +2 -1
  213. package/models/trace/insights/RenderBlocking.js.map +1 -1
  214. package/models/trace/insights/SlowCSSSelector.d.ts +8 -8
  215. package/models/trace/insights/SlowCSSSelector.js +4 -2
  216. package/models/trace/insights/SlowCSSSelector.js.map +1 -1
  217. package/models/trace/insights/ThirdParties.d.ts +6 -6
  218. package/models/trace/insights/ThirdParties.js +8 -5
  219. package/models/trace/insights/ThirdParties.js.map +1 -1
  220. package/models/trace/insights/Viewport.d.ts +2 -2
  221. package/models/trace/insights/Viewport.js +2 -1
  222. package/models/trace/insights/Viewport.js.map +1 -1
  223. package/models/trace/insights/insights-tsconfig.json +2 -1
  224. package/models/trace/insights/types.d.ts +25 -3
  225. package/models/trace/insights/types.js.map +1 -1
  226. package/models/trace/lantern/core/NetworkAnalyzer.d.ts +2 -2
  227. package/models/trace/lantern/core/NetworkAnalyzer.js +2 -2
  228. package/models/trace/lantern/core/NetworkAnalyzer.js.map +1 -1
  229. package/models/trace/lantern/graph/BaseNode.d.ts +1 -1
  230. package/models/trace/lantern/graph/BaseNode.js.map +1 -1
  231. package/models/trace/lantern/graph/CPUNode.js +1 -1
  232. package/models/trace/lantern/graph/CPUNode.js.map +1 -1
  233. package/models/trace/lantern/graph/NetworkNode.js +1 -1
  234. package/models/trace/lantern/graph/NetworkNode.js.map +1 -1
  235. package/models/trace/lantern/graph/PageDependencyGraph.d.ts +2 -2
  236. package/models/trace/lantern/graph/PageDependencyGraph.js.map +1 -1
  237. package/models/trace/lantern/metrics/Metric.js.map +1 -1
  238. package/models/trace/lantern/metrics/TotalBlockingTime.d.ts +2 -2
  239. package/models/trace/lantern/metrics/TotalBlockingTime.js.map +1 -1
  240. package/models/trace/lantern/types/Lantern.d.ts +2 -2
  241. package/models/trace/lantern/types/Lantern.js.map +1 -1
  242. package/models/trace/trace-tsconfig.json +3 -3
  243. package/models/trace/trace.d.ts +1 -2
  244. package/models/trace/trace.js +1 -2
  245. package/models/trace/trace.js.map +1 -1
  246. package/models/trace/types/Configuration.d.ts +10 -0
  247. package/models/trace/types/Configuration.js.map +1 -1
  248. package/models/trace/types/Extensions.d.ts +1 -1
  249. package/models/trace/types/Extensions.js.map +1 -1
  250. package/models/trace/types/TraceEvents.d.ts +87 -4
  251. package/models/trace/types/TraceEvents.js +20 -0
  252. package/models/trace/types/TraceEvents.js.map +1 -1
  253. package/package.json +1 -1
  254. package/test/test-trace-engine.mjs +3 -2
  255. package/models/trace/extras/TimelineJSProfile.d.ts +0 -13
  256. package/models/trace/extras/TimelineJSProfile.js +0 -60
  257. package/models/trace/extras/TimelineJSProfile.js.map +0 -1
  258. package/models/trace/insights/LongCriticalNetworkTree.d.ts +0 -22
  259. package/models/trace/insights/LongCriticalNetworkTree.js +0 -40
  260. package/models/trace/insights/LongCriticalNetworkTree.js.map +0 -1
  261. package/models/trace/root-causes/LayoutShift.d.ts +0 -125
  262. package/models/trace/root-causes/LayoutShift.js +0 -519
  263. package/models/trace/root-causes/LayoutShift.js.map +0 -1
  264. package/models/trace/root-causes/RootCauses.d.ts +0 -15
  265. package/models/trace/root-causes/RootCauses.js +0 -12
  266. package/models/trace/root-causes/RootCauses.js.map +0 -1
  267. package/models/trace/root-causes/bundle-tsconfig.json +0 -1
  268. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +0 -43
  269. package/models/trace/root-causes/root-causes-tsconfig.json +0 -56
  270. package/models/trace/root-causes/root-causes.d.ts +0 -1
  271. package/models/trace/root-causes/root-causes.js +0 -5
  272. package/models/trace/root-causes/root-causes.js.map +0 -1
@@ -4,47 +4,47 @@ export declare const UIStrings: {
4
4
  /**
5
5
  *@description Title of an insight that provides a breakdown for how long it took to download the main document.
6
6
  */
7
- title: string;
7
+ readonly title: "Document request latency";
8
8
  /**
9
9
  *@description Description of an insight that provides a breakdown for how long it took to download the main document.
10
10
  */
11
- description: string;
11
+ readonly description: "Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.";
12
12
  /**
13
13
  * @description Text to tell the user that the document request does not have redirects.
14
14
  */
15
- passingRedirects: string;
15
+ readonly passingRedirects: "Avoids redirects";
16
16
  /**
17
17
  * @description Text to tell the user that the document request had redirects.
18
18
  */
19
- failedRedirects: string;
19
+ readonly failedRedirects: "Had redirects";
20
20
  /**
21
21
  * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.
22
22
  */
23
- passingServerResponseTime: string;
23
+ readonly passingServerResponseTime: "Server responds quickly";
24
24
  /**
25
25
  * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.
26
26
  */
27
- failedServerResponseTime: string;
27
+ readonly failedServerResponseTime: "Server responded slowly";
28
28
  /**
29
29
  * @description Text to tell the user that text compression (like gzip) was applied.
30
30
  */
31
- passingTextCompression: string;
31
+ readonly passingTextCompression: "Applies text compression";
32
32
  /**
33
33
  * @description Text to tell the user that text compression (like gzip) was not applied.
34
34
  */
35
- failedTextCompression: string;
35
+ readonly failedTextCompression: "No compression applied";
36
36
  /**
37
37
  * @description Text for a label describing a network request event as having redirects.
38
38
  */
39
- redirectsLabel: string;
39
+ readonly redirectsLabel: "Redirects";
40
40
  /**
41
41
  * @description Text for a label describing a network request event as taking too long to start delivery by the server.
42
42
  */
43
- serverResponseTimeLabel: string;
43
+ readonly serverResponseTimeLabel: "Server response time";
44
44
  /**
45
45
  * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.
46
46
  */
47
- uncompressedDownload: string;
47
+ readonly uncompressedDownload: "Uncompressed download";
48
48
  };
49
49
  export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
50
50
  export type DocumentLatencyInsightModel = InsightModel<typeof UIStrings, {
@@ -138,11 +138,12 @@ function finalize(partialModel) {
138
138
  !partialModel.data.checklist.serverResponseIsFast.value || !partialModel.data.checklist.noRedirects.value;
139
139
  }
140
140
  return {
141
+ insightKey: "DocumentLatency" /* InsightKeys.DOCUMENT_LATENCY */,
141
142
  strings: UIStrings,
142
143
  title: i18nString(UIStrings.title),
143
144
  description: i18nString(UIStrings.description),
144
145
  category: InsightCategory.ALL,
145
- shouldShow: hasFailure,
146
+ state: hasFailure ? 'fail' : 'pass',
146
147
  ...partialModel,
147
148
  };
148
149
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DocumentLatency.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DocumentLatency.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAEL,eAAe,EAGf,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,0BAA0B;IACjC;;OAEG;IACH,WAAW,EACP,8JAA8J;IAClK;;OAEG;IACH,gBAAgB,EAAE,kBAAkB;IACpC;;OAEG;IACH,eAAe,EAAE,eAAe;IAChC;;OAEG;IACH,yBAAyB,EAAE,yBAAyB;IACpD;;OAEG;IACH,wBAAwB,EAAE,yBAAyB;IACnD;;OAEG;IACH,sBAAsB,EAAE,0BAA0B;IAClD;;OAEG;IACH,qBAAqB,EAAE,wBAAwB;IAC/C;;OAEG;IACH,cAAc,EAAE,WAAW;IAC3B;;OAEG;IACH,uBAAuB,EAAE,sBAAsB;IAC/C;;OAEG;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;YACf,SAAS,EAAE;gBACT,WAAW,EAAE;oBACX,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC;oBACnG,KAAK,EAAE,WAAW;iBACnB;gBACD,oBAAoB,EAAE;oBACpB,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC,CAAC;wBACjD,UAAU,CAAC,SAAS,CAAC,wBAAwB,CAAC;oBAC5E,KAAK,EAAE,oBAAoB;iBAC5B;gBACD,eAAe,EAAE;oBACf,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC,CAAC;wBAC9C,UAAU,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBACpE,KAAK,EAAE,eAAe;iBACvB;aACF;SACF;QACD,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n type Checklist,\n InsightCategory,\n type InsightModel,\n type InsightSetContext,\n InsightWarning,\n type PartialInsightModel,\n type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /**\n *@description Title of an insight that provides a breakdown for how long it took to download the main document.\n */\n title: 'Document request latency',\n /**\n *@description Description of an insight that provides a breakdown for how long it took to download the main document.\n */\n description:\n 'Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.',\n /**\n * @description Text to tell the user that the document request does not have redirects.\n */\n passingRedirects: 'Avoids redirects',\n /**\n * @description Text to tell the user that the document request had redirects.\n */\n failedRedirects: 'Had redirects',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.\n */\n passingServerResponseTime: 'Server responds quickly',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.\n */\n failedServerResponseTime: 'Server responded slowly',\n /**\n * @description Text to tell the user that text compression (like gzip) was applied.\n */\n passingTextCompression: 'Applies text compression',\n /**\n * @description Text to tell the user that text compression (like gzip) was not applied.\n */\n failedTextCompression: 'No compression applied',\n /**\n * @description Text for a label describing a network request event as having redirects.\n */\n redirectsLabel: 'Redirects',\n /**\n * @description Text for a label describing a network request event as taking too long to start delivery by the server.\n */\n serverResponseTimeLabel: 'Server response time',\n /**\n * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.\n */\n uncompressedDownload: 'Uncompressed download',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DocumentLatency.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// Due to the way that DevTools throttling works we cannot see if server response took less than ~570ms.\n// We set our failure threshold to 600ms to avoid those false positives but we want devs to shoot for 100ms.\nconst TOO_SLOW_THRESHOLD_MS = 600;\nconst TARGET_MS = 100;\n\n// Threshold for compression savings.\nconst IGNORE_THRESHOLD_IN_BYTES = 1400;\n\nexport type DocumentLatencyInsightModel = InsightModel<typeof UIStrings, {\n data?: {\n serverResponseTime: Types.Timing.Milli,\n redirectDuration: Types.Timing.Milli,\n uncompressedResponseBytes: number,\n documentRequest?: Types.Events.SyntheticNetworkRequest,\n checklist: Checklist<'noRedirects'|'serverResponseIsFast'|'usesCompression'>,\n },\n}>;\n\nexport function deps(): ['Meta', 'NetworkRequests'] {\n return ['Meta', 'NetworkRequests'];\n}\n\nfunction getServerResponseTime(request: Types.Events.SyntheticNetworkRequest): Types.Timing.Milli|null {\n const timing = request.args.data.timing;\n if (!timing) {\n return null;\n }\n\n const ms = Helpers.Timing.microToMilli(request.args.data.syntheticData.waiting);\n return Math.round(ms) as Types.Timing.Milli;\n}\n\nfunction getCompressionSavings(request: Types.Events.SyntheticNetworkRequest): number {\n // Check from headers if compression was already applied.\n // Older devtools logs are lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i,\n /^x-content-encoding-over-network$/i,\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n const isCompressed = request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n if (isCompressed) {\n return 0;\n }\n\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 // See https://letstalkaboutwebperf.com/en/gzip-brotli-server-config/ for MIME types to compress\n const originalSize = request.args.data.decodedBodyLength;\n let estimatedSavings = 0;\n switch (request.args.data.mimeType) {\n case 'text/css':\n // Stylesheets tend to compress extremely well.\n estimatedSavings = Math.round(originalSize * 0.8);\n break;\n case 'text/html':\n case 'text/javascript':\n // Scripts and HTML compress fairly well too.\n estimatedSavings = Math.round(originalSize * 0.67);\n break;\n case 'text/plain':\n case 'text/xml':\n case 'text/x-component':\n case 'application/javascript':\n case 'application/json':\n case 'application/manifest+json':\n case 'application/vnd.api+json':\n case 'application/xml':\n case 'application/xhtml+xml':\n case 'application/rss+xml':\n case 'application/atom+xml':\n case 'application/vnd.ms-fontobject':\n case 'application/x-font-ttf':\n case 'application/x-font-opentype':\n case 'application/x-font-truetype':\n case 'image/svg+xml':\n case 'image/x-icon':\n case 'image/vnd.microsoft.icon':\n case 'font/ttf':\n case 'font/eot':\n case 'font/otf':\n case 'font/opentype':\n // Use the average savings in HTTPArchive.\n estimatedSavings = Math.round(originalSize * 0.5);\n break;\n default: // Any other MIME types are likely already compressed.\n }\n // Check if the estimated savings are greater than the byte ignore threshold.\n // Note that the estimated gzip savings are always more than 10%, so there is\n // no percent threshold.\n return estimatedSavings < IGNORE_THRESHOLD_IN_BYTES ? 0 : estimatedSavings;\n}\n\nfunction finalize(partialModel: PartialInsightModel<DocumentLatencyInsightModel>): DocumentLatencyInsightModel {\n let hasFailure = false;\n if (partialModel.data) {\n hasFailure = !partialModel.data.checklist.usesCompression.value ||\n !partialModel.data.checklist.serverResponseIsFast.value || !partialModel.data.checklist.noRedirects.value;\n }\n\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow: hasFailure,\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const documentRequest =\n parsedTrace.NetworkRequests.byTime.find(req => req.args.data.requestId === context.navigationId);\n if (!documentRequest) {\n return finalize({warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n const serverResponseTime = getServerResponseTime(documentRequest);\n if (serverResponseTime === null) {\n throw new Error('missing document request timing');\n }\n\n const serverResponseTooSlow = serverResponseTime > TOO_SLOW_THRESHOLD_MS;\n\n let overallSavingsMs = 0;\n if (serverResponseTime > TOO_SLOW_THRESHOLD_MS) {\n overallSavingsMs = Math.max(serverResponseTime - TARGET_MS, 0);\n }\n\n const redirectDuration = Math.round(documentRequest.args.data.syntheticData.redirectionDuration / 1000);\n overallSavingsMs += redirectDuration;\n\n const metricSavings = {\n FCP: overallSavingsMs as Types.Timing.Milli,\n LCP: overallSavingsMs as Types.Timing.Milli,\n };\n\n const uncompressedResponseBytes = getCompressionSavings(documentRequest);\n\n const noRedirects = redirectDuration === 0;\n const serverResponseIsFast = !serverResponseTooSlow;\n const usesCompression = uncompressedResponseBytes === 0;\n\n return finalize({\n relatedEvents: [documentRequest],\n data: {\n serverResponseTime,\n redirectDuration: Types.Timing.Milli(redirectDuration),\n uncompressedResponseBytes,\n documentRequest,\n checklist: {\n noRedirects: {\n label: noRedirects ? i18nString(UIStrings.passingRedirects) : i18nString(UIStrings.failedRedirects),\n value: noRedirects\n },\n serverResponseIsFast: {\n label: serverResponseIsFast ? i18nString(UIStrings.passingServerResponseTime) :\n i18nString(UIStrings.failedServerResponseTime),\n value: serverResponseIsFast\n },\n usesCompression: {\n label: usesCompression ? i18nString(UIStrings.passingTextCompression) :\n i18nString(UIStrings.failedTextCompression),\n value: usesCompression\n },\n },\n },\n metricSavings,\n });\n}\n"]}
1
+ {"version":3,"file":"DocumentLatency.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DocumentLatency.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAEL,eAAe,EAIf,cAAc,EAGf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,0BAA0B;IACjC;;OAEG;IACH,WAAW,EACP,8JAA8J;IAClK;;OAEG;IACH,gBAAgB,EAAE,kBAAkB;IACpC;;OAEG;IACH,eAAe,EAAE,eAAe;IAChC;;OAEG;IACH,yBAAyB,EAAE,yBAAyB;IACpD;;OAEG;IACH,wBAAwB,EAAE,yBAAyB;IACnD;;OAEG;IACH,sBAAsB,EAAE,0BAA0B;IAClD;;OAEG;IACH,qBAAqB,EAAE,wBAAwB;IAC/C;;OAEG;IACH,cAAc,EAAE,WAAW;IAC3B;;OAEG;IACH,uBAAuB,EAAE,sBAAsB;IAC/C;;OAEG;IACH,oBAAoB,EAAE,uBAAuB;CACrC,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,0CAA0C,EAAE,SAAS,CAAC,CAAC;AAChG,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,k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CAAC,UAAU,CAAC,SAAS,CAAC,eAAe,CAAC;oBACnG,KAAK,EAAE,WAAW;iBACnB;gBACD,oBAAoB,EAAE;oBACpB,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,yBAAyB,CAAC,CAAC,CAAC;wBACjD,UAAU,CAAC,SAAS,CAAC,wBAAwB,CAAC;oBAC5E,KAAK,EAAE,oBAAoB;iBAC5B;gBACD,eAAe,EAAE;oBACf,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC,CAAC;wBAC9C,UAAU,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBACpE,KAAK,EAAE,eAAe;iBACvB;aACF;SACF;QACD,aAAa;KACd,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 Helpers from '../helpers/helpers.js';\nimport * 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 type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /**\n *@description Title of an insight that provides a breakdown for how long it took to download the main document.\n */\n title: 'Document request latency',\n /**\n *@description Description of an insight that provides a breakdown for how long it took to download the main document.\n */\n description:\n 'Your first network request is the most important. Reduce its latency by avoiding redirects, ensuring a fast server response, and enabling text compression.',\n /**\n * @description Text to tell the user that the document request does not have redirects.\n */\n passingRedirects: 'Avoids redirects',\n /**\n * @description Text to tell the user that the document request had redirects.\n */\n failedRedirects: 'Had redirects',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is acceptable.\n */\n passingServerResponseTime: 'Server responds quickly',\n /**\n * @description Text to tell the user that the time starting the document request to when the server started responding is not acceptable.\n */\n failedServerResponseTime: 'Server responded slowly',\n /**\n * @description Text to tell the user that text compression (like gzip) was applied.\n */\n passingTextCompression: 'Applies text compression',\n /**\n * @description Text to tell the user that text compression (like gzip) was not applied.\n */\n failedTextCompression: 'No compression applied',\n /**\n * @description Text for a label describing a network request event as having redirects.\n */\n redirectsLabel: 'Redirects',\n /**\n * @description Text for a label describing a network request event as taking too long to start delivery by the server.\n */\n serverResponseTimeLabel: 'Server response time',\n /**\n * @description Text for a label describing a network request event as taking longer to download because it wasn't compressed.\n */\n uncompressedDownload: 'Uncompressed download',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DocumentLatency.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\n// Due to the way that DevTools throttling works we cannot see if server response took less than ~570ms.\n// We set our failure threshold to 600ms to avoid those false positives but we want devs to shoot for 100ms.\nconst TOO_SLOW_THRESHOLD_MS = 600;\nconst TARGET_MS = 100;\n\n// Threshold for compression savings.\nconst IGNORE_THRESHOLD_IN_BYTES = 1400;\n\nexport type DocumentLatencyInsightModel = InsightModel<typeof UIStrings, {\n data?: {\n serverResponseTime: Types.Timing.Milli,\n redirectDuration: Types.Timing.Milli,\n uncompressedResponseBytes: number,\n documentRequest?: Types.Events.SyntheticNetworkRequest,\n checklist: Checklist<'noRedirects'|'serverResponseIsFast'|'usesCompression'>,\n },\n}>;\n\nexport function deps(): ['Meta', 'NetworkRequests'] {\n return ['Meta', 'NetworkRequests'];\n}\n\nfunction getServerResponseTime(request: Types.Events.SyntheticNetworkRequest): Types.Timing.Milli|null {\n const timing = request.args.data.timing;\n if (!timing) {\n return null;\n }\n\n const ms = Helpers.Timing.microToMilli(request.args.data.syntheticData.waiting);\n return Math.round(ms) as Types.Timing.Milli;\n}\n\nfunction getCompressionSavings(request: Types.Events.SyntheticNetworkRequest): number {\n // Check from headers if compression was already applied.\n // Older devtools logs are lower case, while modern logs are Cased-Like-This.\n const patterns = [\n /^content-encoding$/i,\n /^x-content-encoding-over-network$/i,\n ];\n const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];\n const isCompressed = request.args.data.responseHeaders.some(\n header => patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value));\n if (isCompressed) {\n return 0;\n }\n\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 // See https://letstalkaboutwebperf.com/en/gzip-brotli-server-config/ for MIME types to compress\n const originalSize = request.args.data.decodedBodyLength;\n let estimatedSavings = 0;\n switch (request.args.data.mimeType) {\n case 'text/css':\n // Stylesheets tend to compress extremely well.\n estimatedSavings = Math.round(originalSize * 0.8);\n break;\n case 'text/html':\n case 'text/javascript':\n // Scripts and HTML compress fairly well too.\n estimatedSavings = Math.round(originalSize * 0.67);\n break;\n case 'text/plain':\n case 'text/xml':\n case 'text/x-component':\n case 'application/javascript':\n case 'application/json':\n case 'application/manifest+json':\n case 'application/vnd.api+json':\n case 'application/xml':\n case 'application/xhtml+xml':\n case 'application/rss+xml':\n case 'application/atom+xml':\n case 'application/vnd.ms-fontobject':\n case 'application/x-font-ttf':\n case 'application/x-font-opentype':\n case 'application/x-font-truetype':\n case 'image/svg+xml':\n case 'image/x-icon':\n case 'image/vnd.microsoft.icon':\n case 'font/ttf':\n case 'font/eot':\n case 'font/otf':\n case 'font/opentype':\n // Use the average savings in HTTPArchive.\n estimatedSavings = Math.round(originalSize * 0.5);\n break;\n default: // Any other MIME types are likely already compressed.\n }\n // Check if the estimated savings are greater than the byte ignore threshold.\n // Note that the estimated gzip savings are always more than 10%, so there is\n // no percent threshold.\n return estimatedSavings < IGNORE_THRESHOLD_IN_BYTES ? 0 : estimatedSavings;\n}\n\nfunction finalize(partialModel: PartialInsightModel<DocumentLatencyInsightModel>): DocumentLatencyInsightModel {\n let hasFailure = false;\n if (partialModel.data) {\n hasFailure = !partialModel.data.checklist.usesCompression.value ||\n !partialModel.data.checklist.serverResponseIsFast.value || !partialModel.data.checklist.noRedirects.value;\n }\n\n return {\n insightKey: InsightKeys.DOCUMENT_LATENCY,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n state: hasFailure ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DocumentLatencyInsightModel {\n if (!context.navigation) {\n return finalize({});\n }\n\n const documentRequest =\n parsedTrace.NetworkRequests.byTime.find(req => req.args.data.requestId === context.navigationId);\n if (!documentRequest) {\n return finalize({warnings: [InsightWarning.NO_DOCUMENT_REQUEST]});\n }\n\n const serverResponseTime = getServerResponseTime(documentRequest);\n if (serverResponseTime === null) {\n throw new Error('missing document request timing');\n }\n\n const serverResponseTooSlow = serverResponseTime > TOO_SLOW_THRESHOLD_MS;\n\n let overallSavingsMs = 0;\n if (serverResponseTime > TOO_SLOW_THRESHOLD_MS) {\n overallSavingsMs = Math.max(serverResponseTime - TARGET_MS, 0);\n }\n\n const redirectDuration = Math.round(documentRequest.args.data.syntheticData.redirectionDuration / 1000);\n overallSavingsMs += redirectDuration;\n\n const metricSavings = {\n FCP: overallSavingsMs as Types.Timing.Milli,\n LCP: overallSavingsMs as Types.Timing.Milli,\n };\n\n const uncompressedResponseBytes = getCompressionSavings(documentRequest);\n\n const noRedirects = redirectDuration === 0;\n const serverResponseIsFast = !serverResponseTooSlow;\n const usesCompression = uncompressedResponseBytes === 0;\n\n return finalize({\n relatedEvents: [documentRequest],\n data: {\n serverResponseTime,\n redirectDuration: Types.Timing.Milli(redirectDuration),\n uncompressedResponseBytes,\n documentRequest,\n checklist: {\n noRedirects: {\n label: noRedirects ? i18nString(UIStrings.passingRedirects) : i18nString(UIStrings.failedRedirects),\n value: noRedirects\n },\n serverResponseIsFast: {\n label: serverResponseIsFast ? i18nString(UIStrings.passingServerResponseTime) :\n i18nString(UIStrings.failedServerResponseTime),\n value: serverResponseIsFast\n },\n usesCompression: {\n label: usesCompression ? i18nString(UIStrings.passingTextCompression) :\n i18nString(UIStrings.failedTextCompression),\n value: usesCompression\n },\n },\n },\n metricSavings,\n });\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import * as Extras from '../extras/extras.js';
2
+ import { type InsightModel, type InsightSetContext, type RequiredData } from './types.js';
3
+ export declare const UIStrings: {
4
+ /**
5
+ * @description Title of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.
6
+ */
7
+ readonly title: "Duplicate JavaScript";
8
+ /**
9
+ * @description Description of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.
10
+ */
11
+ readonly description: "Remove large, duplicate JavaScript modules from bundles to reduce unnecessary bytes consumed by network activity.";
12
+ };
13
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
14
+ export type DuplicateJavaScriptInsightModel = InsightModel<typeof UIStrings, {
15
+ duplication: Extras.ScriptDuplication.ScriptDuplication;
16
+ }>;
17
+ export declare function deps(): ['Scripts', 'NetworkRequests'];
18
+ export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DuplicateJavaScriptInsightModel;
@@ -0,0 +1,49 @@
1
+ // Copyright 2025 The Chromium Authors. All rights reserved.
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 * as Extras from '../extras/extras.js';
6
+ import * as Helpers from '../helpers/helpers.js';
7
+ import { InsightCategory } from './types.js';
8
+ export const UIStrings = {
9
+ /**
10
+ * @description Title of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.
11
+ */
12
+ title: 'Duplicate JavaScript',
13
+ /**
14
+ * @description Description of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.
15
+ */
16
+ description: 'Remove large, duplicate JavaScript modules from bundles to reduce unnecessary bytes consumed by network activity.',
17
+ };
18
+ // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/DuplicateJavaScript.ts', UIStrings);
19
+ export const i18nString = (i18nId, values) => ({i18nId, values}); // i18n.i18n.getLocalizedString.bind(undefined, str_);
20
+ export function deps() {
21
+ return ['Scripts', 'NetworkRequests'];
22
+ }
23
+ function finalize(partialModel) {
24
+ return {
25
+ insightKey: "DuplicateJavaScript" /* InsightKeys.DUPLICATE_JAVASCRIPT */,
26
+ strings: UIStrings,
27
+ title: i18nString(UIStrings.title),
28
+ description: i18nString(UIStrings.description),
29
+ category: InsightCategory.LCP,
30
+ state: Boolean(partialModel.duplication.values().next().value) ? 'fail' : 'pass',
31
+ // TODO(cjamcl): script network events.
32
+ // relatedEvents: [],
33
+ ...partialModel,
34
+ };
35
+ }
36
+ export function generateInsight(parsedTrace, context) {
37
+ const scriptEntries = [...parsedTrace.Scripts.scripts].filter(([_, script]) => {
38
+ if (!context.navigation) {
39
+ return false;
40
+ }
41
+ if (script.frame !== context.frameId) {
42
+ return false;
43
+ }
44
+ return Helpers.Timing.timestampIsInBounds(context.bounds, script.ts);
45
+ });
46
+ const duplication = Extras.ScriptDuplication.computeScriptDuplication({ scripts: new Map(scriptEntries) });
47
+ return finalize({ duplication });
48
+ }
49
+ //# sourceMappingURL=DuplicateJavaScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DuplicateJavaScript.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/DuplicateJavaScript.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EACL,eAAe,EAMhB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,K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AC,mBAAmB,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,CAAC,iBAAiB,CAAC,wBAAwB,CAAC,EAAC,OAAO,EAAE,IAAI,GAAG,CAAC,aAAa,CAAC,EAAC,CAAC,CAAC;IACzG,OAAO,QAAQ,CAAC,EAAC,WAAW,EAAC,CAAC,CAAC;AACjC,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors. All rights reserved.\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 Extras from '../extras/extras.js';\nimport * as Helpers from '../helpers/helpers.js';\n\nimport {\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /**\n * @description Title of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.\n */\n title: 'Duplicate JavaScript',\n /**\n * @description Description of an insight that identifies multiple copies of the same JavaScript sources, and recommends removing the duplication.\n */\n description:\n 'Remove large, duplicate JavaScript modules from bundles to reduce unnecessary bytes consumed by network activity.',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/DuplicateJavaScript.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type DuplicateJavaScriptInsightModel = InsightModel<typeof UIStrings, {\n duplication: Extras.ScriptDuplication.ScriptDuplication,\n}>;\n\nexport function deps(): ['Scripts', 'NetworkRequests'] {\n return ['Scripts', 'NetworkRequests'];\n}\n\nfunction finalize(partialModel: PartialInsightModel<DuplicateJavaScriptInsightModel>): DuplicateJavaScriptInsightModel {\n return {\n insightKey: InsightKeys.DUPLICATE_JAVASCRIPT,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.LCP,\n state: Boolean(partialModel.duplication.values().next().value) ? 'fail' : 'pass',\n // TODO(cjamcl): script network events.\n // relatedEvents: [],\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): DuplicateJavaScriptInsightModel {\n const scriptEntries = [...parsedTrace.Scripts.scripts].filter(([_, script]) => {\n if (!context.navigation) {\n return false;\n }\n\n if (script.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.timestampIsInBounds(context.bounds, script.ts);\n });\n\n const duplication = Extras.ScriptDuplication.computeScriptDuplication({scripts: new Map(scriptEntries)});\n return finalize({duplication});\n}\n"]}
@@ -3,15 +3,15 @@ import * as Types from '../types/types.js';
3
3
  import { type InsightModel, type InsightSetContext, type RequiredData } from './types.js';
4
4
  export declare const UIStrings: {
5
5
  /** Title of an insight that provides details about the fonts used on the page, and the value of their `font-display` properties. */
6
- title: string;
6
+ readonly title: "Font display";
7
7
  /**
8
8
  * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.
9
9
  */
10
- description: string;
10
+ readonly description: "Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).";
11
11
  /** Column for a font loaded by the page to render text. */
12
- fontColumn: string;
12
+ readonly fontColumn: "Font";
13
13
  /** Column for the amount of time wasted. */
14
- wastedTimeColumn: string;
14
+ readonly wastedTimeColumn: "Wasted time";
15
15
  };
16
16
  export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Platform.UIString.LocalizedString;
17
17
  export declare function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'];
@@ -25,11 +25,12 @@ export function deps() {
25
25
  }
26
26
  function finalize(partialModel) {
27
27
  return {
28
+ insightKey: "FontDisplay" /* InsightKeys.FONT_DISPLAY */,
28
29
  strings: UIStrings,
29
30
  title: i18nString(UIStrings.title),
30
31
  description: i18nString(UIStrings.description),
31
32
  category: InsightCategory.INP,
32
- shouldShow: Boolean(partialModel.fonts.find(font => font.wastedTime > 0)),
33
+ state: partialModel.fonts.find(font => font.wastedTime > 0) ? 'fail' : 'pass',
33
34
  ...partialModel,
34
35
  };
35
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FontDisplay.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/FontDisplay.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EAKhB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,oIAAoI;IACpI,KAAK,EAAE,cAAc;IACrB;;OAEG;IACH,WAAW,EACP,6RAA6R;IACjS,2DAA2D;IAC3D,UAAU,EAAE,MAAM;IAClB,4CAA4C;IAC5C,gBAAgB,EAAE,aAAa;CAChC,CAAC;AAEF,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,sCAAsC,EAAE,SAAS,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAE7E,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC;AAUD,SAAS,QAAQ,CAAC,YAA0D;IAC1E,OAAO;QACL,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;QAClC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC;QAC9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AC,eAAe,CAAC,EAAE,CAAC,GAAG,CAAC,CAAuB,CAAC;YAC9G,yCAAyC;YACzC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAuB,CAAC;QAChE,CAAC;QAED,KAAK,CAAC,IAAI,CAAC;YACT,OAAO;YACP,OAAO;YACP,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAuB,CAAC;IAEhF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACxC,KAAK;QACL,aAAa,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC;KAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n InsightCategory,\n type InsightModel,\n type InsightSetContext,\n type PartialInsightModel,\n type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /** Title of an insight that provides details about the fonts used on the page, and the value of their `font-display` properties. */\n title: 'Font display',\n /**\n * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.\n */\n description:\n 'Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).',\n /** Column for a font loaded by the page to render text. */\n fontColumn: 'Font',\n /** Column for the amount of time wasted. */\n wastedTimeColumn: 'Wasted time',\n};\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/FontDisplay.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'] {\n return ['Meta', 'NetworkRequests', 'LayoutShifts'];\n}\n\nexport type FontDisplayInsightModel = InsightModel<typeof UIStrings, {\n fonts: Array<{\n request: Types.Events.SyntheticNetworkRequest,\n display: string,\n wastedTime: Types.Timing.Milli,\n }>,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<FontDisplayInsightModel>): FontDisplayInsightModel {\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n shouldShow: Boolean(partialModel.fonts.find(font => font.wastedTime > 0)),\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel {\n const fonts = [];\n for (const event of parsedTrace.LayoutShifts.beginRemoteFontLoadEvents) {\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n\n const requestId = `${event.pid}.${event.args.id}`;\n const request = parsedTrace.NetworkRequests.byId.get(requestId);\n if (!request) {\n continue;\n }\n\n const display = event.args.display;\n let wastedTime = Types.Timing.Milli(0);\n\n if (/^(block|fallback|auto)$/.test(display)) {\n const wastedTimeMicro = Types.Timing.Micro(\n request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);\n // TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.\n wastedTime =\n Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5) as Types.Timing.Milli;\n // All browsers wait for no more than 3s.\n wastedTime = Math.min(wastedTime, 3000) as Types.Timing.Milli;\n }\n\n fonts.push({\n request,\n display,\n wastedTime,\n });\n }\n\n fonts.sort((a, b) => b.wastedTime - a.wastedTime);\n\n const savings = Math.max(...fonts.map(f => f.wastedTime)) as Types.Timing.Milli;\n\n return finalize({\n relatedEvents: fonts.map(f => f.request),\n fonts,\n metricSavings: {FCP: savings},\n });\n}\n"]}
1
+ {"version":3,"file":"FontDisplay.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/FontDisplay.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EACL,eAAe,EAMhB,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,oIAAoI;IACpI,KAAK,EAAE,cAAc;IACrB;;OAEG;IACH,WAAW,EACP,6RAA6R;IACjS,2DAA2D;IAC3D,UAAU,EAAE,MAAM;IAClB,4CAA4C;IAC5C,gBAAgB,EAAE,aAAa;CACvB,CAAC;AAEX,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,sCAAsC,EAAE,SAAS,CAAC,CAAC;AAC5F,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAE7E,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC;AACrD,CAAC;AAUD,SAAS,QAAQ,CAAC,YAA0D;IAC1E,OAAO;QACL,UAAU,8CAA0B;QACpC,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;QAClC,WAAW,EAAE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ACN,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,GAAG,CAAC,CAAuB,CAAC;YAC9G,yCAAyC;YACzC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAuB,CAAC;QAChE,CAAC;QAED,KAAK,CAAC,IAAI,CAAC;YACT,OAAO;YACP,OAAO;YACP,UAAU;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAuB,CAAC;IAEhF,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACxC,KAAK;QACL,aAAa,EAAE,EAAC,GAAG,EAAE,OAAO,EAAC;KAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 * 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 type RequiredData\n} from './types.js';\n\nexport const UIStrings = {\n /** Title of an insight that provides details about the fonts used on the page, and the value of their `font-display` properties. */\n title: 'Font display',\n /**\n * @description Text to tell the user about the font-display CSS feature to help improve a the UX of a page.\n */\n description:\n 'Consider setting [`font-display`](https://developer.chrome.com/blog/font-display) to `swap` or `optional` to ensure text is consistently visible. `swap` can be further optimized to mitigate layout shifts with [font metric overrides](https://developer.chrome.com/blog/font-fallbacks).',\n /** Column for a font loaded by the page to render text. */\n fontColumn: 'Font',\n /** Column for the amount of time wasted. */\n wastedTimeColumn: 'Wasted time',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/FontDisplay.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport function deps(): ['Meta', 'NetworkRequests', 'LayoutShifts'] {\n return ['Meta', 'NetworkRequests', 'LayoutShifts'];\n}\n\nexport type FontDisplayInsightModel = InsightModel<typeof UIStrings, {\n fonts: Array<{\n request: Types.Events.SyntheticNetworkRequest,\n display: string,\n wastedTime: Types.Timing.Milli,\n }>,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<FontDisplayInsightModel>): FontDisplayInsightModel {\n return {\n insightKey: InsightKeys.FONT_DISPLAY,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n state: partialModel.fonts.find(font => font.wastedTime > 0) ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): FontDisplayInsightModel {\n const fonts = [];\n for (const event of parsedTrace.LayoutShifts.beginRemoteFontLoadEvents) {\n if (!Helpers.Timing.eventIsInBounds(event, context.bounds)) {\n continue;\n }\n\n const requestId = `${event.pid}.${event.args.id}`;\n const request = parsedTrace.NetworkRequests.byId.get(requestId);\n if (!request) {\n continue;\n }\n\n const display = event.args.display;\n let wastedTime = Types.Timing.Milli(0);\n\n if (/^(block|fallback|auto)$/.test(display)) {\n const wastedTimeMicro = Types.Timing.Micro(\n request.args.data.syntheticData.finishTime - request.args.data.syntheticData.sendStartTime);\n // TODO(crbug.com/352244504): should really end at the time of the next Commit trace event.\n wastedTime =\n Platform.NumberUtilities.floor(Helpers.Timing.microToMilli(wastedTimeMicro), 1 / 5) as Types.Timing.Milli;\n // All browsers wait for no more than 3s.\n wastedTime = Math.min(wastedTime, 3000) as Types.Timing.Milli;\n }\n\n fonts.push({\n request,\n display,\n wastedTime,\n });\n }\n\n fonts.sort((a, b) => b.wastedTime - a.wastedTime);\n\n const savings = Math.max(...fonts.map(f => f.wastedTime)) as Types.Timing.Milli;\n\n return finalize({\n relatedEvents: fonts.map(f => f.request),\n fonts,\n metricSavings: {FCP: savings},\n });\n}\n"]}
@@ -4,23 +4,23 @@ export declare const UIStrings: {
4
4
  /**
5
5
  *@description Title of an insight that provides details about Forced reflow.
6
6
  */
7
- title: string;
7
+ readonly title: "Forced reflow";
8
8
  /**
9
9
  * @description Text to describe the forced reflow.
10
10
  */
11
- description: string;
11
+ readonly description: "Many APIs, typically reading layout geometry, force the rendering engine to pause script execution in order to calculate the style and layout. Learn more about [forced reflow](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts) and its mitigations.";
12
12
  /**
13
13
  *@description Title of a list to provide related stack trace data
14
14
  */
15
- relatedStackTrace: string;
15
+ readonly relatedStackTrace: "Stack trace";
16
16
  /**
17
17
  *@description Text to describe the top time-consuming function call
18
18
  */
19
- topTimeConsumingFunctionCall: string;
19
+ readonly topTimeConsumingFunctionCall: "Top function call";
20
20
  /**
21
21
  * @description Text to describe the total reflow time
22
22
  */
23
- totalReflowTime: string;
23
+ readonly totalReflowTime: "Total reflow time";
24
24
  };
25
25
  export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
26
26
  export type ForcedReflowInsightModel = InsightModel<typeof UIStrings, {
@@ -154,11 +154,14 @@ function aggregateForcedReflow(data, entryToNodeMap) {
154
154
  }
155
155
  function finalize(partialModel) {
156
156
  return {
157
+ insightKey: "ForcedReflow" /* InsightKeys.FORCED_REFLOW */,
157
158
  strings: UIStrings,
158
159
  title: i18nString(UIStrings.title),
159
160
  description: i18nString(UIStrings.description),
160
161
  category: InsightCategory.ALL,
161
- shouldShow: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0,
162
+ state: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0 ?
163
+ 'fail' :
164
+ 'pass',
162
165
  ...partialModel,
163
166
  };
164
167
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ForcedReflow.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ForcedReflow.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAGnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAGL,eAAe,GAIhB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,eAAe;IACtB;;OAEG;IACH,WAAW,EACP,8VAA8V;IAClW;;OAEG;IACH,iBAAiB,EAAE,aAAa;IAChC;;OAEG;IACH,4BAA4B,EAAE,mBAAmB;IACjD;;OAEG;IACH,eAAe,EAAE,mBAAmB;CACrC,CAAC;AAEF,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;AAO7E,SAAS,qBAAqB,CAC1B,IAAwC,EACxC,cAA2E;IAE7E,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC7E,MAAM,eAAe,GAAG,IAAI,GAAG,EAA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AA2D;IAC3E,OAAO;QACL,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;QAClC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC;QAC9C,QAAQ,EAAE,eAAe,CAAC,GAAG;QAC7B,UAAU,EAAE,YAAY,CAAC,wBAAwB,KAAK,SAAS,IAAI,YAAY,CAAC,sBAAsB,CAAC,MAAM,KAAK,CAAC;QACnH,GAAG,YAAY;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,eAA0C;IACxE,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC;IAC9C,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC;IAE5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,wBAAwB,EAAE,sBAAsB,CAAC,GACpD,qBAAqB,CAAC,YAAY,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAEnE,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,wBAAwB,EAAE,0BAA0B;QACnE,wBAAwB;QACxB,sBAAsB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 Protocol from '../../../generated/protocol.js';\nimport type {Warning} from '../handlers/WarningsHandler.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n type BottomUpCallStack,\n type ForcedReflowAggregatedData,\n InsightCategory,\n type InsightModel,\n type PartialInsightModel,\n type RequiredData,\n} from './types.js';\n\nexport function deps(): ['Warnings', 'Renderer'] {\n return ['Warnings', 'Renderer'];\n}\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 'Many APIs, typically reading layout geometry, force the rendering engine to pause script execution in order to calculate the style and layout. Learn more about [forced reflow](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts) and its 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\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\nfunction aggregateForcedReflow(\n data: Map<Warning, Types.Events.Event[]>,\n entryToNodeMap: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>):\n [ForcedReflowAggregatedData|undefined, BottomUpCallStack[]] {\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const forcedReflowEvents = data.get('FORCED_REFLOW');\n if (!forcedReflowEvents || forcedReflowEvents.length === 0) {\n return [undefined, []];\n }\n\n forcedReflowEvents.forEach(e => {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(e);\n\n if (!traceNode) {\n return;\n }\n // Compute call stack fully\n const bottomUpData: (Types.Events.CallFrame|Protocol.Runtime.CallFrame)[] = [];\n let currentNode = traceNode;\n let previousNode;\n const childStack: Protocol.Runtime.CallFrame[] = [];\n\n // Some profileCalls maybe constructed as its children in hierarchy tree\n while (currentNode.children.length > 0) {\n const childNode = currentNode.children[0];\n if (!previousNode) {\n previousNode = childNode;\n }\n const eventData = childNode.entry;\n if (Types.Events.isProfileCall(eventData)) {\n childStack.push(eventData.callFrame);\n }\n currentNode = childNode;\n }\n\n // In order to avoid too much information, we only contain 2 levels bottomUp data,\n while (childStack.length > 0 && bottomUpData.length < 2) {\n const traceData = childStack.pop();\n if (traceData) {\n bottomUpData.push(traceData);\n }\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 if (bottomUpData.length < 2) {\n bottomUpData.push(eventData.callFrame);\n }\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 if (bottomUpData.length === 0) {\n bottomUpData.push(topLevelFunctionCall);\n }\n } else {\n // Sometimes the top level task can be other JSInvocation event\n // then we use the top level profile call as topLevelFunctionCall's data\n const previousData = previousNode?.entry;\n if (previousData && Types.Events.isProfileCall(previousData)) {\n topLevelFunctionCall = previousData.callFrame;\n topLevelFunctionCallEvent = previousNode?.entry;\n }\n }\n break;\n }\n previousNode = node;\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent || bottomUpData.length === 0) {\n return;\n }\n const bottomUpDataId =\n bottomUpData[0].scriptId + ':' + bottomUpData[0].lineNumber + ':' + bottomUpData[0].columnNumber + ':';\n\n const data = bottomUpDataMap.get(bottomUpDataId) ?? {\n bottomUpData: bottomUpData[0],\n totalTime: 0,\n relatedEvents: [],\n };\n data.totalTime += (e.dur ?? 0);\n data.relatedEvents.push(e);\n bottomUpDataMap.set(bottomUpDataId, data);\n\n const aggregatedDataId =\n topLevelFunctionCall.scriptId + ':' + topLevelFunctionCall.lineNumber + ':' + topLevelFunctionCall.columnNumber;\n if (!dataByTopLevelFunction.has(aggregatedDataId)) {\n dataByTopLevelFunction.set(aggregatedDataId, {\n topLevelFunctionCall,\n totalReflowTime: 0,\n bottomUpData: new Set<string>(),\n topLevelFunctionCallEvents: [],\n });\n }\n const aggregatedData = dataByTopLevelFunction.get(aggregatedDataId);\n if (aggregatedData) {\n aggregatedData.totalReflowTime += (e.dur ?? 0);\n aggregatedData.bottomUpData.add(bottomUpDataId);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n });\n\n let topTimeConsumingDataId = '';\n let maxTime = 0;\n dataByTopLevelFunction.forEach((value, key) => {\n if (value.totalReflowTime > maxTime) {\n maxTime = value.totalReflowTime;\n topTimeConsumingDataId = key;\n }\n });\n\n const aggregatedBottomUpData: BottomUpCallStack[] = [];\n const topLevelFunctionCallData = dataByTopLevelFunction.get(topTimeConsumingDataId);\n const dataSet = dataByTopLevelFunction.get(topTimeConsumingDataId)?.bottomUpData;\n if (dataSet) {\n dataSet.forEach(value => {\n const callStackData = bottomUpDataMap.get(value);\n if (callStackData && callStackData.totalTime > Helpers.Timing.milliToMicro(Types.Timing.Milli(1))) {\n aggregatedBottomUpData.push(callStackData);\n }\n });\n }\n\n return [topLevelFunctionCallData, aggregatedBottomUpData];\n}\n\nfunction finalize(partialModel: PartialInsightModel<ForcedReflowInsightModel>): ForcedReflowInsightModel {\n return {\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.ALL,\n shouldShow: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0,\n ...partialModel,\n };\n}\n\nexport function generateInsight(traceParsedData: RequiredData<typeof deps>): ForcedReflowInsightModel {\n const warningsData = traceParsedData.Warnings;\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n\n if (!warningsData) {\n throw new Error('no warnings data');\n }\n\n if (!entryToNodeMap) {\n throw new Error('no renderer data');\n }\n\n const [topLevelFunctionCallData, aggregatedBottomUpData] =\n aggregateForcedReflow(warningsData.perWarning, entryToNodeMap);\n\n return finalize({\n relatedEvents: topLevelFunctionCallData?.topLevelFunctionCallEvents,\n topLevelFunctionCallData,\n aggregatedBottomUpData,\n });\n}\n"]}
1
+ {"version":3,"file":"ForcedReflow.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/ForcedReflow.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAGnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAGL,eAAe,GAKhB,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,KAAK,EAAE,eAAe;IACtB;;OAEG;IACH,WAAW,EACP,8VAA8V;IAClW;;OAEG;IACH,iBAAiB,EAAE,aAAa;IAChC;;OAEG;IACH,4BAA4B,EAAE,mBAAmB;IACjD;;OAEG;IACH,eAAe,EAAE,mBAAmB;CAC5B,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;AAO7E,SAAS,qBAAqB,CAC1B,IAAwC,EACxC,cAA2E;IAE7E,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC7E,MAAM,eAAe,GAAG,IAAI,GAAG,EAA6B,CAAC;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E,OAAO;QACL,UAAU,gDAA2B;QACrC,OAAO,EAAE,SAAS;QAClB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;QAClC,WAAW,EAAE,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC;QAC9C,QAAQ,EAAE,eAAe,CAAC,GAAG;QAC7B,KAAK,EAAE,YAAY,CAAC,wBAAwB,KAAK,SAAS,IAAI,YAAY,CAAC,sBAAsB,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC;YAC5G,MAAM,CAAC,CAAC;YACR,MAAM;QACV,GAAG,YAAY;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,eAA0C;IACxE,MAAM,YAAY,GAAG,eAAe,CAAC,QAAQ,CAAC;IAC9C,MAAM,cAAc,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC;IAE5D,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IAED,MAAM,CAAC,wBAAwB,EAAE,sBAAsB,CAAC,GACpD,qBAAqB,CAAC,YAAY,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;IAEnE,OAAO,QAAQ,CAAC;QACd,aAAa,EAAE,wBAAwB,EAAE,0BAA0B;QACnE,wBAAwB;QACxB,sBAAsB;KACvB,CAAC,CAAC;AACL,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\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 Protocol from '../../../generated/protocol.js';\nimport type {Warning} from '../handlers/WarningsHandler.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {\n type BottomUpCallStack,\n type ForcedReflowAggregatedData,\n InsightCategory,\n InsightKeys,\n type InsightModel,\n type PartialInsightModel,\n type RequiredData,\n} from './types.js';\n\nexport function deps(): ['Warnings', 'Renderer'] {\n return ['Warnings', 'Renderer'];\n}\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 'Many APIs, typically reading layout geometry, force the rendering engine to pause script execution in order to calculate the style and layout. Learn more about [forced reflow](https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing#avoid-forced-synchronous-layouts) and its 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} 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\nfunction aggregateForcedReflow(\n data: Map<Warning, Types.Events.Event[]>,\n entryToNodeMap: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>):\n [ForcedReflowAggregatedData|undefined, BottomUpCallStack[]] {\n const dataByTopLevelFunction = new Map<string, ForcedReflowAggregatedData>();\n const bottomUpDataMap = new Map<string, BottomUpCallStack>();\n const forcedReflowEvents = data.get('FORCED_REFLOW');\n if (!forcedReflowEvents || forcedReflowEvents.length === 0) {\n return [undefined, []];\n }\n\n forcedReflowEvents.forEach(e => {\n // Gather the stack traces by searching in the tree\n const traceNode = entryToNodeMap.get(e);\n\n if (!traceNode) {\n return;\n }\n // Compute call stack fully\n const bottomUpData: Array<Types.Events.CallFrame|Protocol.Runtime.CallFrame> = [];\n let currentNode = traceNode;\n let previousNode;\n const childStack: Protocol.Runtime.CallFrame[] = [];\n\n // Some profileCalls maybe constructed as its children in hierarchy tree\n while (currentNode.children.length > 0) {\n const childNode = currentNode.children[0];\n if (!previousNode) {\n previousNode = childNode;\n }\n const eventData = childNode.entry;\n if (Types.Events.isProfileCall(eventData)) {\n childStack.push(eventData.callFrame);\n }\n currentNode = childNode;\n }\n\n // In order to avoid too much information, we only contain 2 levels bottomUp data,\n while (childStack.length > 0 && bottomUpData.length < 2) {\n const traceData = childStack.pop();\n if (traceData) {\n bottomUpData.push(traceData);\n }\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 if (bottomUpData.length < 2) {\n bottomUpData.push(eventData.callFrame);\n }\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 if (bottomUpData.length === 0) {\n bottomUpData.push(topLevelFunctionCall);\n }\n } else {\n // Sometimes the top level task can be other JSInvocation event\n // then we use the top level profile call as topLevelFunctionCall's data\n const previousData = previousNode?.entry;\n if (previousData && Types.Events.isProfileCall(previousData)) {\n topLevelFunctionCall = previousData.callFrame;\n topLevelFunctionCallEvent = previousNode?.entry;\n }\n }\n break;\n }\n previousNode = node;\n node = node.parent;\n }\n\n if (!topLevelFunctionCall || !topLevelFunctionCallEvent || bottomUpData.length === 0) {\n return;\n }\n const bottomUpDataId =\n bottomUpData[0].scriptId + ':' + bottomUpData[0].lineNumber + ':' + bottomUpData[0].columnNumber + ':';\n\n const data = bottomUpDataMap.get(bottomUpDataId) ?? {\n bottomUpData: bottomUpData[0],\n totalTime: 0,\n relatedEvents: [],\n };\n data.totalTime += (e.dur ?? 0);\n data.relatedEvents.push(e);\n bottomUpDataMap.set(bottomUpDataId, data);\n\n const aggregatedDataId =\n topLevelFunctionCall.scriptId + ':' + topLevelFunctionCall.lineNumber + ':' + topLevelFunctionCall.columnNumber;\n if (!dataByTopLevelFunction.has(aggregatedDataId)) {\n dataByTopLevelFunction.set(aggregatedDataId, {\n topLevelFunctionCall,\n totalReflowTime: 0,\n bottomUpData: new Set<string>(),\n topLevelFunctionCallEvents: [],\n });\n }\n const aggregatedData = dataByTopLevelFunction.get(aggregatedDataId);\n if (aggregatedData) {\n aggregatedData.totalReflowTime += (e.dur ?? 0);\n aggregatedData.bottomUpData.add(bottomUpDataId);\n aggregatedData.topLevelFunctionCallEvents.push(topLevelFunctionCallEvent);\n }\n });\n\n let topTimeConsumingDataId = '';\n let maxTime = 0;\n dataByTopLevelFunction.forEach((value, key) => {\n if (value.totalReflowTime > maxTime) {\n maxTime = value.totalReflowTime;\n topTimeConsumingDataId = key;\n }\n });\n\n const aggregatedBottomUpData: BottomUpCallStack[] = [];\n const topLevelFunctionCallData = dataByTopLevelFunction.get(topTimeConsumingDataId);\n const dataSet = dataByTopLevelFunction.get(topTimeConsumingDataId)?.bottomUpData;\n if (dataSet) {\n dataSet.forEach(value => {\n const callStackData = bottomUpDataMap.get(value);\n if (callStackData && callStackData.totalTime > Helpers.Timing.milliToMicro(Types.Timing.Milli(1))) {\n aggregatedBottomUpData.push(callStackData);\n }\n });\n }\n\n return [topLevelFunctionCallData, aggregatedBottomUpData];\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 category: InsightCategory.ALL,\n state: partialModel.topLevelFunctionCallData !== undefined && partialModel.aggregatedBottomUpData.length !== 0 ?\n 'fail' :\n 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(traceParsedData: RequiredData<typeof deps>): ForcedReflowInsightModel {\n const warningsData = traceParsedData.Warnings;\n const entryToNodeMap = traceParsedData.Renderer.entryToNode;\n\n if (!warningsData) {\n throw new Error('no warnings data');\n }\n\n if (!entryToNodeMap) {\n throw new Error('no renderer data');\n }\n\n const [topLevelFunctionCallData, aggregatedBottomUpData] =\n aggregateForcedReflow(warningsData.perWarning, entryToNodeMap);\n\n return finalize({\n relatedEvents: topLevelFunctionCallData?.topLevelFunctionCallEvents,\n topLevelFunctionCallData,\n aggregatedBottomUpData,\n });\n}\n"]}
@@ -4,46 +4,48 @@ export declare const UIStrings: {
4
4
  /**
5
5
  * @description Title of an insight that recommends ways to reduce the size of images downloaded and used on the page.
6
6
  */
7
- title: string;
7
+ readonly title: "Improve image delivery";
8
8
  /**
9
9
  * @description Description of an insight that recommends ways to reduce the size of images downloaded and used on the page.
10
10
  */
11
- description: string;
11
+ readonly description: "Reducing the download time of images can improve the perceived load time of the page and LCP. [Learn more about optimizing image size](https://developer.chrome.com/docs/lighthouse/performance/uses-optimized-images/)";
12
12
  /**
13
13
  * @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
14
- * @example {50 MB} PH1
15
14
  */
16
- useCompression: string;
15
+ readonly useCompression: "Increasing the image compression factor could improve this image's download size.";
17
16
  /**
18
17
  * @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
19
- * @example {50 MB} PH1
20
18
  */
21
- useModernFormat: string;
19
+ readonly useModernFormat: "Using a modern image format (WebP, AVIF) or increasing the image compression could improve this image's download size.";
22
20
  /**
23
21
  * @description Message displayed in a chip advising the user to use video formats instead of GIFs because videos generally have smaller file sizes.
24
- * @example {50 MB} PH1
25
22
  */
26
- useVideoFormat: string;
23
+ readonly useVideoFormat: "Using video formats instead of GIFs can improve the download size of animated content.";
27
24
  /**
28
25
  * @description Message displayed in a chip explaining that an image was displayed on the page with dimensions much smaller than the image file dimensions.
29
- * @example {50 MB} PH1
30
- * @example {1000x500} PH2
31
- * @example {100x50} PH3
26
+ * @example {1000x500} PH1
27
+ * @example {100x50} PH2
32
28
  */
33
- useResponsiveSize: string;
29
+ readonly useResponsiveSize: "This image file is larger than it needs to be ({PH1}) for its displayed dimensions ({PH2}). Use responsive images to reduce the image download size.";
34
30
  /**
35
31
  * @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
36
32
  */
37
- optimizeFile: string;
33
+ readonly optimizeFile: "Optimize file size";
38
34
  /**
39
35
  * @description Table row value representing the remaining items not shown in the table due to size constraints. This row will always represent at least 2 items.
40
36
  * @example {5} PH1
41
37
  */
42
- others: string;
38
+ readonly others: "{PH1} others";
43
39
  /**
44
40
  * @description Text status indicating that no potential optimizations were found for any image file
45
41
  */
46
- noOptimizableImages: string;
42
+ readonly noOptimizableImages: "No optimizable images";
43
+ /**
44
+ * @description Text describing the estimated number of bytes that an image file optimization can save. This text is appended to another block of text describing the image optimization in more detail. "Est" means "Estimated".
45
+ * @example {Use the correct image dimensions to reduce the image file size.} PH1
46
+ * @example {50 MB} PH2
47
+ */
48
+ readonly estimatedSavings: "{PH1} (Est {PH2})";
47
49
  };
48
50
  export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
49
51
  export declare function deps(): ['NetworkRequests', 'Meta', 'ImagePainting'];
@@ -85,4 +87,6 @@ export type ImageDeliveryInsightModel = InsightModel<typeof UIStrings, {
85
87
  optimizableImages: OptimizableImage[];
86
88
  totalByteSavings: number;
87
89
  }>;
90
+ export declare function getOptimizationMessage(optimization: ImageOptimization): string;
91
+ export declare function getOptimizationMessageWithBytes(optimization: ImageOptimization): string;
88
92
  export declare function generateInsight(parsedTrace: RequiredData<typeof deps>, context: InsightSetContext): ImageDeliveryInsightModel;
@@ -16,26 +16,22 @@ export const UIStrings = {
16
16
  description: 'Reducing the download time of images can improve the perceived load time of the page and LCP. [Learn more about optimizing image size](https://developer.chrome.com/docs/lighthouse/performance/uses-optimized-images/)',
17
17
  /**
18
18
  * @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
19
- * @example {50 MB} PH1
20
19
  */
21
- useCompression: 'Increasing the image compression factor could improve this image\'s download size. (Est {PH1})',
20
+ useCompression: 'Increasing the image compression factor could improve this image\'s download size.',
22
21
  /**
23
22
  * @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
24
- * @example {50 MB} PH1
25
23
  */
26
- useModernFormat: 'Using a modern image format (WebP, AVIF) or increasing the image compression could improve this image\'s download size. (Est {PH1})',
24
+ useModernFormat: 'Using a modern image format (WebP, AVIF) or increasing the image compression could improve this image\'s download size.',
27
25
  /**
28
26
  * @description Message displayed in a chip advising the user to use video formats instead of GIFs because videos generally have smaller file sizes.
29
- * @example {50 MB} PH1
30
27
  */
31
- useVideoFormat: 'Using video formats instead of GIFs can improve the download size of animated content. (Est {PH1})',
28
+ useVideoFormat: 'Using video formats instead of GIFs can improve the download size of animated content.',
32
29
  /**
33
30
  * @description Message displayed in a chip explaining that an image was displayed on the page with dimensions much smaller than the image file dimensions.
34
- * @example {50 MB} PH1
35
- * @example {1000x500} PH2
36
- * @example {100x50} PH3
31
+ * @example {1000x500} PH1
32
+ * @example {100x50} PH2
37
33
  */
38
- useResponsiveSize: 'This image file is larger than it needs to be ({PH2}) for its displayed dimensions ({PH3}). Use responsive images to reduce the image download size. (Est {PH1})',
34
+ useResponsiveSize: 'This image file is larger than it needs to be ({PH1}) for its displayed dimensions ({PH2}). Use responsive images to reduce the image download size.',
39
35
  /**
40
36
  * @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
41
37
  */
@@ -49,6 +45,12 @@ export const UIStrings = {
49
45
  * @description Text status indicating that no potential optimizations were found for any image file
50
46
  */
51
47
  noOptimizableImages: 'No optimizable images',
48
+ /**
49
+ * @description Text describing the estimated number of bytes that an image file optimization can save. This text is appended to another block of text describing the image optimization in more detail. "Est" means "Estimated".
50
+ * @example {Use the correct image dimensions to reduce the image file size.} PH1
51
+ * @example {50 MB} PH2
52
+ */
53
+ estimatedSavings: '{PH1} (Est {PH2})',
52
54
  };
53
55
  // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/ImageDelivery.ts', UIStrings);
54
56
  export const i18nString = (i18nId, values) => ({i18nId, values}); // i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -84,32 +86,36 @@ export var ImageOptimizationType;
84
86
  ImageOptimizationType["VIDEO_FORMAT"] = "VIDEO_FORMAT";
85
87
  ImageOptimizationType["RESPONSIVE_SIZE"] = "RESPONSIVE_SIZE";
86
88
  })(ImageOptimizationType || (ImageOptimizationType = {}));
87
- function getOptimizationMessage(optimization) {
88
- const byteSavingsText = (bytes => ({__i18nBytes: bytes}))(optimization.byteSavings);
89
+ export function getOptimizationMessage(optimization) {
89
90
  switch (optimization.type) {
90
91
  case ImageOptimizationType.ADJUST_COMPRESSION:
91
- return i18nString(UIStrings.useCompression, { PH1: byteSavingsText });
92
+ return i18nString(UIStrings.useCompression);
92
93
  case ImageOptimizationType.MODERN_FORMAT_OR_COMPRESSION:
93
- return i18nString(UIStrings.useModernFormat, { PH1: byteSavingsText });
94
+ return i18nString(UIStrings.useModernFormat);
94
95
  case ImageOptimizationType.VIDEO_FORMAT:
95
- return i18nString(UIStrings.useVideoFormat, { PH1: byteSavingsText });
96
+ return i18nString(UIStrings.useVideoFormat);
96
97
  case ImageOptimizationType.RESPONSIVE_SIZE:
97
98
  return i18nString(UIStrings.useResponsiveSize, {
98
- PH1: byteSavingsText,
99
- PH2: `${optimization.fileDimensions.width}x${optimization.fileDimensions.height}`,
100
- PH3: `${optimization.displayDimensions.width}x${optimization.displayDimensions.height}`,
99
+ PH1: `${optimization.fileDimensions.width}x${optimization.fileDimensions.height}`,
100
+ PH2: `${optimization.displayDimensions.width}x${optimization.displayDimensions.height}`,
101
101
  });
102
102
  }
103
103
  }
104
+ export function getOptimizationMessageWithBytes(optimization) {
105
+ const byteSavingsText = (bytes => ({__i18nBytes: bytes}))(optimization.byteSavings);
106
+ const optimizationMessage = getOptimizationMessage(optimization);
107
+ return i18nString(UIStrings.estimatedSavings, { PH1: optimizationMessage, PH2: byteSavingsText });
108
+ }
104
109
  function finalize(partialModel) {
105
110
  return {
111
+ insightKey: "ImageDelivery" /* InsightKeys.IMAGE_DELIVERY */,
106
112
  strings: UIStrings,
107
113
  title: i18nString(UIStrings.title),
108
114
  description: i18nString(UIStrings.description),
109
115
  category: InsightCategory.LCP,
110
- shouldShow: partialModel.optimizableImages.length > 0,
116
+ state: partialModel.optimizableImages.length > 0 ? 'fail' : 'pass',
111
117
  ...partialModel,
112
- relatedEvents: new Map(partialModel.optimizableImages.map(image => [image.request, image.optimizations.map(getOptimizationMessage)])),
118
+ relatedEvents: new Map(partialModel.optimizableImages.map(image => [image.request, image.optimizations.map(getOptimizationMessageWithBytes)])),
113
119
  };
114
120
  }
115
121
  /**