@paulirish/trace_engine 0.0.54 → 0.0.56

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 (288) hide show
  1. package/.tmp/tsbuildinfo/models/trace/extras/polyfills.d.ts +4 -0
  2. package/.tmp/tsbuildinfo/models/trace/extras/polyfills.d.ts.map +1 -0
  3. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  4. package/core/platform/MimeType.d.ts +3 -2
  5. package/core/platform/MimeType.js +4 -3
  6. package/core/platform/MimeType.js.map +1 -1
  7. package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  8. package/core/platform/platform.prebundle.d.ts +18 -0
  9. package/core/platform/platform.prebundle.js +53 -0
  10. package/core/platform/platform.prebundle.js.map +1 -0
  11. package/core/platform/platform.prebundle.ts +71 -0
  12. package/generated/protocol.d.ts +115 -16
  13. package/locales/af.json +52 -10
  14. package/locales/am.json +52 -10
  15. package/locales/ar.json +51 -9
  16. package/locales/as.json +52 -10
  17. package/locales/az.json +52 -10
  18. package/locales/be.json +52 -10
  19. package/locales/bg.json +52 -10
  20. package/locales/bn.json +52 -10
  21. package/locales/bs.json +52 -10
  22. package/locales/ca.json +52 -10
  23. package/locales/cs.json +52 -10
  24. package/locales/cy.json +52 -10
  25. package/locales/da.json +52 -10
  26. package/locales/de.json +52 -10
  27. package/locales/el.json +52 -10
  28. package/locales/en-GB.json +52 -10
  29. package/locales/en-US.json +70 -58
  30. package/locales/en-XL.json +70 -58
  31. package/locales/es-419.json +52 -10
  32. package/locales/es.json +50 -8
  33. package/locales/et.json +52 -10
  34. package/locales/eu.json +52 -10
  35. package/locales/fa.json +51 -9
  36. package/locales/fi.json +52 -10
  37. package/locales/fil.json +52 -10
  38. package/locales/fr-CA.json +52 -10
  39. package/locales/fr.json +52 -10
  40. package/locales/gl.json +52 -10
  41. package/locales/gu.json +52 -10
  42. package/locales/he.json +52 -10
  43. package/locales/hi.json +52 -10
  44. package/locales/hr.json +52 -10
  45. package/locales/hu.json +51 -9
  46. package/locales/hy.json +51 -9
  47. package/locales/id.json +52 -10
  48. package/locales/is.json +53 -11
  49. package/locales/it.json +51 -9
  50. package/locales/ja.json +52 -10
  51. package/locales/ka.json +53 -11
  52. package/locales/kk.json +51 -9
  53. package/locales/km.json +52 -10
  54. package/locales/kn.json +52 -10
  55. package/locales/ko.json +52 -10
  56. package/locales/ky.json +51 -9
  57. package/locales/lo.json +52 -10
  58. package/locales/lt.json +52 -10
  59. package/locales/lv.json +51 -9
  60. package/locales/mk.json +52 -10
  61. package/locales/ml.json +53 -11
  62. package/locales/mn.json +52 -10
  63. package/locales/mr.json +52 -10
  64. package/locales/ms.json +52 -10
  65. package/locales/my.json +51 -9
  66. package/locales/ne.json +52 -10
  67. package/locales/nl.json +52 -10
  68. package/locales/no.json +52 -10
  69. package/locales/or.json +53 -11
  70. package/locales/pa.json +53 -11
  71. package/locales/pl.json +51 -9
  72. package/locales/pt-PT.json +52 -10
  73. package/locales/pt.json +52 -10
  74. package/locales/ro.json +52 -10
  75. package/locales/ru.json +53 -11
  76. package/locales/si.json +52 -10
  77. package/locales/sk.json +51 -9
  78. package/locales/sl.json +51 -9
  79. package/locales/sq.json +52 -10
  80. package/locales/sr-Latn.json +52 -10
  81. package/locales/sr.json +52 -10
  82. package/locales/sv.json +52 -10
  83. package/locales/sw.json +51 -9
  84. package/locales/ta.json +52 -10
  85. package/locales/te.json +52 -10
  86. package/locales/th.json +51 -9
  87. package/locales/tr.json +52 -10
  88. package/locales/uk.json +52 -10
  89. package/locales/ur.json +52 -10
  90. package/locales/uz.json +51 -9
  91. package/locales/vi.json +52 -10
  92. package/locales/zh-HK.json +52 -10
  93. package/locales/zh-TW.json +51 -9
  94. package/locales/zh.json +52 -10
  95. package/locales/zu.json +52 -10
  96. package/models/cpu_profile/CPUProfileDataModel.d.ts +4 -2
  97. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  98. package/models/cpu_profile/ProfileTreeModel.d.ts +0 -1
  99. package/models/cpu_profile/ProfileTreeModel.js +0 -2
  100. package/models/cpu_profile/ProfileTreeModel.js.map +1 -1
  101. package/models/cpu_profile/cpu_profile.prebundle.d.ts +3 -0
  102. package/models/cpu_profile/cpu_profile.prebundle.js +7 -0
  103. package/models/cpu_profile/cpu_profile.prebundle.js.map +1 -0
  104. package/models/cpu_profile/cpu_profile.prebundle.ts +11 -0
  105. package/models/cpu_profile/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  106. package/models/trace/LanternComputationData.js +7 -6
  107. package/models/trace/LanternComputationData.js.map +1 -1
  108. package/models/trace/Processor.js +25 -18
  109. package/models/trace/Processor.js.map +1 -1
  110. package/models/trace/devtools_entrypoint-bundle-tsconfig-tsconfig.json +61 -0
  111. package/models/trace/{root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json → extras/devtools_entrypoint-bundle-tsconfig-tsconfig.json} +5 -4
  112. package/models/trace/extras/extras-tsconfig.json +0 -2
  113. package/models/trace/extras/extras.js.map +1 -1
  114. package/models/trace/extras/extras.prebundle.d.ts +7 -0
  115. package/models/trace/extras/extras.prebundle.js +11 -0
  116. package/models/trace/extras/extras.prebundle.js.map +1 -0
  117. package/models/trace/extras/extras.prebundle.ts +11 -0
  118. package/models/trace/handlers/ImagePaintingHandler.d.ts +7 -1
  119. package/models/trace/handlers/ImagePaintingHandler.js +33 -1
  120. package/models/trace/handlers/ImagePaintingHandler.js.map +1 -1
  121. package/models/trace/handlers/MetaHandler.js +2 -0
  122. package/models/trace/handlers/MetaHandler.js.map +1 -1
  123. package/models/trace/handlers/NetworkRequestsHandler.d.ts +0 -5
  124. package/models/trace/handlers/NetworkRequestsHandler.js +61 -20
  125. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  126. package/models/trace/handlers/SamplesHandler.js +7 -2
  127. package/models/trace/handlers/SamplesHandler.js.map +1 -1
  128. package/models/trace/handlers/ScriptsHandler.js.map +1 -1
  129. package/models/trace/{root-causes/root-causes-tsconfig.json → handlers/devtools_entrypoint-bundle-tsconfig-tsconfig.json} +5 -17
  130. package/models/trace/handlers/handlers.prebundle.d.ts +4 -0
  131. package/models/trace/handlers/handlers.prebundle.js +8 -0
  132. package/models/trace/handlers/handlers.prebundle.js.map +1 -0
  133. package/models/trace/handlers/handlers.prebundle.ts +8 -0
  134. package/models/trace/helpers/SamplesIntegrator.js +8 -13
  135. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  136. package/models/trace/helpers/Trace.js +0 -7
  137. package/models/trace/helpers/Trace.js.map +1 -1
  138. package/models/trace/helpers/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  139. package/models/trace/helpers/helpers.prebundle.d.ts +7 -0
  140. package/models/trace/helpers/helpers.prebundle.js +11 -0
  141. package/models/trace/helpers/helpers.prebundle.js.map +1 -0
  142. package/models/trace/helpers/helpers.prebundle.ts +11 -0
  143. package/models/trace/insights/CLSCulprits.d.ts +27 -7
  144. package/models/trace/insights/CLSCulprits.js +34 -15
  145. package/models/trace/insights/CLSCulprits.js.map +1 -1
  146. package/models/trace/insights/Common.d.ts +1 -1
  147. package/models/trace/insights/Common.js +3 -3
  148. package/models/trace/insights/Common.js.map +1 -1
  149. package/models/trace/insights/DOMSize.d.ts +26 -1
  150. package/models/trace/insights/DOMSize.js +34 -1
  151. package/models/trace/insights/DOMSize.js.map +1 -1
  152. package/models/trace/insights/DocumentLatency.d.ts +2 -2
  153. package/models/trace/insights/DocumentLatency.js +3 -3
  154. package/models/trace/insights/DocumentLatency.js.map +1 -1
  155. package/models/trace/insights/ForcedReflow.d.ts +1 -1
  156. package/models/trace/insights/ForcedReflow.js +1 -1
  157. package/models/trace/insights/ForcedReflow.js.map +1 -1
  158. package/models/trace/insights/{InteractionToNextPaint.d.ts → INPBreakdown.d.ts} +8 -8
  159. package/models/trace/insights/{InteractionToNextPaint.js → INPBreakdown.js} +10 -10
  160. package/models/trace/insights/INPBreakdown.js.map +1 -0
  161. package/models/trace/insights/ImageDelivery.js +18 -7
  162. package/models/trace/insights/ImageDelivery.js.map +1 -1
  163. package/models/trace/insights/{LCPPhases.d.ts → LCPBreakdown.d.ts} +26 -22
  164. package/models/trace/insights/{LCPPhases.js → LCPBreakdown.js} +56 -46
  165. package/models/trace/insights/LCPBreakdown.js.map +1 -0
  166. package/models/trace/insights/LCPDiscovery.js +1 -1
  167. package/models/trace/insights/LCPDiscovery.js.map +1 -1
  168. package/models/trace/insights/Models.d.ts +2 -2
  169. package/models/trace/insights/Models.js +2 -2
  170. package/models/trace/insights/Models.js.map +1 -1
  171. package/models/trace/insights/NetworkDependencyTree.d.ts +34 -8
  172. package/models/trace/insights/NetworkDependencyTree.js +144 -18
  173. package/models/trace/insights/NetworkDependencyTree.js.map +1 -1
  174. package/models/trace/insights/Viewport.d.ts +8 -2
  175. package/models/trace/insights/Viewport.js +16 -1
  176. package/models/trace/insights/Viewport.js.map +1 -1
  177. package/models/trace/insights/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  178. package/models/trace/insights/insights-tsconfig.json +2 -2
  179. package/models/trace/insights/insights.prebundle.d.ts +4 -0
  180. package/models/trace/insights/insights.prebundle.js +8 -0
  181. package/models/trace/insights/insights.prebundle.js.map +1 -0
  182. package/models/trace/insights/insights.prebundle.ts +8 -0
  183. package/models/trace/insights/types.d.ts +2 -2
  184. package/models/trace/insights/types.js +2 -2
  185. package/models/trace/insights/types.js.map +1 -1
  186. package/models/trace/lantern/core/core.prebundle.d.ts +2 -0
  187. package/models/trace/lantern/core/core.prebundle.js +6 -0
  188. package/models/trace/lantern/core/core.prebundle.js.map +1 -0
  189. package/models/trace/lantern/core/core.prebundle.ts +6 -0
  190. package/models/trace/lantern/core/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  191. package/models/trace/lantern/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  192. package/models/trace/lantern/graph/BaseNode.d.ts +5 -2
  193. package/models/trace/lantern/graph/BaseNode.js +8 -5
  194. package/models/trace/lantern/graph/BaseNode.js.map +1 -1
  195. package/models/trace/lantern/graph/PageDependencyGraph.js +46 -3
  196. package/models/trace/lantern/graph/PageDependencyGraph.js.map +1 -1
  197. package/models/trace/lantern/graph/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  198. package/models/trace/lantern/graph/graph.prebundle.d.ts +4 -0
  199. package/models/trace/lantern/graph/graph.prebundle.js +8 -0
  200. package/models/trace/lantern/graph/graph.prebundle.js.map +1 -0
  201. package/models/trace/lantern/graph/graph.prebundle.ts +8 -0
  202. package/models/trace/lantern/lantern.prebundle.d.ts +6 -0
  203. package/models/trace/lantern/lantern.prebundle.js +10 -0
  204. package/models/trace/lantern/lantern.prebundle.js.map +1 -0
  205. package/models/trace/lantern/lantern.prebundle.ts +17 -0
  206. package/models/trace/lantern/metrics/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  207. package/models/trace/lantern/metrics/metrics.prebundle.d.ts +8 -0
  208. package/models/trace/lantern/metrics/metrics.prebundle.js +12 -0
  209. package/models/trace/lantern/metrics/metrics.prebundle.js.map +1 -0
  210. package/models/trace/lantern/metrics/metrics.prebundle.ts +12 -0
  211. package/models/trace/lantern/simulation/Simulator.js +1 -1
  212. package/models/trace/lantern/simulation/Simulator.js.map +1 -1
  213. package/models/trace/lantern/simulation/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  214. package/models/trace/lantern/simulation/simulation.prebundle.d.ts +6 -0
  215. package/models/trace/lantern/simulation/simulation.prebundle.js +10 -0
  216. package/models/trace/lantern/simulation/simulation.prebundle.js.map +1 -0
  217. package/models/trace/lantern/simulation/simulation.prebundle.ts +10 -0
  218. package/models/trace/lantern/types/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  219. package/models/trace/lantern/types/types.prebundle.d.ts +1 -0
  220. package/models/trace/lantern/types/types.prebundle.js +5 -0
  221. package/models/trace/lantern/types/types.prebundle.js.map +1 -0
  222. package/models/trace/lantern/types/types.prebundle.ts +5 -0
  223. package/models/trace/trace-tsconfig.json +0 -1
  224. package/models/trace/trace.d.ts +1 -2
  225. package/models/trace/trace.js +1 -2
  226. package/models/trace/trace.js.map +1 -1
  227. package/models/trace/trace.prebundle.d.ts +10 -0
  228. package/models/trace/trace.prebundle.js +14 -0
  229. package/models/trace/trace.prebundle.js.map +1 -0
  230. package/models/trace/trace.prebundle.ts +25 -0
  231. package/models/trace/types/Extensions.d.ts +6 -1
  232. package/models/trace/types/Extensions.js.map +1 -1
  233. package/models/trace/types/File.d.ts +16 -1
  234. package/models/trace/types/File.js.map +1 -1
  235. package/models/trace/types/Timing.js.map +1 -1
  236. package/models/trace/types/TraceEvents.d.ts +7 -4
  237. package/models/trace/types/TraceEvents.js +4 -3
  238. package/models/trace/types/TraceEvents.js.map +1 -1
  239. package/models/trace/types/devtools_entrypoint-bundle-tsconfig-tsconfig.json +43 -0
  240. package/models/trace/types/types.prebundle.d.ts +5 -0
  241. package/models/trace/types/types.prebundle.js +9 -0
  242. package/models/trace/types/types.prebundle.js.map +1 -0
  243. package/models/trace/types/types.prebundle.ts +9 -0
  244. package/package.json +1 -1
  245. package/test/test-trace-engine.mjs +2 -2
  246. package/core/platform/ServerTiming.d.ts +0 -31
  247. package/core/platform/ServerTiming.js +0 -212
  248. package/core/platform/ServerTiming.js.map +0 -1
  249. package/models/trace/TracingManager.js.map +0 -1
  250. package/models/trace/extras/FetchNodes.d.ts +0 -61
  251. package/models/trace/extras/FetchNodes.js +0 -214
  252. package/models/trace/extras/FetchNodes.js.map +0 -1
  253. package/models/trace/extras/Metadata.d.ts +0 -3
  254. package/models/trace/extras/Metadata.js +0 -71
  255. package/models/trace/extras/Metadata.js.map +0 -1
  256. package/models/trace/extras/TimelineJSProfile.d.ts +0 -13
  257. package/models/trace/extras/TimelineJSProfile.js +0 -55
  258. package/models/trace/extras/TimelineJSProfile.js.map +0 -1
  259. package/models/trace/extras/URLForEntry.d.ts +0 -12
  260. package/models/trace/extras/URLForEntry.js +0 -43
  261. package/models/trace/extras/URLForEntry.js.map +0 -1
  262. package/models/trace/handlers/ServerTimingsHandler.d.ts +0 -9
  263. package/models/trace/handlers/ServerTimingsHandler.js +0 -106
  264. package/models/trace/handlers/ServerTimingsHandler.js.map +0 -1
  265. package/models/trace/insights/CumulativeLayoutShift.d.ts +0 -57
  266. package/models/trace/insights/CumulativeLayoutShift.js +0 -335
  267. package/models/trace/insights/CumulativeLayoutShift.js.map +0 -1
  268. package/models/trace/insights/InsightRunners.d.ts +0 -9
  269. package/models/trace/insights/InsightRunners.js +0 -13
  270. package/models/trace/insights/InsightRunners.js.map +0 -1
  271. package/models/trace/insights/InteractionToNextPaint.js.map +0 -1
  272. package/models/trace/insights/LCPPhases.js.map +0 -1
  273. package/models/trace/insights/LargestContentfulPaint.d.ts +0 -38
  274. package/models/trace/insights/LargestContentfulPaint.js +0 -113
  275. package/models/trace/insights/LargestContentfulPaint.js.map +0 -1
  276. package/models/trace/insights/ThirdPartyWeb.d.ts +0 -13
  277. package/models/trace/insights/ThirdPartyWeb.js +0 -42
  278. package/models/trace/insights/ThirdPartyWeb.js.map +0 -1
  279. package/models/trace/root-causes/LayoutShift.d.ts +0 -125
  280. package/models/trace/root-causes/LayoutShift.js +0 -519
  281. package/models/trace/root-causes/LayoutShift.js.map +0 -1
  282. package/models/trace/root-causes/RootCauses.d.ts +0 -15
  283. package/models/trace/root-causes/RootCauses.js +0 -12
  284. package/models/trace/root-causes/RootCauses.js.map +0 -1
  285. package/models/trace/root-causes/bundle-tsconfig.json +0 -1
  286. package/models/trace/root-causes/root-causes.d.ts +0 -1
  287. package/models/trace/root-causes/root-causes.js +0 -5
  288. package/models/trace/root-causes/root-causes.js.map +0 -1
@@ -1,4 +1,5 @@
1
- import type * as Handlers from '../handlers/handlers.js';
1
+ import * as Platform from '../../../core/platform/platform.js';
2
+ import * as Handlers from '../handlers/handlers.js';
2
3
  import type * as Types from '../types/types.js';
3
4
  import { type InsightModel, type InsightSetContext } from './types.js';
4
5
  export declare const UIStrings: {
@@ -8,10 +9,15 @@ export declare const UIStrings: {
8
9
  * @description Text to tell the user how a viewport meta element can improve performance. \xa0 is a non-breaking space
9
10
  */
10
11
  readonly description: "Tap interactions may be [delayed by up to 300 ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/) if the viewport is not optimized for mobile.";
12
+ /**
13
+ * @description Text for a label describing the portion of an interaction event that was delayed due to a bad mobile viewport.
14
+ */
15
+ readonly mobileTapDelayLabel: "Mobile tap delay";
11
16
  };
12
- export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => Record<string, string>;
17
+ export declare const i18nString: (id: string, values?: Record<string, string> | undefined) => {i18nId: string, values: Record<string, string|number>, formattedDefault: string};
13
18
  export type ViewportInsightModel = InsightModel<typeof UIStrings, {
14
19
  mobileOptimized: boolean | null;
15
20
  viewportEvent?: Types.Events.ParseMetaViewport;
21
+ longPointerInteractions?: Types.Events.SyntheticInteractionPair[];
16
22
  }>;
17
23
  export declare function generateInsight(parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): ViewportInsightModel;
@@ -2,6 +2,8 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  // import * as i18n from '../../../core/i18n/i18n.js';
5
+ import * as Platform from '../../../core/platform/platform.js';
6
+ import * as Handlers from '../handlers/handlers.js';
5
7
  import * as Helpers from '../helpers/helpers.js';
6
8
  import { InsightCategory, InsightKeys, InsightWarning, } from './types.js';
7
9
  export const UIStrings = {
@@ -11,6 +13,10 @@ export const UIStrings = {
11
13
  * @description Text to tell the user how a viewport meta element can improve performance. \xa0 is a non-breaking space
12
14
  */
13
15
  description: 'Tap interactions may be [delayed by up to 300\xA0ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/) if the viewport is not optimized for mobile.',
16
+ /**
17
+ * @description Text for a label describing the portion of an interaction event that was delayed due to a bad mobile viewport.
18
+ */
19
+ mobileTapDelayLabel: 'Mobile tap delay',
14
20
  };
15
21
  // const str_ = i18n.i18n.registerUIStrings('models/trace/insights/Viewport.ts', UIStrings);
16
22
  export const i18nString = (i18nId, values) => ({i18nId, values}); // i18n.i18n.getLocalizedString.bind(undefined, str_);
@@ -53,10 +59,19 @@ export function generateInsight(parsedTrace, context) {
53
59
  // Returns true only if all events are mobile optimized.
54
60
  for (const event of compositorEvents) {
55
61
  if (!event.args.is_mobile_optimized) {
62
+ // Grab all the pointer events with at least 50ms of input delay.
63
+ const longPointerInteractions = [...parsedTrace.UserInteractions.interactionsOverThreshold.values()].filter(interaction => Handlers.ModelHandlers.UserInteractions.categoryOfInteraction(interaction) === 'POINTER' &&
64
+ interaction.inputDelay >= 50_000);
65
+ // The actual impact varies between 0 and 300.
66
+ // Using inputDelay as the closest thing we have for measuring this, though inputDelay may be high for other reasons.
67
+ // b/371566378#comment8
68
+ const inputDelay = Math.max(0, ...longPointerInteractions.map(interaction => interaction.inputDelay)) / 1000;
69
+ const inpMetricSavings = Platform.NumberUtilities.clamp(inputDelay, 0, 300);
56
70
  return finalize({
57
71
  mobileOptimized: false,
58
72
  viewportEvent,
59
- metricSavings: { INP: 300 },
73
+ longPointerInteractions,
74
+ metricSavings: { INP: inpMetricSavings },
60
75
  });
61
76
  }
62
77
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Viewport.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/Viewport.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,4BAA4B,CAAC;AAEnD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AAGjD,OAAO,EACL,eAAe,EACf,WAAW,EAGX,cAAc,GAEf,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,8GAA8G;IAC9G,KAAK,EAAE,8BAA8B;IACrC;;OAEG;IACH,WAAW,EACP,iKAAiK;CAC7J,CAAC;AAEX,MAAM,IAA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IAAI,KAAK,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,EAAE,CAAC;YACjD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC;QAC7B,uCAAuC;QACvC,OAAO,QAAQ,CAAC;YACd,eAAe,EAAE,IAAI;YACrB,QAAQ,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC;SACrC,CAAC,CAAC;IACL,CAAC;IAED,wDAAwD;IACxD,KAAK,MAAM,KAAK,IAAI,gBAAgB,EAAE,CAAC;QACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,OAAO,QAAQ,CAAC;gBACd,eAAe,EAAE,KAAK;gBACtB,aAAa;gBACb,aAAa,EAAE,EAAC,GAAG,EAAE,GAAyB,EAAC;aAChD,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,eAAe,EAAE,IAAI;QACrB,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 type * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\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 /** Title of an insight that provides details about if the page's viewport is optimized for mobile viewing. */\n title: 'Optimize viewport for mobile',\n /**\n * @description Text to tell the user how a viewport meta element can improve performance. \\xa0 is a non-breaking space\n */\n description:\n 'Tap interactions may be [delayed by up to 300\\xA0ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/) if the viewport is not optimized for mobile.',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/Viewport.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type ViewportInsightModel = InsightModel<typeof UIStrings, {\n mobileOptimized: boolean | null,\n viewportEvent?: Types.Events.ParseMetaViewport,\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<ViewportInsightModel>): ViewportInsightModel {\n return {\n insightKey: InsightKeys.VIEWPORT,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n state: partialModel.mobileOptimized === false ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): ViewportInsightModel {\n const viewportEvent = parsedTrace.UserInteractions.parseMetaViewportEvents.find(event => {\n if (event.args.data.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n const compositorEvents = parsedTrace.UserInteractions.beginCommitCompositorFrameEvents.filter(event => {\n if (event.args.frame !== context.frameId) {\n return false;\n }\n\n // Commit compositor frame events can be emitted before the viewport tag is parsed.\n // We shouldn't count these since the browser hasn't had time to make the viewport mobile optimized.\n if (viewportEvent && event.ts < viewportEvent.ts) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n if (!compositorEvents.length) {\n // Trace doesn't have the data we need.\n return finalize({\n mobileOptimized: null,\n warnings: [InsightWarning.NO_LAYOUT],\n });\n }\n\n // Returns true only if all events are mobile optimized.\n for (const event of compositorEvents) {\n if (!event.args.is_mobile_optimized) {\n return finalize({\n mobileOptimized: false,\n viewportEvent,\n metricSavings: {INP: 300 as Types.Timing.Milli},\n });\n }\n }\n\n return finalize({\n mobileOptimized: true,\n viewportEvent,\n });\n}\n"]}
1
+ {"version":3,"file":"Viewport.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,QAAQ,CAAC,aAAa,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,WAAW,CAAC,KAAK,SAAS;gBACnG,WAAW,CAAC,UAAU,IAAI,MAAM,CAAC,CAAC;YAE1C,8CAA8C;YAC9C,qHAAqH;YACrH,uBAAuB;YACvB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,uBAAuB,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC;YAC7G,MAAM,gBAAgB,GAAG,QAAQ,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;YAE5E,OAAO,QAAQ,CAAC;gBACd,eAAe,EAAE,KAAK;gBACtB,aAAa;gBACb,uBAAuB;gBACvB,aAAa,EAAE,EAAC,GAAG,EAAE,gBAAsC,EAAC;aAC7D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;QACd,eAAe,EAAE,IAAI;QACrB,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 Platform from '../../../core/platform/platform.js';\nimport * as Handlers from '../handlers/handlers.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport type * as Types from '../types/types.js';\n\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 /** Title of an insight that provides details about if the page's viewport is optimized for mobile viewing. */\n title: 'Optimize viewport for mobile',\n /**\n * @description Text to tell the user how a viewport meta element can improve performance. \\xa0 is a non-breaking space\n */\n description:\n 'Tap interactions may be [delayed by up to 300\\xA0ms](https://developer.chrome.com/blog/300ms-tap-delay-gone-away/) if the viewport is not optimized for mobile.',\n /**\n * @description Text for a label describing the portion of an interaction event that was delayed due to a bad mobile viewport.\n */\n mobileTapDelayLabel: 'Mobile tap delay',\n} as const;\n\nconst str_ = i18n.i18n.registerUIStrings('models/trace/insights/Viewport.ts', UIStrings);\nexport const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);\n\nexport type ViewportInsightModel = InsightModel<typeof UIStrings, {\n mobileOptimized: boolean | null,\n viewportEvent?: Types.Events.ParseMetaViewport,\n longPointerInteractions?: Types.Events.SyntheticInteractionPair[],\n}>;\n\nfunction finalize(partialModel: PartialInsightModel<ViewportInsightModel>): ViewportInsightModel {\n return {\n insightKey: InsightKeys.VIEWPORT,\n strings: UIStrings,\n title: i18nString(UIStrings.title),\n description: i18nString(UIStrings.description),\n category: InsightCategory.INP,\n state: partialModel.mobileOptimized === false ? 'fail' : 'pass',\n ...partialModel,\n };\n}\n\nexport function generateInsight(\n parsedTrace: Handlers.Types.ParsedTrace, context: InsightSetContext): ViewportInsightModel {\n const viewportEvent = parsedTrace.UserInteractions.parseMetaViewportEvents.find(event => {\n if (event.args.data.frame !== context.frameId) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n const compositorEvents = parsedTrace.UserInteractions.beginCommitCompositorFrameEvents.filter(event => {\n if (event.args.frame !== context.frameId) {\n return false;\n }\n\n // Commit compositor frame events can be emitted before the viewport tag is parsed.\n // We shouldn't count these since the browser hasn't had time to make the viewport mobile optimized.\n if (viewportEvent && event.ts < viewportEvent.ts) {\n return false;\n }\n\n return Helpers.Timing.eventIsInBounds(event, context.bounds);\n });\n\n if (!compositorEvents.length) {\n // Trace doesn't have the data we need.\n return finalize({\n mobileOptimized: null,\n warnings: [InsightWarning.NO_LAYOUT],\n });\n }\n\n // Returns true only if all events are mobile optimized.\n for (const event of compositorEvents) {\n if (!event.args.is_mobile_optimized) {\n // Grab all the pointer events with at least 50ms of input delay.\n const longPointerInteractions = [...parsedTrace.UserInteractions.interactionsOverThreshold.values()].filter(\n interaction => Handlers.ModelHandlers.UserInteractions.categoryOfInteraction(interaction) === 'POINTER' &&\n interaction.inputDelay >= 50_000);\n\n // The actual impact varies between 0 and 300.\n // Using inputDelay as the closest thing we have for measuring this, though inputDelay may be high for other reasons.\n // b/371566378#comment8\n const inputDelay = Math.max(0, ...longPointerInteractions.map(interaction => interaction.inputDelay)) / 1000;\n const inpMetricSavings = Platform.NumberUtilities.clamp(inputDelay, 0, 300);\n\n return finalize({\n mobileOptimized: false,\n viewportEvent,\n longPointerInteractions,\n metricSavings: {INP: inpMetricSavings as Types.Timing.Milli},\n });\n }\n }\n\n return finalize({\n mobileOptimized: true,\n viewportEvent,\n });\n}\n"]}
@@ -0,0 +1,43 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
+ "outDir": ".",
23
+ "rootDir": ".",
24
+ "skipLibCheck": true,
25
+ "sourceMap": true,
26
+ "strict": true,
27
+ "target": "esnext",
28
+ "tsBuildInfoFile": "devtools_entrypoint-bundle-tsconfig-tsconfig.json.tsbuildinfo",
29
+ "typeRoots": [],
30
+ "useUnknownInCatchVariables": false
31
+ },
32
+ "files": [
33
+ "insights.prebundle.ts",
34
+ "../../../../../../../front_end/legacy/legacy-defs.d.ts",
35
+ "../../../../../../../front_end/global_typings/global_defs.d.ts",
36
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts"
37
+ ],
38
+ "references": [
39
+ {
40
+ "path": "./insights-tsconfig.json"
41
+ }
42
+ ]
43
+ }
@@ -38,10 +38,10 @@
38
38
  "../../../../../../../front_end/models/trace/insights/DuplicatedJavaScript.ts",
39
39
  "../../../../../../../front_end/models/trace/insights/FontDisplay.ts",
40
40
  "../../../../../../../front_end/models/trace/insights/ForcedReflow.ts",
41
+ "../../../../../../../front_end/models/trace/insights/INPBreakdown.ts",
41
42
  "../../../../../../../front_end/models/trace/insights/ImageDelivery.ts",
42
- "../../../../../../../front_end/models/trace/insights/InteractionToNextPaint.ts",
43
+ "../../../../../../../front_end/models/trace/insights/LCPBreakdown.ts",
43
44
  "../../../../../../../front_end/models/trace/insights/LCPDiscovery.ts",
44
- "../../../../../../../front_end/models/trace/insights/LCPPhases.ts",
45
45
  "../../../../../../../front_end/models/trace/insights/LegacyJavaScript.ts",
46
46
  "../../../../../../../front_end/models/trace/insights/Models.ts",
47
47
  "../../../../../../../front_end/models/trace/insights/ModernHTTP.ts",
@@ -0,0 +1,4 @@
1
+ export * as Common from './Common.js';
2
+ export * as Models from './Models.js';
3
+ export * as Statistics from './Statistics.js';
4
+ export * as Types from './types.js';
@@ -0,0 +1,8 @@
1
+ // Copyright 2024 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
+ export * as Common from './Common.js';
5
+ export * as Models from './Models.js';
6
+ export * as Statistics from './Statistics.js';
7
+ export * as Types from './types.js';
8
+ //# sourceMappingURL=insights.prebundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insights.prebundle.js","sourceRoot":"","sources":["insights.prebundle.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,KAAK,UAAU,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,KAAK,MAAM,YAAY,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\nexport * as Common from './Common.js';\nexport * as Models from './Models.js';\nexport * as Statistics from './Statistics.js';\nexport * as Types from './types.js';\n"]}
@@ -0,0 +1,8 @@
1
+ // Copyright 2024 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
+
5
+ export * as Common from './Common.js';
6
+ export * as Models from './Models.js';
7
+ export * as Statistics from './Statistics.js';
8
+ export * as Types from './types.js';
@@ -107,8 +107,8 @@ export type InsightModels = {
107
107
  */
108
108
  export type TraceInsightSets = Map<Types.Events.NavigationId, InsightSet>;
109
109
  export declare enum InsightKeys {
110
- LCP_PHASES = "LCPPhases",
111
- INTERACTION_TO_NEXT_PAINT = "InteractionToNextPaint",
110
+ LCP_BREAKDOWN = "LCPBreakdown",
111
+ INP_BREAKDOWN = "INPBreakdown",
112
112
  CLS_CULPRITS = "CLSCulprits",
113
113
  THIRD_PARTIES = "ThirdParties",
114
114
  DOCUMENT_LATENCY = "DocumentLatency",
@@ -18,8 +18,8 @@ export var InsightCategory;
18
18
  })(InsightCategory || (InsightCategory = {}));
19
19
  export var InsightKeys;
20
20
  (function (InsightKeys) {
21
- InsightKeys["LCP_PHASES"] = "LCPPhases";
22
- InsightKeys["INTERACTION_TO_NEXT_PAINT"] = "InteractionToNextPaint";
21
+ InsightKeys["LCP_BREAKDOWN"] = "LCPBreakdown";
22
+ InsightKeys["INP_BREAKDOWN"] = "INPBreakdown";
23
23
  InsightKeys["CLS_CULPRITS"] = "CLSCulprits";
24
24
  InsightKeys["THIRD_PARTIES"] = "ThirdParties";
25
25
  InsightKeys["DOCUMENT_LATENCY"] = "DocumentLatency";
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAoC7B,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,uEAAuE;IACvE,6DAA2C,CAAA;IAC3C,yCAAuB,CAAA;AACzB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAYD,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;AACb,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B;AAuED,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,uCAAwB,CAAA;IACxB,mEAAoD,CAAA;IACpD,2CAA4B,CAAA;IAC5B,6CAA8B,CAAA;IAC9B,mDAAoC,CAAA;IACpC,mCAAoB,CAAA;IACpB,4DAA6C,CAAA;IAC7C,2CAA4B,CAAA;IAC5B,6CAA8B,CAAA;IAC9B,+CAAgC,CAAA;IAChC,6CAA8B,CAAA;IAC9B,qDAAsC,CAAA;IACtC,gEAAiD,CAAA;IACjD,iDAAkC,CAAA;IAClC,oDAAqC,CAAA;IACrC,oCAAqB,CAAA;AACvB,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB","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 type * as Common from '../../../core/common/common.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport type * as Types from '../types/types.js';\n\nimport type * as Models from './Models.js';\n\n/**\n * Context for the portion of the trace an insight should look at.\n */\nexport type InsightSetContext = InsightSetContextWithoutNavigation|InsightSetContextWithNavigation;\n\nexport interface InsightSetContextWithoutNavigation {\n bounds: Types.Timing.TraceWindowMicro;\n frameId: string;\n navigation?: never;\n}\n\nexport interface InsightSetContextWithNavigation {\n bounds: Types.Timing.TraceWindowMicro;\n frameId: string;\n navigation: Types.Events.NavigationStart;\n navigationId: string;\n lantern?: LanternContext;\n}\n\nexport interface LanternContext {\n requests: Array<Lantern.Types.NetworkRequest<Types.Events.SyntheticNetworkRequest>>;\n graph: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>;\n simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest>;\n metrics: Record<string, Lantern.Metrics.MetricResult>;\n}\n\nexport type InsightModelsType = typeof Models;\n\nexport enum InsightWarning {\n NO_FP = 'NO_FP',\n NO_LCP = 'NO_LCP',\n // No network request could be identified as the primary HTML document.\n NO_DOCUMENT_REQUEST = 'NO_DOCUMENT_REQUEST',\n NO_LAYOUT = 'NO_LAYOUT',\n}\n\nexport interface MetricSavings {\n /* eslint-disable @typescript-eslint/naming-convention */\n FCP?: Types.Timing.Milli;\n LCP?: Types.Timing.Milli;\n TBT?: Types.Timing.Milli;\n CLS?: number;\n INP?: Types.Timing.Milli;\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\nexport enum InsightCategory {\n ALL = 'All',\n INP = 'INP',\n LCP = 'LCP',\n CLS = 'CLS',\n}\n\nexport type RelatedEventsMap = Map<Types.Events.Event, string[]>;\n\nexport type Checklist<Keys extends string> = Record<Keys, {label: Common.UIString.LocalizedString, value: boolean}>;\n\nexport type InsightModel<UIStrings extends Record<string, string> = Record<string, string>,\n ExtraDetail extends Record<string, unknown> = Record<string, unknown>> =\n ExtraDetail&{\n /** Used internally to identify the type of a model, not shown visibly to users **/\n insightKey: keyof InsightModelsType,\n /** Not used within DevTools - this is for external consumers (like Lighthouse). */\n strings: UIStrings,\n title: Common.UIString.LocalizedString,\n description: Common.UIString.LocalizedString,\n category: InsightCategory,\n state: 'pass' | 'fail' | 'informative',\n /** Used by RelatedInsightChips.ts */\n relatedEvents?: RelatedEventsMap | Types.Events.Event[],\n warnings?: InsightWarning[],\n metricSavings?: MetricSavings,\n /**\n * An estimate for the number of bytes that this insight deems to have been wasted.\n * Bytes are in terms of transfer size: for each component of savings related to an\n * individual request, the insight will estimate its impact on transfer size by using\n * the compression ratio of the resource.\n *\n * This field is only displayed for informational purposes.\n */\n wastedBytes?: number,\n frameId?: string,\n /**\n * If this insight is attached to a navigation, this stores its ID.\n */\n navigationId?: string,\n };\n\nexport type PartialInsightModel<T> =\n Omit<T, 'strings'|'title'|'description'|'category'|'state'|'insightKey'|'navigationId'|'frameId'>;\n\n/**\n * Contains insights for a specific navigation. If a trace began after a navigation already started,\n * this could instead represent the duration from the beginning of the trace up to the first recorded\n * navigation (or the end of the trace).\n */\nexport interface InsightSet {\n /** If for a navigation, this is the navigationId. Else it is Trace.Types.Events.NO_NAVIGATION. */\n id: Types.Events.NavigationId;\n /** The URL to show in the accordion list. */\n url: URL;\n frameId: string;\n bounds: Types.Timing.TraceWindowMicro;\n model: InsightModels;\n navigation?: Types.Events.NavigationStart;\n}\n\n/**\n * Contains insights for a specific insight set.\n */\nexport type InsightModels = {\n [I in keyof InsightModelsType]: ReturnType<InsightModelsType[I]['generateInsight']>;\n};\n\n/**\n * Contains insights for the entire trace. Insights are mostly grouped by `navigationId`, with one exception:\n *\n * If the analyzed trace started after the navigation, and has meaningful work with that span, there is no\n * navigation to map it to. In this case `Types.Events.NO_NAVIGATION` is used for the key.\n */\nexport type TraceInsightSets = Map<Types.Events.NavigationId, InsightSet>;\n\nexport enum InsightKeys {\n LCP_PHASES = 'LCPPhases',\n INTERACTION_TO_NEXT_PAINT = 'InteractionToNextPaint',\n CLS_CULPRITS = 'CLSCulprits',\n THIRD_PARTIES = 'ThirdParties',\n DOCUMENT_LATENCY = 'DocumentLatency',\n DOM_SIZE = 'DOMSize',\n DUPLICATE_JAVASCRIPT = 'DuplicatedJavaScript',\n FONT_DISPLAY = 'FontDisplay',\n FORCED_REFLOW = 'ForcedReflow',\n IMAGE_DELIVERY = 'ImageDelivery',\n LCP_DISCOVERY = 'LCPDiscovery',\n LEGACY_JAVASCRIPT = 'LegacyJavaScript',\n NETWORK_DEPENDENCY_TREE = 'NetworkDependencyTree',\n RENDER_BLOCKING = 'RenderBlocking',\n SLOW_CSS_SELECTOR = 'SlowCSSSelector',\n VIEWPORT = 'Viewport',\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/insights/types.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAoC7B,MAAM,CAAN,IAAY,cAMX;AAND,WAAY,cAAc;IACxB,iCAAe,CAAA;IACf,mCAAiB,CAAA;IACjB,uEAAuE;IACvE,6DAA2C,CAAA;IAC3C,yCAAuB,CAAA;AACzB,CAAC,EANW,cAAc,KAAd,cAAc,QAMzB;AAYD,MAAM,CAAN,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;IACX,8BAAW,CAAA;AACb,CAAC,EALW,eAAe,KAAf,eAAe,QAK1B;AAuED,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,6CAA8B,CAAA;IAC9B,6CAA8B,CAAA;IAC9B,2CAA4B,CAAA;IAC5B,6CAA8B,CAAA;IAC9B,mDAAoC,CAAA;IACpC,mCAAoB,CAAA;IACpB,4DAA6C,CAAA;IAC7C,2CAA4B,CAAA;IAC5B,6CAA8B,CAAA;IAC9B,+CAAgC,CAAA;IAChC,6CAA8B,CAAA;IAC9B,qDAAsC,CAAA;IACtC,gEAAiD,CAAA;IACjD,iDAAkC,CAAA;IAClC,oDAAqC,CAAA;IACrC,oCAAqB,CAAA;AACvB,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB","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 type * as Common from '../../../core/common/common.js';\nimport type * as Lantern from '../lantern/lantern.js';\nimport type * as Types from '../types/types.js';\n\nimport type * as Models from './Models.js';\n\n/**\n * Context for the portion of the trace an insight should look at.\n */\nexport type InsightSetContext = InsightSetContextWithoutNavigation|InsightSetContextWithNavigation;\n\nexport interface InsightSetContextWithoutNavigation {\n bounds: Types.Timing.TraceWindowMicro;\n frameId: string;\n navigation?: never;\n}\n\nexport interface InsightSetContextWithNavigation {\n bounds: Types.Timing.TraceWindowMicro;\n frameId: string;\n navigation: Types.Events.NavigationStart;\n navigationId: string;\n lantern?: LanternContext;\n}\n\nexport interface LanternContext {\n requests: Array<Lantern.Types.NetworkRequest<Types.Events.SyntheticNetworkRequest>>;\n graph: Lantern.Graph.Node<Types.Events.SyntheticNetworkRequest>;\n simulator: Lantern.Simulation.Simulator<Types.Events.SyntheticNetworkRequest>;\n metrics: Record<string, Lantern.Metrics.MetricResult>;\n}\n\nexport type InsightModelsType = typeof Models;\n\nexport enum InsightWarning {\n NO_FP = 'NO_FP',\n NO_LCP = 'NO_LCP',\n // No network request could be identified as the primary HTML document.\n NO_DOCUMENT_REQUEST = 'NO_DOCUMENT_REQUEST',\n NO_LAYOUT = 'NO_LAYOUT',\n}\n\nexport interface MetricSavings {\n /* eslint-disable @typescript-eslint/naming-convention */\n FCP?: Types.Timing.Milli;\n LCP?: Types.Timing.Milli;\n TBT?: Types.Timing.Milli;\n CLS?: number;\n INP?: Types.Timing.Milli;\n /* eslint-enable @typescript-eslint/naming-convention */\n}\n\nexport enum InsightCategory {\n ALL = 'All',\n INP = 'INP',\n LCP = 'LCP',\n CLS = 'CLS',\n}\n\nexport type RelatedEventsMap = Map<Types.Events.Event, string[]>;\n\nexport type Checklist<Keys extends string> = Record<Keys, {label: Common.UIString.LocalizedString, value: boolean}>;\n\nexport type InsightModel<UIStrings extends Record<string, string> = Record<string, string>,\n ExtraDetail extends Record<string, unknown> = Record<string, unknown>> =\n ExtraDetail&{\n /** Used internally to identify the type of a model, not shown visibly to users **/\n insightKey: keyof InsightModelsType,\n /** Not used within DevTools - this is for external consumers (like Lighthouse). */\n strings: UIStrings,\n title: Common.UIString.LocalizedString,\n description: Common.UIString.LocalizedString,\n category: InsightCategory,\n state: 'pass' | 'fail' | 'informative',\n /** Used by RelatedInsightChips.ts */\n relatedEvents?: RelatedEventsMap | Types.Events.Event[],\n warnings?: InsightWarning[],\n metricSavings?: MetricSavings,\n /**\n * An estimate for the number of bytes that this insight deems to have been wasted.\n * Bytes are in terms of transfer size: for each component of savings related to an\n * individual request, the insight will estimate its impact on transfer size by using\n * the compression ratio of the resource.\n *\n * This field is only displayed for informational purposes.\n */\n wastedBytes?: number,\n frameId?: string,\n /**\n * If this insight is attached to a navigation, this stores its ID.\n */\n navigationId?: string,\n };\n\nexport type PartialInsightModel<T> =\n Omit<T, 'strings'|'title'|'description'|'category'|'state'|'insightKey'|'navigationId'|'frameId'>;\n\n/**\n * Contains insights for a specific navigation. If a trace began after a navigation already started,\n * this could instead represent the duration from the beginning of the trace up to the first recorded\n * navigation (or the end of the trace).\n */\nexport interface InsightSet {\n /** If for a navigation, this is the navigationId. Else it is Trace.Types.Events.NO_NAVIGATION. */\n id: Types.Events.NavigationId;\n /** The URL to show in the accordion list. */\n url: URL;\n frameId: string;\n bounds: Types.Timing.TraceWindowMicro;\n model: InsightModels;\n navigation?: Types.Events.NavigationStart;\n}\n\n/**\n * Contains insights for a specific insight set.\n */\nexport type InsightModels = {\n [I in keyof InsightModelsType]: ReturnType<InsightModelsType[I]['generateInsight']>;\n};\n\n/**\n * Contains insights for the entire trace. Insights are mostly grouped by `navigationId`, with one exception:\n *\n * If the analyzed trace started after the navigation, and has meaningful work with that span, there is no\n * navigation to map it to. In this case `Types.Events.NO_NAVIGATION` is used for the key.\n */\nexport type TraceInsightSets = Map<Types.Events.NavigationId, InsightSet>;\n\nexport enum InsightKeys {\n LCP_BREAKDOWN = 'LCPBreakdown',\n INP_BREAKDOWN = 'INPBreakdown',\n CLS_CULPRITS = 'CLSCulprits',\n THIRD_PARTIES = 'ThirdParties',\n DOCUMENT_LATENCY = 'DocumentLatency',\n DOM_SIZE = 'DOMSize',\n DUPLICATE_JAVASCRIPT = 'DuplicatedJavaScript',\n FONT_DISPLAY = 'FontDisplay',\n FORCED_REFLOW = 'ForcedReflow',\n IMAGE_DELIVERY = 'ImageDelivery',\n LCP_DISCOVERY = 'LCPDiscovery',\n LEGACY_JAVASCRIPT = 'LegacyJavaScript',\n NETWORK_DEPENDENCY_TREE = 'NetworkDependencyTree',\n RENDER_BLOCKING = 'RenderBlocking',\n SLOW_CSS_SELECTOR = 'SlowCSSSelector',\n VIEWPORT = 'Viewport',\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from './LanternError.js';
2
+ export * from './NetworkAnalyzer.js';
@@ -0,0 +1,6 @@
1
+ // Copyright 2024 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
+ export * from './LanternError.js';
5
+ export * from './NetworkAnalyzer.js';
6
+ //# sourceMappingURL=core.prebundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.prebundle.js","sourceRoot":"","sources":["core.prebundle.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,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\nexport * from './LanternError.js';\nexport * from './NetworkAnalyzer.js';\n"]}
@@ -0,0 +1,6 @@
1
+ // Copyright 2024 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
+
5
+ export * from './LanternError.js';
6
+ export * from './NetworkAnalyzer.js';
@@ -0,0 +1,43 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
+ "outDir": ".",
23
+ "rootDir": ".",
24
+ "skipLibCheck": true,
25
+ "sourceMap": true,
26
+ "strict": true,
27
+ "target": "esnext",
28
+ "tsBuildInfoFile": "devtools_entrypoint-bundle-tsconfig-tsconfig.json.tsbuildinfo",
29
+ "typeRoots": [],
30
+ "useUnknownInCatchVariables": false
31
+ },
32
+ "files": [
33
+ "core.prebundle.ts",
34
+ "../../../../../../../../front_end/legacy/legacy-defs.d.ts",
35
+ "../../../../../../../../front_end/global_typings/global_defs.d.ts",
36
+ "../../../../../../../../node_modules/@types/filesystem/index.d.ts"
37
+ ],
38
+ "references": [
39
+ {
40
+ "path": "./core-tsconfig.json"
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "composite": true,
6
+ "declaration": true,
7
+ "experimentalDecorators": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "inlineSources": true,
10
+ "lib": [
11
+ "esnext",
12
+ "dom",
13
+ "dom.iterable"
14
+ ],
15
+ "module": "esnext",
16
+ "noEmitOnError": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+ "noImplicitOverride": true,
19
+ "noImplicitReturns": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
+ "outDir": ".",
23
+ "rootDir": ".",
24
+ "skipLibCheck": true,
25
+ "sourceMap": true,
26
+ "strict": true,
27
+ "target": "esnext",
28
+ "tsBuildInfoFile": "devtools_entrypoint-bundle-tsconfig-tsconfig.json.tsbuildinfo",
29
+ "typeRoots": [],
30
+ "useUnknownInCatchVariables": false
31
+ },
32
+ "files": [
33
+ "lantern.prebundle.ts",
34
+ "../../../../../../../front_end/legacy/legacy-defs.d.ts",
35
+ "../../../../../../../front_end/global_typings/global_defs.d.ts",
36
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts"
37
+ ],
38
+ "references": [
39
+ {
40
+ "path": "./lantern-tsconfig.json"
41
+ }
42
+ ]
43
+ }
@@ -87,9 +87,12 @@ declare class BaseNode<T = Lantern.AnyNetworkObject> {
87
87
  traversalPath: Node[];
88
88
  }, void, unknown>;
89
89
  /**
90
- * Returns whether the given node has a cycle in its dependent graph by performing a DFS.
90
+ * If the given node has a cycle, returns a path representing that cycle.
91
+ * Else returns null.
92
+ *
93
+ * Does a DFS on in its dependent graph.
91
94
  */
92
- static hasCycle(node: Node, direction?: 'dependents' | 'dependencies' | 'both'): boolean;
95
+ static findCycle(node: Node, direction?: 'dependents' | 'dependencies' | 'both'): BaseNode[] | null;
93
96
  canDependOn(node: Node): boolean;
94
97
  }
95
98
  export { BaseNode };
@@ -222,12 +222,15 @@ class BaseNode {
222
222
  }
223
223
  }
224
224
  /**
225
- * Returns whether the given node has a cycle in its dependent graph by performing a DFS.
225
+ * If the given node has a cycle, returns a path representing that cycle.
226
+ * Else returns null.
227
+ *
228
+ * Does a DFS on in its dependent graph.
226
229
  */
227
- static hasCycle(node, direction = 'both') {
230
+ static findCycle(node, direction = 'both') {
228
231
  // Checking 'both' is the default entrypoint to recursively check both directions
229
232
  if (direction === 'both') {
230
- return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');
233
+ return BaseNode.findCycle(node, 'dependents') || BaseNode.findCycle(node, 'dependencies');
231
234
  }
232
235
  const visited = new Set();
233
236
  const currentPath = [];
@@ -240,7 +243,7 @@ class BaseNode {
240
243
  const currentNode = toVisit.pop();
241
244
  // We've hit a cycle if the node we're visiting is in our current dependency path
242
245
  if (currentPath.includes(currentNode)) {
243
- return true;
246
+ return currentPath;
244
247
  }
245
248
  // If we've already visited the node, no need to revisit it
246
249
  if (visited.has(currentNode)) {
@@ -264,7 +267,7 @@ class BaseNode {
264
267
  depthAdded.set(nextNode, currentPath.length);
265
268
  }
266
269
  }
267
- return false;
270
+ return null;
268
271
  }
269
272
  canDependOn(node) {
270
273
  return node.startTime <= this.startTime;
@@ -1 +1 @@
1
- {"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/graph/BaseNode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAYxC;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ;IACZ,MAAM,CAAC,KAAK,GAAG;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,EAAE,KAAK;KACF,CAAC;IAEX,GAAG,CAAS;IACZ,eAAe,CAAU;IACzB,UAAU,CAAS;IACnB,YAAY,CAAS;IAErB,YAAY,EAAU;QACpB,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,IAAI,IAAI;QACN,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,IAAI,SAAS;QACX,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;IAED,iBAAiB,CAAC,KAAc;QAC9B,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,EA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GAAG,CAAC,WAAW,CAAC,CAAC;YACzB,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAE9B,iDAAiD;YACjD,MAAM,cAAc,GAAG,SAAS,KAAK,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,CAAC;YACtG,KAAK,MAAM,QAAQ,IAAI,cAAc,EAAE,CAAC;gBACtC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC/B,SAAS;gBACX,CAAC;gBACD,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAC/C,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;;AAGH,OAAO,EAAC,QAAQ,EAAC,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 Core from '../core/core.js';\nimport type * as Lantern from '../types/types.js';\n\nimport type {CPUNode} from './CPUNode.js';\nimport type {NetworkNode} from './NetworkNode.js';\n\n/**\n * A union of all types derived from BaseNode, allowing type check discrimination\n * based on `node.type`. If a new node type is created, it should be added here.\n */\nexport type Node<T = Lantern.AnyNetworkObject> = CPUNode<T>|NetworkNode<T>;\n\n/**\n * @fileoverview This class encapsulates logic for handling resources and tasks used to model the\n * execution dependency graph of the page. A node has a unique identifier and can depend on other\n * nodes/be depended on. The construction of the graph maintains some important invariants that are\n * inherent to the model:\n *\n * 1. The graph is a DAG, there are no cycles.\n * 2. There is always a root node upon which all other nodes eventually depend.\n *\n * This allows particular optimizations in this class so that we do no need to check for cycles as\n * these methods are called and we can always start traversal at the root node.\n */\n\nclass BaseNode<T = Lantern.AnyNetworkObject> {\n static types = {\n NETWORK: 'network',\n CPU: 'cpu',\n } as const;\n\n _id: string;\n _isMainDocument: boolean;\n dependents: Node[];\n dependencies: Node[];\n\n constructor(id: string) {\n this._id = id;\n this._isMainDocument = false;\n this.dependents = [];\n this.dependencies = [];\n }\n\n get id(): string {\n return this._id;\n }\n\n get type(): 'network'|'cpu' {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get startTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get endTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n setIsMainDocument(value: boolean): void {\n this._isMainDocument = value;\n }\n\n isMainDocument(): boolean {\n return this._isMainDocument;\n }\n\n getDependents(): Node[] {\n return this.dependents.slice();\n }\n\n getNumberOfDependents(): number {\n return this.dependents.length;\n }\n\n getDependencies(): Node[] {\n return this.dependencies.slice();\n }\n\n getNumberOfDependencies(): number {\n return this.dependencies.length;\n }\n\n getRootNode(): Node<T> {\n let rootNode = this as BaseNode as Node;\n while (rootNode.dependencies.length) {\n rootNode = rootNode.dependencies[0];\n }\n\n return rootNode;\n }\n\n addDependent(node: Node): void {\n node.addDependency(this as BaseNode as Node);\n }\n\n addDependency(node: Node): void {\n // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.\n if (node === this) {\n throw new Core.LanternError('Cannot add dependency on itself');\n }\n\n if (this.dependencies.includes(node)) {\n return;\n }\n\n node.dependents.push(this as BaseNode as Node);\n this.dependencies.push(node);\n }\n\n removeDependent(node: Node): void {\n node.removeDependency(this as BaseNode as Node);\n }\n\n removeDependency(node: Node): void {\n if (!this.dependencies.includes(node)) {\n return;\n }\n\n const thisIndex = node.dependents.indexOf(this as BaseNode as Node);\n node.dependents.splice(thisIndex, 1);\n this.dependencies.splice(this.dependencies.indexOf(node), 1);\n }\n\n // Unused in devtools, but used in LH.\n removeAllDependencies(): void {\n for (const node of this.dependencies.slice()) {\n this.removeDependency(node);\n }\n }\n\n /**\n * Computes whether the given node is anywhere in the dependency graph of this node.\n * While this method can prevent cycles, it walks the graph and should be used sparingly.\n * Nodes are always considered dependent on themselves for the purposes of cycle detection.\n */\n isDependentOn(node: BaseNode<T>): boolean {\n let isDependentOnNode = false;\n this.traverse(\n currentNode => {\n if (isDependentOnNode) {\n return;\n }\n isDependentOnNode = currentNode === node;\n },\n currentNode => {\n // If we've already found the dependency, don't traverse further.\n if (isDependentOnNode) {\n return [];\n }\n // Otherwise, traverse the dependencies.\n return currentNode.getDependencies();\n });\n\n return isDependentOnNode;\n }\n\n /**\n * Clones the node's information without adding any dependencies/dependents.\n */\n cloneWithoutRelationships(): Node<T> {\n const node = new BaseNode(this.id) as Node<T>;\n node.setIsMainDocument(this._isMainDocument);\n return node;\n }\n\n /**\n * Clones the entire graph connected to this node filtered by the optional predicate. If a node is\n * included by the predicate, all nodes along the paths between the node and the root will be included. If the\n * node this was called on is not included in the resulting filtered graph, the method will throw.\n *\n * This does not clone NetworkNode's `record` or `rawRecord` fields. It may be reasonable to clone the former,\n * to assist in graph construction, but the latter should never be cloned as one constraint of Lantern is that\n * the underlying data records are accessible for plain object reference equality checks.\n */\n cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node {\n const rootNode = this.getRootNode();\n\n const idsToIncludedClones = new Map<string, Node>();\n\n // Walk down dependents.\n rootNode.traverse(node => {\n if (idsToIncludedClones.has(node.id)) {\n return;\n }\n\n if (predicate === undefined) {\n // No condition for entry, so clone every node.\n idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());\n return;\n }\n\n if (predicate(node)) {\n // Node included, so walk back up dependencies, cloning nodes from here back to the root.\n node.traverse(\n node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),\n // Dependencies already cloned have already cloned ancestors, so no need to visit again.\n node => node.dependencies.filter(parent => !idsToIncludedClones.has(parent.id)),\n );\n }\n });\n\n // Copy dependencies between nodes.\n rootNode.traverse(originalNode => {\n const clonedNode = idsToIncludedClones.get(originalNode.id);\n if (!clonedNode) {\n return;\n }\n\n for (const dependency of originalNode.dependencies) {\n const clonedDependency = idsToIncludedClones.get(dependency.id);\n if (!clonedDependency) {\n throw new Core.LanternError('Dependency somehow not cloned');\n }\n clonedNode.addDependency(clonedDependency);\n }\n });\n\n const clonedThisNode = idsToIncludedClones.get(this.id);\n if (!clonedThisNode) {\n throw new Core.LanternError('Cloned graph missing node');\n }\n return clonedThisNode;\n }\n\n /**\n * Traverses all connected nodes in BFS order, calling `callback` exactly once\n * on each. `traversalPath` is the shortest (though not necessarily unique)\n * path from `node` to the root of the iteration.\n *\n * The `getNextNodes` function takes a visited node and returns which nodes to\n * visit next. It defaults to returning the node's dependents.\n */\n traverse(\n callback: (node: Node<T>, traversalPath: Array<Node<T>>) => void,\n getNextNodes?: (arg0: Node<T>) => Array<Node<T>>): void {\n for (const {node, traversalPath} of this.traverseGenerator(getNextNodes)) {\n callback(node, traversalPath);\n }\n }\n\n /**\n * @see BaseNode.traverse\n */\n // clang-format off\n *traverseGenerator(getNextNodes?: (arg0: Node) => Node[]):\n Generator<{node: Node, traversalPath: Node[]}, void, unknown> {\n // clang-format on\n if (!getNextNodes) {\n getNextNodes = node => node.getDependents();\n }\n\n // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one\n const queue: Node[][] = [[this]];\n const visited = new Set([this.id]);\n\n while (queue.length) {\n // @ts-expect-error - queue has length so it's guaranteed to have an item\n const traversalPath: Node[] = queue.shift();\n const node = traversalPath[0];\n yield {node, traversalPath};\n\n for (const nextNode of getNextNodes(node)) {\n if (visited.has(nextNode.id)) {\n continue;\n }\n visited.add(nextNode.id);\n\n queue.push([nextNode, ...traversalPath]);\n }\n }\n }\n\n /**\n * Returns whether the given node has a cycle in its dependent graph by performing a DFS.\n */\n static hasCycle(node: Node, direction: 'dependents'|'dependencies'|'both' = 'both'): boolean {\n // Checking 'both' is the default entrypoint to recursively check both directions\n if (direction === 'both') {\n return BaseNode.hasCycle(node, 'dependents') || BaseNode.hasCycle(node, 'dependencies');\n }\n\n const visited = new Set();\n const currentPath: BaseNode[] = [];\n const toVisit = [node];\n const depthAdded = new Map([[node, 0]]);\n\n // Keep going while we have nodes to visit in the stack\n while (toVisit.length) {\n // Get the last node in the stack (DFS uses stack, not queue)\n // @ts-expect-error - toVisit has length so it's guaranteed to have an item\n const currentNode: BaseNode = toVisit.pop();\n\n // We've hit a cycle if the node we're visiting is in our current dependency path\n if (currentPath.includes(currentNode)) {\n return true;\n }\n // If we've already visited the node, no need to revisit it\n if (visited.has(currentNode)) {\n continue;\n }\n\n // Since we're visiting this node, clear out any nodes in our path that we had to backtrack\n // @ts-expect-error\n while (currentPath.length > depthAdded.get(currentNode)) {\n currentPath.pop();\n }\n\n // Update our data structures to reflect that we're adding this node to our path\n visited.add(currentNode);\n currentPath.push(currentNode);\n\n // Add all of its dependents to our toVisit stack\n const nodesToExplore = direction === 'dependents' ? currentNode.dependents : currentNode.dependencies;\n for (const nextNode of nodesToExplore) {\n if (toVisit.includes(nextNode)) {\n continue;\n }\n toVisit.push(nextNode);\n depthAdded.set(nextNode, currentPath.length);\n }\n }\n\n return false;\n }\n\n canDependOn(node: Node): boolean {\n return node.startTime <= this.startTime;\n }\n}\n\nexport {BaseNode};\n"]}
1
+ {"version":3,"file":"BaseNode.js","sourceRoot":"","sources":["../../../../../../../../front_end/models/trace/lantern/graph/BaseNode.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAC;AAYxC;;;;;;;;;;;GAWG;AAEH,MAAM,QAAQ;IACZ,MAAM,CAAC,KAAK,GAAG;QACb,OAAO,EAAE,SAAS;QAClB,GAAG,EAAE,KAAK;KACF,CAAC;IAEX,GAAG,CAAS;IACZ,eAAe,CAAU;IACzB,UAAU,CAAS;IACnB,YAAY,CAAS;IAErB,YAAY,EAAU;QACpB,IA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OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,IAAU;QACpB,OAAO,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;IAC1C,CAAC;;AAGH,OAAO,EAAC,QAAQ,EAAC,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 Core from '../core/core.js';\nimport type * as Lantern from '../types/types.js';\n\nimport type {CPUNode} from './CPUNode.js';\nimport type {NetworkNode} from './NetworkNode.js';\n\n/**\n * A union of all types derived from BaseNode, allowing type check discrimination\n * based on `node.type`. If a new node type is created, it should be added here.\n */\nexport type Node<T = Lantern.AnyNetworkObject> = CPUNode<T>|NetworkNode<T>;\n\n/**\n * @fileoverview This class encapsulates logic for handling resources and tasks used to model the\n * execution dependency graph of the page. A node has a unique identifier and can depend on other\n * nodes/be depended on. The construction of the graph maintains some important invariants that are\n * inherent to the model:\n *\n * 1. The graph is a DAG, there are no cycles.\n * 2. There is always a root node upon which all other nodes eventually depend.\n *\n * This allows particular optimizations in this class so that we do no need to check for cycles as\n * these methods are called and we can always start traversal at the root node.\n */\n\nclass BaseNode<T = Lantern.AnyNetworkObject> {\n static types = {\n NETWORK: 'network',\n CPU: 'cpu',\n } as const;\n\n _id: string;\n _isMainDocument: boolean;\n dependents: Node[];\n dependencies: Node[];\n\n constructor(id: string) {\n this._id = id;\n this._isMainDocument = false;\n this.dependents = [];\n this.dependencies = [];\n }\n\n get id(): string {\n return this._id;\n }\n\n get type(): 'network'|'cpu' {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get startTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n /**\n * In microseconds\n */\n get endTime(): number {\n throw new Core.LanternError('Unimplemented');\n }\n\n setIsMainDocument(value: boolean): void {\n this._isMainDocument = value;\n }\n\n isMainDocument(): boolean {\n return this._isMainDocument;\n }\n\n getDependents(): Node[] {\n return this.dependents.slice();\n }\n\n getNumberOfDependents(): number {\n return this.dependents.length;\n }\n\n getDependencies(): Node[] {\n return this.dependencies.slice();\n }\n\n getNumberOfDependencies(): number {\n return this.dependencies.length;\n }\n\n getRootNode(): Node<T> {\n let rootNode = this as BaseNode as Node;\n while (rootNode.dependencies.length) {\n rootNode = rootNode.dependencies[0];\n }\n\n return rootNode;\n }\n\n addDependent(node: Node): void {\n node.addDependency(this as BaseNode as Node);\n }\n\n addDependency(node: Node): void {\n // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.\n if (node === this) {\n throw new Core.LanternError('Cannot add dependency on itself');\n }\n\n if (this.dependencies.includes(node)) {\n return;\n }\n\n node.dependents.push(this as BaseNode as Node);\n this.dependencies.push(node);\n }\n\n removeDependent(node: Node): void {\n node.removeDependency(this as BaseNode as Node);\n }\n\n removeDependency(node: Node): void {\n if (!this.dependencies.includes(node)) {\n return;\n }\n\n const thisIndex = node.dependents.indexOf(this as BaseNode as Node);\n node.dependents.splice(thisIndex, 1);\n this.dependencies.splice(this.dependencies.indexOf(node), 1);\n }\n\n // Unused in devtools, but used in LH.\n removeAllDependencies(): void {\n for (const node of this.dependencies.slice()) {\n this.removeDependency(node);\n }\n }\n\n /**\n * Computes whether the given node is anywhere in the dependency graph of this node.\n * While this method can prevent cycles, it walks the graph and should be used sparingly.\n * Nodes are always considered dependent on themselves for the purposes of cycle detection.\n */\n isDependentOn(node: BaseNode<T>): boolean {\n let isDependentOnNode = false;\n this.traverse(\n currentNode => {\n if (isDependentOnNode) {\n return;\n }\n isDependentOnNode = currentNode === node;\n },\n currentNode => {\n // If we've already found the dependency, don't traverse further.\n if (isDependentOnNode) {\n return [];\n }\n // Otherwise, traverse the dependencies.\n return currentNode.getDependencies();\n });\n\n return isDependentOnNode;\n }\n\n /**\n * Clones the node's information without adding any dependencies/dependents.\n */\n cloneWithoutRelationships(): Node<T> {\n const node = new BaseNode(this.id) as Node<T>;\n node.setIsMainDocument(this._isMainDocument);\n return node;\n }\n\n /**\n * Clones the entire graph connected to this node filtered by the optional predicate. If a node is\n * included by the predicate, all nodes along the paths between the node and the root will be included. If the\n * node this was called on is not included in the resulting filtered graph, the method will throw.\n *\n * This does not clone NetworkNode's `record` or `rawRecord` fields. It may be reasonable to clone the former,\n * to assist in graph construction, but the latter should never be cloned as one constraint of Lantern is that\n * the underlying data records are accessible for plain object reference equality checks.\n */\n cloneWithRelationships(predicate?: (arg0: Node) => boolean): Node {\n const rootNode = this.getRootNode();\n\n const idsToIncludedClones = new Map<string, Node>();\n\n // Walk down dependents.\n rootNode.traverse(node => {\n if (idsToIncludedClones.has(node.id)) {\n return;\n }\n\n if (predicate === undefined) {\n // No condition for entry, so clone every node.\n idsToIncludedClones.set(node.id, node.cloneWithoutRelationships());\n return;\n }\n\n if (predicate(node)) {\n // Node included, so walk back up dependencies, cloning nodes from here back to the root.\n node.traverse(\n node => idsToIncludedClones.set(node.id, node.cloneWithoutRelationships()),\n // Dependencies already cloned have already cloned ancestors, so no need to visit again.\n node => node.dependencies.filter(parent => !idsToIncludedClones.has(parent.id)),\n );\n }\n });\n\n // Copy dependencies between nodes.\n rootNode.traverse(originalNode => {\n const clonedNode = idsToIncludedClones.get(originalNode.id);\n if (!clonedNode) {\n return;\n }\n\n for (const dependency of originalNode.dependencies) {\n const clonedDependency = idsToIncludedClones.get(dependency.id);\n if (!clonedDependency) {\n throw new Core.LanternError('Dependency somehow not cloned');\n }\n clonedNode.addDependency(clonedDependency);\n }\n });\n\n const clonedThisNode = idsToIncludedClones.get(this.id);\n if (!clonedThisNode) {\n throw new Core.LanternError('Cloned graph missing node');\n }\n return clonedThisNode;\n }\n\n /**\n * Traverses all connected nodes in BFS order, calling `callback` exactly once\n * on each. `traversalPath` is the shortest (though not necessarily unique)\n * path from `node` to the root of the iteration.\n *\n * The `getNextNodes` function takes a visited node and returns which nodes to\n * visit next. It defaults to returning the node's dependents.\n */\n traverse(\n callback: (node: Node<T>, traversalPath: Array<Node<T>>) => void,\n getNextNodes?: (arg0: Node<T>) => Array<Node<T>>): void {\n for (const {node, traversalPath} of this.traverseGenerator(getNextNodes)) {\n callback(node, traversalPath);\n }\n }\n\n /**\n * @see BaseNode.traverse\n */\n // clang-format off\n *traverseGenerator(getNextNodes?: (arg0: Node) => Node[]):\n Generator<{node: Node, traversalPath: Node[]}, void, unknown> {\n // clang-format on\n if (!getNextNodes) {\n getNextNodes = node => node.getDependents();\n }\n\n // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one\n const queue: Node[][] = [[this]];\n const visited = new Set([this.id]);\n\n while (queue.length) {\n // @ts-expect-error - queue has length so it's guaranteed to have an item\n const traversalPath: Node[] = queue.shift();\n const node = traversalPath[0];\n yield {node, traversalPath};\n\n for (const nextNode of getNextNodes(node)) {\n if (visited.has(nextNode.id)) {\n continue;\n }\n visited.add(nextNode.id);\n\n queue.push([nextNode, ...traversalPath]);\n }\n }\n }\n\n /**\n * If the given node has a cycle, returns a path representing that cycle.\n * Else returns null.\n *\n * Does a DFS on in its dependent graph.\n */\n static findCycle(node: Node, direction: 'dependents'|'dependencies'|'both' = 'both'): BaseNode[]|null {\n // Checking 'both' is the default entrypoint to recursively check both directions\n if (direction === 'both') {\n return BaseNode.findCycle(node, 'dependents') || BaseNode.findCycle(node, 'dependencies');\n }\n\n const visited = new Set();\n const currentPath: BaseNode[] = [];\n const toVisit = [node];\n const depthAdded = new Map([[node, 0]]);\n\n // Keep going while we have nodes to visit in the stack\n while (toVisit.length) {\n // Get the last node in the stack (DFS uses stack, not queue)\n // @ts-expect-error - toVisit has length so it's guaranteed to have an item\n const currentNode: BaseNode = toVisit.pop();\n\n // We've hit a cycle if the node we're visiting is in our current dependency path\n if (currentPath.includes(currentNode)) {\n return currentPath;\n }\n // If we've already visited the node, no need to revisit it\n if (visited.has(currentNode)) {\n continue;\n }\n\n // Since we're visiting this node, clear out any nodes in our path that we had to backtrack\n // @ts-expect-error\n while (currentPath.length > depthAdded.get(currentNode)) {\n currentPath.pop();\n }\n\n // Update our data structures to reflect that we're adding this node to our path\n visited.add(currentNode);\n currentPath.push(currentNode);\n\n // Add all of its dependents to our toVisit stack\n const nodesToExplore = direction === 'dependents' ? currentNode.dependents : currentNode.dependencies;\n for (const nextNode of nodesToExplore) {\n if (toVisit.includes(nextNode)) {\n continue;\n }\n toVisit.push(nextNode);\n depthAdded.set(nextNode, currentPath.length);\n }\n }\n\n return null;\n }\n\n canDependOn(node: Node): boolean {\n return node.startTime <= this.startTime;\n }\n}\n\nexport {BaseNode};\n"]}
@@ -477,19 +477,34 @@ class PageDependencyGraph {
477
477
  PageDependencyGraph.linkNetworkNodes(rootNode, networkNodeOutput);
478
478
  PageDependencyGraph.linkCPUNodes(rootNode, networkNodeOutput, cpuNodes);
479
479
  mainDocumentNode.setIsMainDocument(true);
480
- if (NetworkNode.hasCycle(rootNode)) {
480
+ if (NetworkNode.findCycle(rootNode)) {
481
+ // Uncomment the following if you are debugging cycles.
482
+ // this.printGraph(rootNode);
481
483
  throw new Core.LanternError('Invalid dependency graph created, cycle detected');
482
484
  }
483
485
  return rootNode;
484
486
  }
485
487
  // Unused, but useful for debugging.
486
- static printGraph(rootNode, widthInCharacters = 100) {
488
+ static printGraph(rootNode, widthInCharacters = 80) {
487
489
  function padRight(str, target, padChar = ' ') {
488
490
  return str + padChar.repeat(Math.max(target - str.length, 0));
489
491
  }
490
492
  const nodes = [];
491
493
  rootNode.traverse(node => nodes.push(node));
492
494
  nodes.sort((a, b) => a.startTime - b.startTime);
495
+ // Assign labels (A, B, C, ..., Z, Z1, Z2, ...) for each node.
496
+ const nodeToLabel = new Map();
497
+ rootNode.traverse(node => {
498
+ const ascii = 65 + nodeToLabel.size;
499
+ let label;
500
+ if (ascii > 90) {
501
+ label = `Z${ascii - 90}`;
502
+ }
503
+ else {
504
+ label = String.fromCharCode(ascii);
505
+ }
506
+ nodeToLabel.set(node, label);
507
+ });
493
508
  const min = nodes[0].startTime;
494
509
  const max = nodes.reduce((max, node) => Math.max(max, node.endTime), 0);
495
510
  const totalTime = max - min;
@@ -501,8 +516,36 @@ class PageDependencyGraph {
501
516
  // @ts-expect-error -- disambiguate displayName from across possible Node types.
502
517
  const displayName = node.request ? node.request.url : node.type;
503
518
  // eslint-disable-next-line
504
- console.log(padRight(bar, widthInCharacters), `| ${displayName.slice(0, 30)}`);
519
+ console.log(padRight(bar, widthInCharacters), `| ${displayName.slice(0, 50)}`);
520
+ });
521
+ // Print labels for each node.
522
+ // eslint-disable-next-line
523
+ console.log();
524
+ // Print dependencies.
525
+ nodes.forEach(node => {
526
+ // @ts-expect-error -- disambiguate displayName from across possible Node types.
527
+ const displayName = node.request ? node.request.url : node.type;
528
+ // eslint-disable-next-line
529
+ console.log(nodeToLabel.get(node), displayName.slice(0, widthInCharacters - 5));
530
+ for (const child of node.dependents) {
531
+ // @ts-expect-error -- disambiguate displayName from across possible Node types.
532
+ const displayName = child.request ? child.request.url : child.type;
533
+ // eslint-disable-next-line
534
+ console.log(' ->', nodeToLabel.get(child), displayName.slice(0, widthInCharacters - 10));
535
+ }
536
+ // eslint-disable-next-line
537
+ console.log();
505
538
  });
539
+ // Show cycle.
540
+ const cyclePath = NetworkNode.findCycle(rootNode);
541
+ // eslint-disable-next-line
542
+ console.log('Cycle?', cyclePath ? 'yes' : 'no');
543
+ if (cyclePath) {
544
+ const path = [...cyclePath];
545
+ path.push(path[0]);
546
+ // eslint-disable-next-line
547
+ console.log(path.map(node => nodeToLabel.get(node)).join(' -> '));
548
+ }
506
549
  }
507
550
  }
508
551
  export { PageDependencyGraph };