@paulirish/trace_engine 0.0.9 → 0.0.11

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 (292) hide show
  1. package/analyze-trace.mjs +1 -1
  2. package/core/platform/DevToolsPath.d.ts +23 -0
  3. package/core/platform/DevToolsPath.js +7 -0
  4. package/core/platform/DevToolsPath.js.map +1 -0
  5. package/core/platform/MimeType.d.ts +27 -0
  6. package/core/platform/MimeType.js +137 -0
  7. package/core/platform/MimeType.js.map +1 -0
  8. package/core/platform/Timing.d.ts +7 -0
  9. package/core/platform/Timing.js +13 -0
  10. package/core/platform/Timing.js.map +1 -0
  11. package/core/platform/UIString.d.ts +3 -0
  12. package/core/platform/UIString.js +5 -0
  13. package/core/platform/UIString.js.map +1 -0
  14. package/core/platform/UserVisibleError.d.ts +12 -0
  15. package/core/platform/UserVisibleError.js +23 -0
  16. package/core/platform/UserVisibleError.js.map +1 -0
  17. package/core/platform/array-utilities.d.ts +66 -0
  18. package/core/platform/array-utilities.js +199 -0
  19. package/core/platform/array-utilities.js.map +1 -0
  20. package/core/platform/brand.d.ts +14 -0
  21. package/core/platform/brand.js +5 -0
  22. package/core/platform/brand.js.map +1 -0
  23. package/core/platform/bundle-tsconfig.json +1 -0
  24. package/core/platform/date-utilities.d.ts +2 -0
  25. package/core/platform/date-utilities.js +14 -0
  26. package/core/platform/date-utilities.js.map +1 -0
  27. package/core/platform/dcheck-tsconfig.json +8 -0
  28. package/core/platform/dcheck.d.ts +4 -0
  29. package/core/platform/dcheck.js +5 -0
  30. package/core/platform/devtools_entrypoint-bundle-tsconfig-tsconfig.json +40 -0
  31. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  32. package/core/platform/dom-utilities.d.ts +8 -0
  33. package/core/platform/dom-utilities.js +109 -0
  34. package/core/platform/dom-utilities.js.map +1 -0
  35. package/core/platform/keyboard-utilities.d.ts +17 -0
  36. package/core/platform/keyboard-utilities.js +22 -0
  37. package/core/platform/keyboard-utilities.js.map +1 -0
  38. package/core/platform/map-utilities.d.ts +18 -0
  39. package/core/platform/map-utilities.js +76 -0
  40. package/core/platform/map-utilities.js.map +1 -0
  41. package/core/platform/number-utilities.d.ts +15 -0
  42. package/core/platform/number-utilities.js +82 -0
  43. package/core/platform/number-utilities.js.map +1 -0
  44. package/core/platform/platform-tsconfig.json +59 -0
  45. package/core/platform/platform.d.ts +19 -0
  46. package/core/platform/platform.js +54 -0
  47. package/core/platform/platform.js.compressed +0 -0
  48. package/core/platform/platform.js.hash +1 -0
  49. package/core/platform/platform.js.map +1 -0
  50. package/core/platform/platform.prebundle.d.ts +15 -0
  51. package/core/platform/platform.prebundle.js +50 -0
  52. package/core/platform/platform.prebundle.js.map +1 -0
  53. package/core/platform/platform.prebundle.ts +64 -0
  54. package/core/platform/promise-utilities.d.ts +10 -0
  55. package/core/platform/promise-utilities.js +18 -0
  56. package/core/platform/promise-utilities.js.map +1 -0
  57. package/core/platform/set-utilities.d.ts +2 -0
  58. package/core/platform/set-utilities.js +23 -0
  59. package/core/platform/set-utilities.js.map +1 -0
  60. package/core/platform/string-utilities.d.ts +71 -0
  61. package/core/platform/string-utilities.js +513 -0
  62. package/core/platform/string-utilities.js.map +1 -0
  63. package/core/platform/typescript-utilities.d.ts +56 -0
  64. package/core/platform/typescript-utilities.js +25 -0
  65. package/core/platform/typescript-utilities.js.map +1 -0
  66. package/generated/protocol.d.ts +17923 -0
  67. package/generated/protocol.js +5 -0
  68. package/models/cpu_profile/CPUProfileDataModel.d.ts +77 -0
  69. package/models/cpu_profile/CPUProfileDataModel.js +508 -0
  70. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -0
  71. package/models/cpu_profile/ProfileTreeModel.d.ts +29 -0
  72. package/models/cpu_profile/ProfileTreeModel.js +95 -0
  73. package/models/cpu_profile/ProfileTreeModel.js.map +1 -0
  74. package/models/cpu_profile/bundle-tsconfig.json +1 -0
  75. package/models/cpu_profile/cpu_profile-tsconfig.json +51 -0
  76. package/models/cpu_profile/cpu_profile.d.ts +3 -0
  77. package/models/cpu_profile/cpu_profile.js +7 -0
  78. package/models/cpu_profile/cpu_profile.js.map +1 -0
  79. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  80. package/models/trace/EntriesFilter.d.ts +55 -0
  81. package/models/trace/EntriesFilter.js +243 -0
  82. package/models/trace/EntriesFilter.js.map +1 -0
  83. package/models/trace/LegacyTracingModel.d.ts +1 -0
  84. package/models/trace/LegacyTracingModel.js +1 -0
  85. package/models/trace/LegacyTracingModel.js.map +1 -0
  86. package/models/trace/ModelImpl.d.ts +110 -0
  87. package/models/trace/ModelImpl.js +175 -0
  88. package/models/trace/ModelImpl.js.map +1 -0
  89. package/models/trace/Processor.d.ts +36 -0
  90. package/models/trace/Processor.js +213 -0
  91. package/models/trace/Processor.js.map +1 -0
  92. package/models/trace/SDKServices.js +104 -0
  93. package/models/trace/SDKServices.js.map +7 -0
  94. package/models/trace/TraceProcessor.js +133 -0
  95. package/models/trace/TraceProcessor.js.map +7 -0
  96. package/models/trace/TracingManager.d.ts +1 -0
  97. package/models/trace/TracingManager.js +1 -0
  98. package/models/trace/TracingManager.js.map +1 -0
  99. package/models/trace/TreeManipulator.js +85 -0
  100. package/models/trace/TreeManipulator.js.map +7 -0
  101. package/models/trace/bundle-tsconfig.json +1 -0
  102. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  103. package/models/trace/devtools_entrypoint-legacy-typescript-tsconfig.json +43 -0
  104. package/models/trace/extras/FetchNodes.d.ts +46 -0
  105. package/models/trace/extras/FetchNodes.js +145 -0
  106. package/models/trace/extras/FetchNodes.js.map +1 -0
  107. package/models/trace/extras/FilmStrip.d.ts +19 -0
  108. package/models/trace/extras/FilmStrip.js +44 -0
  109. package/models/trace/extras/FilmStrip.js.map +1 -0
  110. package/models/trace/extras/MainThreadActivity.d.ts +2 -0
  111. package/models/trace/extras/MainThreadActivity.js +77 -0
  112. package/models/trace/extras/MainThreadActivity.js.map +1 -0
  113. package/models/trace/extras/Metadata.d.ts +2 -0
  114. package/models/trace/extras/Metadata.js +44 -0
  115. package/models/trace/extras/Metadata.js.map +1 -0
  116. package/models/trace/extras/bundle-tsconfig.json +1 -0
  117. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  118. package/models/trace/extras/extras-tsconfig.json +59 -0
  119. package/models/trace/extras/extras.d.ts +1 -0
  120. package/models/trace/extras/extras.js +1 -0
  121. package/models/trace/extras/extras.js.map +1 -0
  122. package/models/trace/frames/TimelineFrameModel.js +392 -0
  123. package/models/trace/frames/TimelineFrameModel.js.map +7 -0
  124. package/models/trace/frames/bundle-tsconfig.json +1 -0
  125. package/models/trace/frames/devtools_entrypoint-bundle-typescript-tsconfig.json +43 -0
  126. package/models/trace/frames/frames-tsconfig.json +58 -0
  127. package/models/trace/frames/frames.js +5 -0
  128. package/models/trace/frames/frames.js.map +7 -0
  129. package/models/trace/handlers/AnimationHandler.d.ts +8 -0
  130. package/models/trace/handlers/AnimationHandler.js +32 -0
  131. package/models/trace/handlers/AnimationHandler.js.map +1 -0
  132. package/models/trace/handlers/AuctionWorkletsHandler.d.ts +8 -0
  133. package/models/trace/handlers/AuctionWorkletsHandler.js +160 -0
  134. package/models/trace/handlers/AuctionWorkletsHandler.js.map +1 -0
  135. package/models/trace/handlers/FramesHandler.d.ts +76 -0
  136. package/models/trace/handlers/FramesHandler.js +457 -0
  137. package/models/trace/handlers/FramesHandler.js.map +1 -0
  138. package/models/trace/handlers/GPUHandler.d.ts +11 -0
  139. package/models/trace/handlers/GPUHandler.js +54 -0
  140. package/models/trace/handlers/GPUHandler.js.map +1 -0
  141. package/models/trace/handlers/InitiatorsHandler.d.ts +10 -0
  142. package/models/trace/handlers/InitiatorsHandler.js +184 -0
  143. package/models/trace/handlers/InitiatorsHandler.js.map +1 -0
  144. package/models/trace/handlers/InvalidationsHandler.d.ts +10 -0
  145. package/models/trace/handlers/InvalidationsHandler.js +120 -0
  146. package/models/trace/handlers/InvalidationsHandler.js.map +1 -0
  147. package/models/trace/handlers/LargestImagePaintHandler.d.ts +5 -0
  148. package/models/trace/handlers/LargestImagePaintHandler.js +38 -0
  149. package/models/trace/handlers/LargestImagePaintHandler.js.map +1 -0
  150. package/models/trace/handlers/LargestTextPaintHandler.d.ts +5 -0
  151. package/models/trace/handlers/LargestTextPaintHandler.js +26 -0
  152. package/models/trace/handlers/LargestTextPaintHandler.js.map +1 -0
  153. package/models/trace/handlers/LayerTreeHandler.d.ts +13 -0
  154. package/models/trace/handlers/LayerTreeHandler.js +116 -0
  155. package/models/trace/handlers/LayerTreeHandler.js.map +1 -0
  156. package/models/trace/handlers/LayoutShiftsHandler.d.ts +44 -0
  157. package/models/trace/handlers/LayoutShiftsHandler.js +347 -0
  158. package/models/trace/handlers/LayoutShiftsHandler.js.map +1 -0
  159. package/models/trace/handlers/MemoryHandler.d.ts +7 -0
  160. package/models/trace/handlers/MemoryHandler.js +20 -0
  161. package/models/trace/handlers/MemoryHandler.js.map +1 -0
  162. package/models/trace/handlers/MetaHandler.d.ts +37 -0
  163. package/models/trace/handlers/MetaHandler.js +338 -0
  164. package/models/trace/handlers/MetaHandler.js.map +1 -0
  165. package/models/trace/handlers/Migration.js +27 -0
  166. package/models/trace/handlers/Migration.js.map +7 -0
  167. package/models/trace/handlers/ModelHandlers.d.ts +21 -0
  168. package/models/trace/handlers/ModelHandlers.js +25 -0
  169. package/models/trace/handlers/ModelHandlers.js.map +1 -0
  170. package/models/trace/handlers/NetworkRequestsHandler.d.ts +17 -0
  171. package/models/trace/handlers/NetworkRequestsHandler.js +361 -0
  172. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -0
  173. package/models/trace/handlers/PageLoadMetricsHandler.d.ts +67 -0
  174. package/models/trace/handlers/PageLoadMetricsHandler.js +407 -0
  175. package/models/trace/handlers/PageLoadMetricsHandler.js.map +1 -0
  176. package/models/trace/handlers/RendererHandler.d.ts +101 -0
  177. package/models/trace/handlers/RendererHandler.js +325 -0
  178. package/models/trace/handlers/RendererHandler.js.map +1 -0
  179. package/models/trace/handlers/SamplesHandler.d.ts +46 -0
  180. package/models/trace/handlers/SamplesHandler.js +215 -0
  181. package/models/trace/handlers/SamplesHandler.js.map +1 -0
  182. package/models/trace/handlers/ScreenshotsHandler.d.ts +7 -0
  183. package/models/trace/handlers/ScreenshotsHandler.js +79 -0
  184. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -0
  185. package/models/trace/handlers/Threads.d.ts +33 -0
  186. package/models/trace/handlers/Threads.js +95 -0
  187. package/models/trace/handlers/Threads.js.map +1 -0
  188. package/models/trace/handlers/UberFramesHandler.js +293 -0
  189. package/models/trace/handlers/UberFramesHandler.js.map +7 -0
  190. package/models/trace/handlers/UserInteractionsHandler.d.ts +57 -0
  191. package/models/trace/handlers/UserInteractionsHandler.js +267 -0
  192. package/models/trace/handlers/UserInteractionsHandler.js.map +1 -0
  193. package/models/trace/handlers/UserTimingsHandler.d.ts +28 -0
  194. package/models/trace/handlers/UserTimingsHandler.js +108 -0
  195. package/models/trace/handlers/UserTimingsHandler.js.map +1 -0
  196. package/models/trace/handlers/WarningsHandler.d.ts +14 -0
  197. package/models/trace/handlers/WarningsHandler.js +125 -0
  198. package/models/trace/handlers/WarningsHandler.js.map +1 -0
  199. package/models/trace/handlers/WorkersHandler.d.ts +11 -0
  200. package/models/trace/handlers/WorkersHandler.js +52 -0
  201. package/models/trace/handlers/WorkersHandler.js.map +1 -0
  202. package/models/trace/handlers/bundle-tsconfig.json +1 -0
  203. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  204. package/models/trace/handlers/handlers-tsconfig.json +79 -0
  205. package/models/trace/handlers/handlers.d.ts +3 -0
  206. package/models/trace/handlers/handlers.js +7 -0
  207. package/models/trace/handlers/handlers.js.map +1 -0
  208. package/models/trace/handlers/types.d.ts +45 -0
  209. package/models/trace/handlers/types.js +18 -0
  210. package/models/trace/handlers/types.js.map +1 -0
  211. package/models/trace/helpers/SamplesIntegrator.d.ts +49 -0
  212. package/models/trace/helpers/SamplesIntegrator.js +397 -0
  213. package/models/trace/helpers/SamplesIntegrator.js.map +1 -0
  214. package/models/trace/helpers/Timing.d.ts +26 -0
  215. package/models/trace/helpers/Timing.js +162 -0
  216. package/models/trace/helpers/Timing.js.map +1 -0
  217. package/models/trace/helpers/Trace.d.ts +37 -0
  218. package/models/trace/helpers/Trace.js +230 -0
  219. package/models/trace/helpers/Trace.js.map +1 -0
  220. package/models/trace/helpers/TreeHelpers.d.ts +90 -0
  221. package/models/trace/helpers/TreeHelpers.js +222 -0
  222. package/models/trace/helpers/TreeHelpers.js.map +1 -0
  223. package/models/trace/helpers/bundle-tsconfig.json +1 -0
  224. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  225. package/models/trace/helpers/helpers-tsconfig.json +59 -0
  226. package/models/trace/helpers/helpers.d.ts +4 -0
  227. package/models/trace/helpers/helpers.js +8 -0
  228. package/models/trace/helpers/helpers.js.map +1 -0
  229. package/models/trace/legacy-tsconfig.json +1 -0
  230. package/models/trace/root-causes/LayoutShift.d.ts +119 -0
  231. package/models/trace/root-causes/LayoutShift.js +517 -0
  232. package/models/trace/root-causes/LayoutShift.js.map +1 -0
  233. package/models/trace/root-causes/RootCauses.d.ts +14 -0
  234. package/models/trace/root-causes/RootCauses.js +11 -0
  235. package/models/trace/root-causes/RootCauses.js.map +1 -0
  236. package/models/trace/root-causes/bundle-tsconfig.json +1 -0
  237. package/models/trace/root-causes/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  238. package/models/trace/root-causes/root-causes-tsconfig.json +57 -0
  239. package/models/trace/root-causes/root-causes.d.ts +1 -0
  240. package/models/trace/root-causes/root-causes.js +5 -0
  241. package/models/trace/root-causes/root-causes.js.map +1 -0
  242. package/models/trace/sdk_services/DOMNodeLookup.js +41 -0
  243. package/models/trace/sdk_services/DOMNodeLookup.js.map +7 -0
  244. package/models/trace/sdk_services/LayoutShifts.js +68 -0
  245. package/models/trace/sdk_services/LayoutShifts.js.map +7 -0
  246. package/models/trace/sdk_services/bundle-tsconfig.json +1 -0
  247. package/models/trace/sdk_services/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
  248. package/models/trace/sdk_services/sdk_services-tsconfig.json +57 -0
  249. package/models/trace/sdk_services/sdk_services.js +7 -0
  250. package/models/trace/sdk_services/sdk_services.js.map +7 -0
  251. package/models/trace/trace-legacy.js +16 -0
  252. package/models/trace/trace-legacy.js.map +7 -0
  253. package/models/trace/trace-tsconfig.json +69 -0
  254. package/models/trace/trace.d.ts +11 -0
  255. package/models/trace/trace.js +17 -0
  256. package/models/trace/trace.js.map +1 -0
  257. package/models/trace/types/Configuration.d.ts +33 -0
  258. package/models/trace/types/Configuration.js +29 -0
  259. package/models/trace/types/Configuration.js.map +1 -0
  260. package/models/trace/types/File.d.ts +23 -0
  261. package/models/trace/types/File.js +5 -0
  262. package/models/trace/types/File.js.map +1 -0
  263. package/models/trace/types/Timing.d.ts +25 -0
  264. package/models/trace/types/Timing.js +16 -0
  265. package/models/trace/types/Timing.js.map +1 -0
  266. package/models/trace/types/TraceEvents.d.ts +1571 -0
  267. package/models/trace/types/TraceEvents.js +388 -0
  268. package/models/trace/types/TraceEvents.js.map +1 -0
  269. package/models/trace/types/bundle-tsconfig.json +1 -0
  270. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +44 -0
  271. package/models/trace/types/types-tsconfig.json +47 -0
  272. package/models/trace/types/types.d.ts +4 -0
  273. package/models/trace/types/types.js +8 -0
  274. package/models/trace/types/types.js.map +1 -0
  275. package/models/trace/worker/Processor.js +143 -0
  276. package/models/trace/worker/Processor.js.map +7 -0
  277. package/models/trace/worker/Types.js +1 -0
  278. package/models/trace/worker/Types.js.map +7 -0
  279. package/models/trace/worker/bundle-tsconfig.json +1 -0
  280. package/models/trace/worker/devtools_entrypoint-bundle-typescript-tsconfig.json +41 -0
  281. package/models/trace/worker/devtools_entrypoint-worker_entrypoint-typescript-tsconfig.json +41 -0
  282. package/models/trace/worker/processor-tsconfig.json +45 -0
  283. package/models/trace/worker/worker.js +7 -0
  284. package/models/trace/worker/worker.js.map +7 -0
  285. package/models/trace/worker/worker_entrypoint-tsconfig.json +1 -0
  286. package/models/trace/worker/worker_entrypoint.js +36 -0
  287. package/models/trace/worker/worker_entrypoint.js.map +7 -0
  288. package/package.json +2 -2
  289. package/TracingManager.js +0 -0
  290. package/extras/extras.js +0 -0
  291. package/trace.mjs +0 -6980
  292. package/trace.mjs.map +0 -8
@@ -0,0 +1,517 @@
1
+ // Copyright 2023 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 Platform from '../../../core/platform/platform.js';
5
+ import * as Helpers from '../helpers/helpers.js';
6
+ import * as Types from '../types/types.js';
7
+ const fontRequestsByPrePaint = new Map();
8
+ const renderBlocksByPrePaint = new Map();
9
+ function setDefaultValue(map, shift) {
10
+ Platform.MapUtilities.getWithDefault(map, shift, () => {
11
+ return {
12
+ unsizedMedia: [],
13
+ iframes: [],
14
+ fontChanges: [],
15
+ renderBlockingRequests: [],
16
+ scriptStackTrace: [],
17
+ };
18
+ });
19
+ }
20
+ // Important: we purposefully treat `potentially_blocking` as
21
+ // non-render-blocking here because:
22
+ // 1. An async script can run on the main thread at any point, including before
23
+ // the page is loaded
24
+ // 2. An async script will never block the parsing and rendering process of the
25
+ // browser.
26
+ // 3. Therefore, from a developer's point of view, there is nothing more they
27
+ // can do if they've put `async` on, and within the context of Insights, we
28
+ // shouldn't report an async script as render blocking.
29
+ // In the future we may want to consider suggesting the use of `defer` over
30
+ // `async`, as it doesn't have this concern, but for now we'll allow `async`
31
+ // and not report it as an issue.
32
+ const NON_RENDER_BLOCKING_VALUES = new Set([
33
+ 'non_blocking',
34
+ 'potentially_blocking',
35
+ ]);
36
+ function networkRequestIsRenderBlockingInFrame(event, frameId) {
37
+ const isRenderBlocking = !NON_RENDER_BLOCKING_VALUES.has(event.args.data.renderBlocking);
38
+ return isRenderBlocking && event.args.data.frame === frameId;
39
+ }
40
+ export class LayoutShiftRootCauses {
41
+ #protocolInterface;
42
+ #rootCauseCacheMap = new Map();
43
+ constructor(protocolInterface) {
44
+ this.#protocolInterface = protocolInterface;
45
+ }
46
+ /**
47
+ * Calculates the potential root causes for a given layout shift event. Once
48
+ * calculated, this data is cached.
49
+ * Note: because you need all layout shift data at once to calculate these
50
+ * correctly, this function will parse the root causes for _all_ layout shift
51
+ * events the first time that it's called. That then populates the cache for
52
+ * each shift, so any subsequent calls are just a constant lookup.
53
+ */
54
+ async rootCausesForEvent(modelData, event) {
55
+ const cachedResult = this.#rootCauseCacheMap.get(event);
56
+ if (cachedResult) {
57
+ return cachedResult;
58
+ }
59
+ const allLayoutShifts = modelData.LayoutShifts.clusters.flatMap(cluster => cluster.events);
60
+ // Make sure a value in the cache is set even for shifts that don't have a root cause,
61
+ // so that we don't have to recompute when no root causes are found. In case a cause
62
+ // for a shift is found, the default value is replaced.
63
+ allLayoutShifts.forEach(shift => setDefaultValue(this.#rootCauseCacheMap, shift));
64
+ // Populate the cache
65
+ await this.blameShifts(allLayoutShifts, modelData);
66
+ const resultForEvent = this.#rootCauseCacheMap.get(event);
67
+ if (!resultForEvent) {
68
+ // No root causes available for this layout shift.
69
+ return null;
70
+ }
71
+ return resultForEvent;
72
+ }
73
+ /**
74
+ * Determines potential root causes for shifts
75
+ */
76
+ async blameShifts(layoutShifts, modelData) {
77
+ await this.linkShiftsToLayoutInvalidations(layoutShifts, modelData);
78
+ this.linkShiftsToLayoutEvents(layoutShifts, modelData);
79
+ }
80
+ /**
81
+ * "LayoutInvalidations" are a set of trace events dispatched in Blink under the name
82
+ * "layoutInvalidationTracking", which track invalidations on the "Layout"stage of the
83
+ * rendering pipeline. This function utilizes this event to flag potential root causes
84
+ * to layout shifts.
85
+ */
86
+ async linkShiftsToLayoutInvalidations(layoutShifts, modelData) {
87
+ const { prePaintEvents, layoutInvalidationEvents, scheduleStyleInvalidationEvents, backendNodeIds } = modelData.LayoutShifts;
88
+ // For the purposes of determining root causes of layout shifts, we
89
+ // consider scheduleStyleInvalidationTracking and
90
+ // LayoutInvalidationTracking events as events that could have been the
91
+ // cause of the layout shift.
92
+ const eventsForLayoutInvalidation = [...layoutInvalidationEvents, ...scheduleStyleInvalidationEvents];
93
+ const nodes = await this.#protocolInterface.pushNodesByBackendIdsToFrontend(backendNodeIds);
94
+ const nodeIdsByBackendIdMap = new Map();
95
+ for (let i = 0; i < backendNodeIds.length; i++) {
96
+ nodeIdsByBackendIdMap.set(backendNodeIds[i], nodes[i]);
97
+ }
98
+ // Maps from PrePaint events to LayoutShifts that occured in each one.
99
+ const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);
100
+ for (const layoutInvalidation of eventsForLayoutInvalidation) {
101
+ // Get the first PrePaint event that happened after the current LayoutInvalidation event.
102
+ const nextPrePaintIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(prePaintEvents, prePaint => prePaint.ts > layoutInvalidation.ts);
103
+ if (nextPrePaintIndex === null) {
104
+ // No PrePaint event registered after this LayoutInvalidation. Continue.
105
+ continue;
106
+ }
107
+ const nextPrePaint = prePaintEvents[nextPrePaintIndex];
108
+ const subsequentShifts = shiftsByPrePaint.get(nextPrePaint);
109
+ if (!subsequentShifts) {
110
+ // The PrePaint after the current LayoutInvalidation doesn't contain shifts.
111
+ continue;
112
+ }
113
+ const fontChangeRootCause = this.getFontChangeRootCause(layoutInvalidation, nextPrePaint, modelData);
114
+ const renderBlockRootCause = this.getRenderBlockRootCause(layoutInvalidation, nextPrePaint, modelData);
115
+ const layoutInvalidationNodeId = nodeIdsByBackendIdMap.get(layoutInvalidation.args.data.nodeId);
116
+ const layoutInvalidationNode = layoutInvalidationNodeId !== undefined ?
117
+ await this.#protocolInterface.getNode(layoutInvalidationNodeId) :
118
+ null;
119
+ let unsizedMediaRootCause = null;
120
+ let iframeRootCause = null;
121
+ if (layoutInvalidationNode && layoutInvalidation.args.data.reason) {
122
+ unsizedMediaRootCause =
123
+ await this.getUnsizedMediaRootCause(layoutInvalidation.args.data.reason, layoutInvalidationNode);
124
+ iframeRootCause = this.getIframeRootCause(layoutInvalidation.args.data.reason, layoutInvalidationNode);
125
+ }
126
+ if (!unsizedMediaRootCause && !iframeRootCause && !fontChangeRootCause && !renderBlockRootCause) {
127
+ continue;
128
+ }
129
+ // Add found potential root causes to all the shifts in this PrePaint and populate the cache.
130
+ for (const shift of subsequentShifts) {
131
+ const rootCausesForShift = Platform.MapUtilities.getWithDefault(this.#rootCauseCacheMap, shift, () => {
132
+ return {
133
+ unsizedMedia: [],
134
+ iframes: [],
135
+ fontChanges: [],
136
+ renderBlockingRequests: [],
137
+ scriptStackTrace: [],
138
+ };
139
+ });
140
+ if (unsizedMediaRootCause &&
141
+ !rootCausesForShift.unsizedMedia.some(media => media.node.nodeId === unsizedMediaRootCause?.node.nodeId) &&
142
+ shift.args.frame === layoutInvalidation.args.data.frame) {
143
+ rootCausesForShift.unsizedMedia.push(unsizedMediaRootCause);
144
+ }
145
+ if (iframeRootCause &&
146
+ !rootCausesForShift.iframes.some(injectedIframe => injectedIframe.iframe.nodeId === iframeRootCause?.iframe.nodeId)) {
147
+ rootCausesForShift.iframes.push(iframeRootCause);
148
+ }
149
+ if (fontChangeRootCause) {
150
+ // Unlike other root causes, we calculate fonts causing a shift only once,
151
+ // which means we assign the built array instead of appending new objects
152
+ // to it.
153
+ rootCausesForShift.fontChanges = fontChangeRootCause;
154
+ }
155
+ if (renderBlockRootCause) {
156
+ rootCausesForShift.renderBlockingRequests = renderBlockRootCause;
157
+ }
158
+ }
159
+ }
160
+ }
161
+ /**
162
+ * For every shift looks up the initiator of its corresponding Layout event. This initiator
163
+ * is assigned by the RendererHandler and contains the stack trace of the point in a script
164
+ * that caused a style recalculation or a relayout. This stack trace is added to the shift's
165
+ * potential root causes.
166
+ * Note that a Layout cannot always be linked to a script, in that case, we cannot add a
167
+ * "script causing reflow" as a potential root cause to the corresponding shift.
168
+ */
169
+ linkShiftsToLayoutEvents(layoutShifts, modelData) {
170
+ const { prePaintEvents } = modelData.LayoutShifts;
171
+ // Maps from PrePaint events to LayoutShifts that occured in each one.
172
+ const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);
173
+ const eventTriggersLayout = ({ name }) => {
174
+ const knownName = name;
175
+ return knownName === "Layout" /* Types.TraceEvents.KnownEventName.Layout */;
176
+ };
177
+ const layoutEvents = modelData.Renderer.allTraceEntries.filter(eventTriggersLayout);
178
+ for (const layout of layoutEvents) {
179
+ // Get the first PrePaint event that happened after the current layout event.
180
+ const nextPrePaintIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(prePaintEvents, prePaint => prePaint.ts > layout.ts + (layout.dur || 0));
181
+ if (nextPrePaintIndex === null) {
182
+ // No PrePaint event registered after this LayoutInvalidation. Continue.
183
+ continue;
184
+ }
185
+ const nextPrePaint = prePaintEvents[nextPrePaintIndex];
186
+ const subsequentShifts = shiftsByPrePaint.get(nextPrePaint);
187
+ if (!subsequentShifts) {
188
+ // The PrePaint after the current LayoutInvalidation doesn't contain shifts.
189
+ continue;
190
+ }
191
+ const layoutNode = modelData.Renderer.entryToNode.get(layout);
192
+ const initiator = layoutNode ? modelData.Initiators.eventToInitiator.get(layoutNode.entry) : null;
193
+ const stackTrace = initiator?.args?.data?.stackTrace;
194
+ if (!stackTrace) {
195
+ continue;
196
+ }
197
+ // Add found potential root causes to all the shifts in this PrePaint and populate the cache.
198
+ for (const shift of subsequentShifts) {
199
+ const rootCausesForShift = Platform.MapUtilities.getWithDefault(this.#rootCauseCacheMap, shift, () => {
200
+ return {
201
+ unsizedMedia: [],
202
+ iframes: [],
203
+ fontChanges: [],
204
+ renderBlockingRequests: [],
205
+ scriptStackTrace: [],
206
+ };
207
+ });
208
+ if (rootCausesForShift.scriptStackTrace.length === 0) {
209
+ rootCausesForShift.scriptStackTrace = stackTrace;
210
+ }
211
+ }
212
+ }
213
+ }
214
+ /**
215
+ * Given a LayoutInvalidation trace event, determines if it was dispatched
216
+ * because a media element without dimensions was resized.
217
+ */
218
+ async getUnsizedMediaRootCause(reason, layoutInvalidationNode) {
219
+ // Filter events to resizes only.
220
+ if (reason !== "Size changed" /* Types.TraceEvents.LayoutInvalidationReason.SIZE_CHANGED */) {
221
+ return null;
222
+ }
223
+ const computedStylesList = await this.#protocolInterface.getComputedStyleForNode(layoutInvalidationNode.nodeId);
224
+ const computedStyles = new Map(computedStylesList.map(item => [item.name, item.value]));
225
+ if (computedStyles && !(await nodeIsUnfixedMedia(layoutInvalidationNode, computedStyles))) {
226
+ return null;
227
+ }
228
+ const authoredDimensions = await this.getNodeAuthoredDimensions(layoutInvalidationNode);
229
+ if (dimensionsAreExplicit(authoredDimensions)) {
230
+ return null;
231
+ }
232
+ const computedDimensions = computedStyles ? getNodeComputedDimensions(computedStyles) : {};
233
+ return { node: layoutInvalidationNode, authoredDimensions, computedDimensions };
234
+ }
235
+ /**
236
+ * Given a LayoutInvalidation trace event, determines if it was dispatched
237
+ * because a node, which is an ancestor to an iframe, was injected.
238
+ */
239
+ getIframeRootCause(reason, layoutInvalidationDOMNode) {
240
+ if (layoutInvalidationDOMNode.nodeName !== 'IFRAME' &&
241
+ reason !== "Style changed" /* Types.TraceEvents.LayoutInvalidationReason.STYLE_CHANGED */ &&
242
+ reason !== "Added to layout" /* Types.TraceEvents.LayoutInvalidationReason.ADDED_TO_LAYOUT */) {
243
+ return null;
244
+ }
245
+ const iframe = firstIframeInDOMTree(layoutInvalidationDOMNode);
246
+ if (!iframe) {
247
+ return null;
248
+ }
249
+ return { iframe };
250
+ }
251
+ /**
252
+ * Given a layout invalidation event and a sorted array, returns the subset of requests that arrived within a
253
+ * 500ms window before the layout invalidation.
254
+ */
255
+ requestsInInvalidationWindow(layoutInvalidation, modelData) {
256
+ const requestsSortedByEndTime = modelData.NetworkRequests.byTime.sort((req1, req2) => {
257
+ const req1EndTime = req1.ts + req1.dur;
258
+ const req2EndTime = req2.ts + req2.dur;
259
+ return req1EndTime - req2EndTime;
260
+ });
261
+ const lastRequestIndex = Platform.ArrayUtilities.nearestIndexFromEnd(requestsSortedByEndTime, request => request.ts + request.dur < layoutInvalidation.ts);
262
+ if (lastRequestIndex === null) {
263
+ return [];
264
+ }
265
+ const MAX_DELTA_FOR_FONT_REQUEST = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));
266
+ const requestsInInvalidationWindow = [];
267
+ // Get all requests finished within the valid window.
268
+ for (let i = lastRequestIndex; i > -1; i--) {
269
+ const previousRequest = requestsSortedByEndTime[i];
270
+ const previousRequestEndTime = previousRequest.ts + previousRequest.dur;
271
+ if (layoutInvalidation.ts - previousRequestEndTime < MAX_DELTA_FOR_FONT_REQUEST) {
272
+ const requestInInvalidationWindow = { request: previousRequest };
273
+ const initiator = this.#protocolInterface.getInitiatorForRequest(previousRequest.args.data.url);
274
+ requestInInvalidationWindow.initiator = initiator || undefined;
275
+ requestsInInvalidationWindow.push(requestInInvalidationWindow);
276
+ }
277
+ else {
278
+ // No more requests fit in the time window.
279
+ break;
280
+ }
281
+ }
282
+ return requestsInInvalidationWindow;
283
+ }
284
+ /**
285
+ * Given a LayoutInvalidation trace event, determines if it was dispatched
286
+ * because fonts were changed and if so returns the information of all network
287
+ * request with which the fonts were possibly fetched, if any. The computed
288
+ * network requests are cached for the corresponding prepaint event, meaning
289
+ * that other LayoutInvalidation events that correspond to the same prepaint
290
+ * are not processed and the cached network requests for the prepaint is
291
+ * returned instead.
292
+ */
293
+ getFontChangeRootCause(layoutInvalidation, nextPrePaint, modelData) {
294
+ if (layoutInvalidation.args.data.reason !== "Fonts changed" /* Types.TraceEvents.LayoutInvalidationReason.FONTS_CHANGED */) {
295
+ return null;
296
+ }
297
+ // Prevent computing the result of this function multiple times per PrePaint event.
298
+ const fontRequestsForPrepaint = fontRequestsByPrePaint.get(nextPrePaint);
299
+ if (fontRequestsForPrepaint !== undefined) {
300
+ return fontRequestsForPrepaint;
301
+ }
302
+ const fontRequestsInThisPrepaint = this.getFontRequestsInInvalidationWindow(this.requestsInInvalidationWindow(layoutInvalidation, modelData));
303
+ fontRequestsByPrePaint.set(nextPrePaint, fontRequestsInThisPrepaint);
304
+ return fontRequestsInThisPrepaint;
305
+ }
306
+ /**
307
+ * Given the requests that arrived within a 500ms window before the layout invalidation, returns the font
308
+ * requests of them.
309
+ */
310
+ getFontRequestsInInvalidationWindow(requestsInInvalidationWindow) {
311
+ const fontRequests = [];
312
+ // Get all requests finished within the valid window.
313
+ for (let i = 0; i < requestsInInvalidationWindow.length; i++) {
314
+ const fontRequest = requestsInInvalidationWindow[i];
315
+ if (!fontRequest.request.args.data.mimeType.startsWith('font')) {
316
+ continue;
317
+ }
318
+ const fontFace = this.#protocolInterface.fontFaceForSource(fontRequest.request.args.data.url);
319
+ if (!fontFace || fontFace.fontDisplay === 'optional') {
320
+ // Setting font-display to optional is part of what the developer
321
+ // can do to avoid layout shifts due to FOIT/FOUT, as such we cannot
322
+ // suggest any actionable insight here.
323
+ continue;
324
+ }
325
+ fontRequest.fontFace = fontFace;
326
+ fontRequests.push(fontRequest);
327
+ }
328
+ return fontRequests;
329
+ }
330
+ /**
331
+ * Given a LayoutInvalidation trace event, determines if it arrived within a 500ms window before the layout
332
+ * invalidation and if so returns the information of all network request, if any. The computed network
333
+ * requests are cached for the corresponding prepaint event, meaning that other LayoutInvalidation events
334
+ * that correspond to the same prepaint are not processed and the cached network requests for the prepaint is
335
+ * returned instead.
336
+ */
337
+ getRenderBlockRootCause(layoutInvalidation, nextPrePaint, modelData) {
338
+ // Prevent computing the result of this function multiple times per PrePaint event.
339
+ const renderBlocksInPrepaint = renderBlocksByPrePaint.get(nextPrePaint);
340
+ if (renderBlocksInPrepaint !== undefined) {
341
+ return renderBlocksInPrepaint;
342
+ }
343
+ const renderBlocksInThisPrepaint = getRenderBlockRequestsInInvalidationWindow(this.requestsInInvalidationWindow(layoutInvalidation, modelData));
344
+ renderBlocksByPrePaint.set(nextPrePaint, renderBlocksInThisPrepaint);
345
+ return renderBlocksInThisPrepaint;
346
+ }
347
+ /**
348
+ * Returns a function that retrieves the active value of a given
349
+ * CSS property within the matched styles of the param node.
350
+ * The first occurence within the matched styles is returned and the
351
+ * value is looked up in the following order, which follows CSS
352
+ * specificity:
353
+ * 1. Inline styles.
354
+ * 2. CSS rules matching this node, from all applicable stylesheets.
355
+ * 3. Attribute defined styles.
356
+ */
357
+ async nodeMatchedStylesPropertyGetter(node) {
358
+ const response = await this.#protocolInterface.getMatchedStylesForNode(node.nodeId);
359
+ function cssPropertyValueGetter(cssProperty) {
360
+ let prop = response.inlineStyle?.cssProperties.find(prop => prop.name === cssProperty);
361
+ if (prop) {
362
+ return prop.value;
363
+ }
364
+ for (const { rule } of response.matchedCSSRules || []) {
365
+ const prop = rule.style.cssProperties.find(prop => prop.name === cssProperty);
366
+ if (prop) {
367
+ return prop.value;
368
+ }
369
+ }
370
+ prop = response.attributesStyle?.cssProperties.find(prop => prop.name === cssProperty);
371
+ if (prop) {
372
+ return prop.value;
373
+ }
374
+ return null;
375
+ }
376
+ return cssPropertyValueGetter;
377
+ }
378
+ /**
379
+ * Returns the CSS dimensions set to the node from its matched styles.
380
+ */
381
+ async getNodeAuthoredDimensions(node) {
382
+ const authoredDimensions = {};
383
+ const cssMatchedRulesGetter = await this.nodeMatchedStylesPropertyGetter(node);
384
+ if (!cssMatchedRulesGetter) {
385
+ return authoredDimensions;
386
+ }
387
+ const attributesFlat = node.attributes || [];
388
+ const attributes = [];
389
+ for (let i = 0; i < attributesFlat.length; i += 2) {
390
+ attributes.push({ name: attributesFlat[i], value: attributesFlat[i + 1] });
391
+ }
392
+ const htmlHeight = attributes.find(attr => attr.name === 'height' && htmlAttributeIsExplicit(attr));
393
+ const htmlWidth = attributes.find(attr => attr.name === 'width' && htmlAttributeIsExplicit(attr));
394
+ const cssExplicitAspectRatio = cssMatchedRulesGetter('aspect-ratio') || undefined;
395
+ if (htmlHeight && htmlWidth && cssExplicitAspectRatio) {
396
+ return { height: htmlHeight.value, width: htmlWidth.value, aspectRatio: cssExplicitAspectRatio };
397
+ }
398
+ const cssHeight = cssMatchedRulesGetter('height') || undefined;
399
+ const cssWidth = cssMatchedRulesGetter('width') || undefined;
400
+ return { height: cssHeight, width: cssWidth, aspectRatio: cssExplicitAspectRatio };
401
+ }
402
+ }
403
+ /**
404
+ * Given the requests that arrived within a 500ms window before the layout invalidation, returns the render
405
+ * block requests of them.
406
+ */
407
+ function getRenderBlockRequestsInInvalidationWindow(requestsInInvalidationWindow) {
408
+ const renderBlockingRequests = [];
409
+ // Get all requests finished within the valid window.
410
+ for (let i = 0; i < requestsInInvalidationWindow.length; i++) {
411
+ const mainFrameId = requestsInInvalidationWindow[i].request.args.data.frame;
412
+ if (!networkRequestIsRenderBlockingInFrame(requestsInInvalidationWindow[i].request, mainFrameId)) {
413
+ continue;
414
+ }
415
+ renderBlockingRequests.push(requestsInInvalidationWindow[i]);
416
+ }
417
+ return renderBlockingRequests;
418
+ }
419
+ function firstIframeInDOMTree(root) {
420
+ if (root.nodeName === 'IFRAME') {
421
+ return root;
422
+ }
423
+ const children = root.children;
424
+ if (!children) {
425
+ return null;
426
+ }
427
+ for (const child of children) {
428
+ const iFrameInChild = firstIframeInDOMTree(child);
429
+ if (iFrameInChild) {
430
+ return iFrameInChild;
431
+ }
432
+ }
433
+ return null;
434
+ }
435
+ function cssPropertyIsExplicitlySet(propertyValue) {
436
+ return !['auto', 'initial', 'unset', 'inherit'].includes(propertyValue);
437
+ }
438
+ function htmlAttributeIsExplicit(attr) {
439
+ return parseInt(attr.value, 10) >= 0;
440
+ }
441
+ function computedStyleHasBackroundImage(computedStyle) {
442
+ const CSS_URL_REGEX = /^url\("([^"]+)"\)$/;
443
+ const backgroundImage = computedStyle.get('background-image');
444
+ if (!backgroundImage) {
445
+ return false;
446
+ }
447
+ return CSS_URL_REGEX.test(backgroundImage);
448
+ }
449
+ function computedStyleHasFixedPosition(computedStyle) {
450
+ const position = computedStyle.get('position');
451
+ if (!position) {
452
+ return false;
453
+ }
454
+ return position === 'fixed' || position === 'absolute';
455
+ }
456
+ function getNodeComputedDimensions(computedStyle) {
457
+ const computedDimensions = {};
458
+ computedDimensions.height = computedStyle.get('height');
459
+ computedDimensions.width = computedStyle.get('width');
460
+ computedDimensions.aspectRatio = computedStyle.get('aspect-ratio');
461
+ return computedDimensions;
462
+ }
463
+ /**
464
+ * Determines if a node is a media element and is not fixed positioned
465
+ * (i.e. "position: fixed;" or "position: absolute;")
466
+ */
467
+ async function nodeIsUnfixedMedia(node, computedStyle) {
468
+ const localName = node.localName;
469
+ const isBackgroundImage = computedStyleHasBackroundImage(computedStyle);
470
+ if (localName !== 'img' && localName !== 'video' && !isBackgroundImage) {
471
+ // Not a media element.
472
+ return false;
473
+ }
474
+ const isFixed = computedStyleHasFixedPosition(computedStyle);
475
+ return !isFixed;
476
+ }
477
+ /**
478
+ * Determines if a CSS dimensions object explicitly defines both width and height
479
+ * (i.e. not set to auto, inherit, etc.)
480
+ */
481
+ function dimensionsAreExplicit(dimensions) {
482
+ const { height, width, aspectRatio } = dimensions;
483
+ const explicitHeight = Boolean(height && cssPropertyIsExplicitlySet(height));
484
+ const explicitWidth = Boolean(width && cssPropertyIsExplicitlySet(width));
485
+ const explicitAspectRatio = Boolean(aspectRatio && cssPropertyIsExplicitlySet(aspectRatio));
486
+ const explicitWithAR = (explicitHeight || explicitWidth) && explicitAspectRatio;
487
+ return (explicitHeight && explicitWidth) || explicitWithAR;
488
+ }
489
+ /**
490
+ * Given an array of layout shift and PrePaint events, returns a mapping from
491
+ * PrePaint events to layout shifts dispatched within it.
492
+ */
493
+ function getShiftsByPrePaintEvents(layoutShifts, prePaintEvents) {
494
+ // Maps from PrePaint events to LayoutShifts that occured in each one.
495
+ const shiftsByPrePaint = new Map();
496
+ // Associate all shifts to their corresponding PrePaint.
497
+ for (const prePaintEvent of prePaintEvents) {
498
+ const firstShiftIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(layoutShifts, shift => shift.ts >= prePaintEvent.ts);
499
+ if (firstShiftIndex === null) {
500
+ // No layout shifts registered after this PrePaint start. Continue.
501
+ continue;
502
+ }
503
+ for (let i = firstShiftIndex; i < layoutShifts.length; i++) {
504
+ const shift = layoutShifts[i];
505
+ if (shift.ts >= prePaintEvent.ts && shift.ts <= prePaintEvent.ts + prePaintEvent.dur) {
506
+ const shiftsInPrePaint = Platform.MapUtilities.getWithDefault(shiftsByPrePaint, prePaintEvent, () => []);
507
+ shiftsInPrePaint.push(shift);
508
+ }
509
+ if (shift.ts > prePaintEvent.ts + prePaintEvent.dur) {
510
+ // Reached the end of this PrePaint. Continue to the next one.
511
+ break;
512
+ }
513
+ }
514
+ }
515
+ return shiftsByPrePaint;
516
+ }
517
+ //# sourceMappingURL=LayoutShift.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LayoutShift.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/root-causes/LayoutShift.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAG/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAuC3C,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAA2D,CAAC;AAClG,MAAM,sBAAsB,GAAG,IAAI,GAAG,EAAsE,CAAC;AAE7G,SAAS,eAAe,CACpB,GAA4E,EAC5E,KAA8C;IAChD,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE;QACpD,OAAO;YACL,YAAY,EAAE,EAAE;YAChB,OAAO,EAAE,EAAE;YACX,WAAW,EAAE,EAAE;YACf,sBAAsB,EAAE,EAAE;YAC1B,gBAAgB,EAAE,EAAE;SACrB,CAAC;IACJ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AE,CAAC,EAAE,EAAE;YAC1D,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;YAC9B,IAAI,KAAK,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,IAAI,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,GAAG,EAAE;gBACpF,MAAM,gBAAgB,GAAG,QAAQ,CAAC,YAAY,CAAC,cAAc,CAAC,gBAAgB,EAAE,aAAa,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;gBACzG,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC9B;YACD,IAAI,KAAK,CAAC,EAAE,GAAG,aAAa,CAAC,EAAE,GAAG,aAAa,CAAC,GAAG,EAAE;gBACnD,8DAA8D;gBAC9D,MAAM;aACP;SACF;KACF;IACD,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright 2023 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 Platform from '../../../core/platform/platform.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport {type TraceParseData} from '../handlers/types.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {type RootCauseProtocolInterface} from './RootCauses.js';\n\nexport type CSSDimensions = {\n width?: string,\n height?: string,\n aspectRatio?: string,\n};\n\nexport interface UnsizedMedia {\n node: Protocol.DOM.Node;\n authoredDimensions?: CSSDimensions;\n computedDimensions: CSSDimensions;\n}\n\nexport interface InjectedIframe {\n iframe: Protocol.DOM.Node;\n}\n\nexport interface RootCauseRequest {\n request: Types.TraceEvents.SyntheticNetworkRequest;\n initiator?: Protocol.Network.Initiator;\n}\n\nexport interface FontChange extends RootCauseRequest {\n fontFace: Protocol.CSS.FontFace;\n}\n\nexport interface RenderBlockingRequest extends RootCauseRequest {}\n\nexport interface LayoutShiftRootCausesData {\n unsizedMedia: UnsizedMedia[];\n iframes: InjectedIframe[];\n fontChanges: FontChange[];\n renderBlockingRequests: RenderBlockingRequest[];\n scriptStackTrace: Types.TraceEvents.TraceEventCallFrame[];\n}\n\nconst fontRequestsByPrePaint = new Map<Types.TraceEvents.TraceEventPrePaint, FontChange[]|null>();\nconst renderBlocksByPrePaint = new Map<Types.TraceEvents.TraceEventPrePaint, RenderBlockingRequest[]|null>();\n\nfunction setDefaultValue(\n map: Map<Types.TraceEvents.TraceEventLayoutShift, LayoutShiftRootCausesData>,\n shift: Types.TraceEvents.TraceEventLayoutShift): void {\n Platform.MapUtilities.getWithDefault(map, shift, () => {\n return {\n unsizedMedia: [],\n iframes: [],\n fontChanges: [],\n renderBlockingRequests: [],\n scriptStackTrace: [],\n };\n });\n}\n\n// Important: we purposefully treat `potentially_blocking` as\n// non-render-blocking here because:\n// 1. An async script can run on the main thread at any point, including before\n// the page is loaded\n// 2. An async script will never block the parsing and rendering process of the\n// browser.\n// 3. Therefore, from a developer's point of view, there is nothing more they\n// can do if they've put `async` on, and within the context of Insights, we\n// shouldn't report an async script as render blocking.\n// In the future we may want to consider suggesting the use of `defer` over\n// `async`, as it doesn't have this concern, but for now we'll allow `async`\n// and not report it as an issue.\nconst NON_RENDER_BLOCKING_VALUES = new Set<Types.TraceEvents.RenderBlocking>([\n 'non_blocking',\n 'potentially_blocking',\n]);\nfunction networkRequestIsRenderBlockingInFrame(\n event: Types.TraceEvents.SyntheticNetworkRequest, frameId: string): boolean {\n const isRenderBlocking = !NON_RENDER_BLOCKING_VALUES.has(event.args.data.renderBlocking);\n return isRenderBlocking && event.args.data.frame === frameId;\n}\n\nexport class LayoutShiftRootCauses {\n #protocolInterface: RootCauseProtocolInterface;\n #rootCauseCacheMap = new Map<Types.TraceEvents.TraceEventLayoutShift, LayoutShiftRootCausesData>();\n\n constructor(protocolInterface: RootCauseProtocolInterface) {\n this.#protocolInterface = protocolInterface;\n }\n\n /**\n * Calculates the potential root causes for a given layout shift event. Once\n * calculated, this data is cached.\n * Note: because you need all layout shift data at once to calculate these\n * correctly, this function will parse the root causes for _all_ layout shift\n * events the first time that it's called. That then populates the cache for\n * each shift, so any subsequent calls are just a constant lookup.\n */\n async rootCausesForEvent(modelData: TraceParseData, event: Types.TraceEvents.TraceEventLayoutShift):\n Promise<Readonly<LayoutShiftRootCausesData>|null> {\n const cachedResult = this.#rootCauseCacheMap.get(event);\n if (cachedResult) {\n return cachedResult;\n }\n\n const allLayoutShifts = modelData.LayoutShifts.clusters.flatMap(cluster => cluster.events);\n // Make sure a value in the cache is set even for shifts that don't have a root cause,\n // so that we don't have to recompute when no root causes are found. In case a cause\n // for a shift is found, the default value is replaced.\n allLayoutShifts.forEach(shift => setDefaultValue(this.#rootCauseCacheMap, shift));\n\n // Populate the cache\n await this.blameShifts(\n allLayoutShifts,\n modelData,\n );\n\n const resultForEvent = this.#rootCauseCacheMap.get(event);\n if (!resultForEvent) {\n // No root causes available for this layout shift.\n return null;\n }\n return resultForEvent;\n }\n\n /**\n * Determines potential root causes for shifts\n */\n async blameShifts(\n layoutShifts: Types.TraceEvents.TraceEventLayoutShift[],\n modelData: TraceParseData,\n ): Promise<void> {\n await this.linkShiftsToLayoutInvalidations(layoutShifts, modelData);\n this.linkShiftsToLayoutEvents(layoutShifts, modelData);\n }\n\n /**\n * \"LayoutInvalidations\" are a set of trace events dispatched in Blink under the name\n * \"layoutInvalidationTracking\", which track invalidations on the \"Layout\"stage of the\n * rendering pipeline. This function utilizes this event to flag potential root causes\n * to layout shifts.\n */\n async linkShiftsToLayoutInvalidations(\n layoutShifts: Types.TraceEvents.TraceEventLayoutShift[], modelData: TraceParseData): Promise<void> {\n const {prePaintEvents, layoutInvalidationEvents, scheduleStyleInvalidationEvents, backendNodeIds} =\n modelData.LayoutShifts;\n\n // For the purposes of determining root causes of layout shifts, we\n // consider scheduleStyleInvalidationTracking and\n // LayoutInvalidationTracking events as events that could have been the\n // cause of the layout shift.\n const eventsForLayoutInvalidation: Array<Types.TraceEvents.TraceEventLayoutInvalidationTracking|\n Types.TraceEvents.TraceEventScheduleStyleInvalidationTracking> =\n [...layoutInvalidationEvents, ...scheduleStyleInvalidationEvents];\n\n const nodes = await this.#protocolInterface.pushNodesByBackendIdsToFrontend(backendNodeIds);\n const nodeIdsByBackendIdMap = new Map<Protocol.DOM.BackendNodeId, Protocol.DOM.NodeId>();\n for (let i = 0; i < backendNodeIds.length; i++) {\n nodeIdsByBackendIdMap.set(backendNodeIds[i], nodes[i]);\n }\n\n // Maps from PrePaint events to LayoutShifts that occured in each one.\n const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);\n for (const layoutInvalidation of eventsForLayoutInvalidation) {\n // Get the first PrePaint event that happened after the current LayoutInvalidation event.\n const nextPrePaintIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(\n prePaintEvents, prePaint => prePaint.ts > layoutInvalidation.ts);\n if (nextPrePaintIndex === null) {\n // No PrePaint event registered after this LayoutInvalidation. Continue.\n continue;\n }\n const nextPrePaint = prePaintEvents[nextPrePaintIndex];\n const subsequentShifts = shiftsByPrePaint.get(nextPrePaint);\n if (!subsequentShifts) {\n // The PrePaint after the current LayoutInvalidation doesn't contain shifts.\n continue;\n }\n const fontChangeRootCause = this.getFontChangeRootCause(layoutInvalidation, nextPrePaint, modelData);\n const renderBlockRootCause = this.getRenderBlockRootCause(layoutInvalidation, nextPrePaint, modelData);\n const layoutInvalidationNodeId = nodeIdsByBackendIdMap.get(layoutInvalidation.args.data.nodeId);\n const layoutInvalidationNode = layoutInvalidationNodeId !== undefined ?\n await this.#protocolInterface.getNode(layoutInvalidationNodeId) :\n null;\n let unsizedMediaRootCause: UnsizedMedia|null = null;\n let iframeRootCause: InjectedIframe|null = null;\n if (layoutInvalidationNode && layoutInvalidation.args.data.reason) {\n unsizedMediaRootCause =\n await this.getUnsizedMediaRootCause(layoutInvalidation.args.data.reason, layoutInvalidationNode);\n iframeRootCause = this.getIframeRootCause(layoutInvalidation.args.data.reason, layoutInvalidationNode);\n }\n\n if (!unsizedMediaRootCause && !iframeRootCause && !fontChangeRootCause && !renderBlockRootCause) {\n continue;\n }\n\n // Add found potential root causes to all the shifts in this PrePaint and populate the cache.\n for (const shift of subsequentShifts) {\n const rootCausesForShift = Platform.MapUtilities.getWithDefault(this.#rootCauseCacheMap, shift, () => {\n return {\n unsizedMedia: [],\n iframes: [],\n fontChanges: [],\n renderBlockingRequests: [],\n scriptStackTrace: [],\n };\n });\n if (unsizedMediaRootCause &&\n !rootCausesForShift.unsizedMedia.some(media => media.node.nodeId === unsizedMediaRootCause?.node.nodeId) &&\n shift.args.frame === layoutInvalidation.args.data.frame) {\n rootCausesForShift.unsizedMedia.push(unsizedMediaRootCause);\n }\n if (iframeRootCause &&\n !rootCausesForShift.iframes.some(\n injectedIframe => injectedIframe.iframe.nodeId === iframeRootCause?.iframe.nodeId)) {\n rootCausesForShift.iframes.push(iframeRootCause);\n }\n if (fontChangeRootCause) {\n // Unlike other root causes, we calculate fonts causing a shift only once,\n // which means we assign the built array instead of appending new objects\n // to it.\n rootCausesForShift.fontChanges = fontChangeRootCause;\n }\n if (renderBlockRootCause) {\n rootCausesForShift.renderBlockingRequests = renderBlockRootCause;\n }\n }\n }\n }\n\n /**\n * For every shift looks up the initiator of its corresponding Layout event. This initiator\n * is assigned by the RendererHandler and contains the stack trace of the point in a script\n * that caused a style recalculation or a relayout. This stack trace is added to the shift's\n * potential root causes.\n * Note that a Layout cannot always be linked to a script, in that case, we cannot add a\n * \"script causing reflow\" as a potential root cause to the corresponding shift.\n */\n linkShiftsToLayoutEvents(layoutShifts: Types.TraceEvents.TraceEventLayoutShift[], modelData: TraceParseData): void {\n const {prePaintEvents} = modelData.LayoutShifts;\n // Maps from PrePaint events to LayoutShifts that occured in each one.\n const shiftsByPrePaint = getShiftsByPrePaintEvents(layoutShifts, prePaintEvents);\n\n const eventTriggersLayout = ({name}: {name: string}): boolean => {\n const knownName = name as Types.TraceEvents.KnownEventName;\n return knownName === Types.TraceEvents.KnownEventName.Layout;\n };\n const layoutEvents = modelData.Renderer.allTraceEntries.filter(eventTriggersLayout);\n for (const layout of layoutEvents) {\n // Get the first PrePaint event that happened after the current layout event.\n const nextPrePaintIndex = Platform.ArrayUtilities.nearestIndexFromBeginning(\n prePaintEvents, prePaint => prePaint.ts > layout.ts + (layout.dur || 0));\n if (nextPrePaintIndex === null) {\n // No PrePaint event registered after this LayoutInvalidation. Continue.\n continue;\n }\n const nextPrePaint = prePaintEvents[nextPrePaintIndex];\n const subsequentShifts = shiftsByPrePaint.get(nextPrePaint);\n if (!subsequentShifts) {\n // The PrePaint after the current LayoutInvalidation doesn't contain shifts.\n continue;\n }\n const layoutNode = modelData.Renderer.entryToNode.get(layout);\n const initiator = layoutNode ? modelData.Initiators.eventToInitiator.get(layoutNode.entry) : null;\n const stackTrace = initiator?.args?.data?.stackTrace;\n if (!stackTrace) {\n continue;\n }\n // Add found potential root causes to all the shifts in this PrePaint and populate the cache.\n for (const shift of subsequentShifts) {\n const rootCausesForShift = Platform.MapUtilities.getWithDefault(this.#rootCauseCacheMap, shift, () => {\n return {\n unsizedMedia: [],\n iframes: [],\n fontChanges: [],\n renderBlockingRequests: [],\n scriptStackTrace: [],\n };\n });\n if (rootCausesForShift.scriptStackTrace.length === 0) {\n rootCausesForShift.scriptStackTrace = stackTrace;\n }\n }\n }\n }\n\n /**\n * Given a LayoutInvalidation trace event, determines if it was dispatched\n * because a media element without dimensions was resized.\n */\n async getUnsizedMediaRootCause(\n reason: Types.TraceEvents.LayoutInvalidationReason,\n layoutInvalidationNode: Protocol.DOM.Node): Promise<UnsizedMedia|null> {\n // Filter events to resizes only.\n if (reason !== Types.TraceEvents.LayoutInvalidationReason.SIZE_CHANGED) {\n return null;\n }\n const computedStylesList = await this.#protocolInterface.getComputedStyleForNode(layoutInvalidationNode.nodeId);\n const computedStyles = new Map(computedStylesList.map(item => [item.name, item.value]));\n if (computedStyles && !(await nodeIsUnfixedMedia(layoutInvalidationNode, computedStyles))) {\n return null;\n }\n const authoredDimensions = await this.getNodeAuthoredDimensions(layoutInvalidationNode);\n if (dimensionsAreExplicit(authoredDimensions)) {\n return null;\n }\n const computedDimensions = computedStyles ? getNodeComputedDimensions(computedStyles) : {};\n\n return {node: layoutInvalidationNode, authoredDimensions, computedDimensions};\n }\n\n /**\n * Given a LayoutInvalidation trace event, determines if it was dispatched\n * because a node, which is an ancestor to an iframe, was injected.\n */\n getIframeRootCause(reason: Types.TraceEvents.LayoutInvalidationReason, layoutInvalidationDOMNode: Protocol.DOM.Node):\n InjectedIframe|null {\n if (layoutInvalidationDOMNode.nodeName !== 'IFRAME' &&\n reason !== Types.TraceEvents.LayoutInvalidationReason.STYLE_CHANGED &&\n reason !== Types.TraceEvents.LayoutInvalidationReason.ADDED_TO_LAYOUT) {\n return null;\n }\n const iframe = firstIframeInDOMTree(layoutInvalidationDOMNode);\n if (!iframe) {\n return null;\n }\n return {iframe};\n }\n\n /**\n * Given a layout invalidation event and a sorted array, returns the subset of requests that arrived within a\n * 500ms window before the layout invalidation.\n */\n requestsInInvalidationWindow(\n layoutInvalidation: Types.TraceEvents.TraceEventLayoutInvalidationTracking|\n Types.TraceEvents.TraceEventScheduleStyleInvalidationTracking,\n modelData: TraceParseData): RootCauseRequest[] {\n const requestsSortedByEndTime = modelData.NetworkRequests.byTime.sort((req1, req2) => {\n const req1EndTime = req1.ts + req1.dur;\n const req2EndTime = req2.ts + req2.dur;\n return req1EndTime - req2EndTime;\n });\n\n const lastRequestIndex = Platform.ArrayUtilities.nearestIndexFromEnd(\n requestsSortedByEndTime, request => request.ts + request.dur < layoutInvalidation.ts);\n if (lastRequestIndex === null) {\n return [];\n }\n\n const MAX_DELTA_FOR_FONT_REQUEST = Helpers.Timing.secondsToMicroseconds(Types.Timing.Seconds(0.5));\n\n const requestsInInvalidationWindow: RootCauseRequest[] = [];\n\n // Get all requests finished within the valid window.\n for (let i = lastRequestIndex; i > -1; i--) {\n const previousRequest = requestsSortedByEndTime[i];\n const previousRequestEndTime = previousRequest.ts + previousRequest.dur;\n if (layoutInvalidation.ts - previousRequestEndTime < MAX_DELTA_FOR_FONT_REQUEST) {\n const requestInInvalidationWindow: RootCauseRequest = {request: previousRequest};\n\n const initiator = this.#protocolInterface.getInitiatorForRequest(\n previousRequest.args.data.url as Platform.DevToolsPath.UrlString);\n requestInInvalidationWindow.initiator = initiator || undefined;\n requestsInInvalidationWindow.push(requestInInvalidationWindow);\n } else {\n // No more requests fit in the time window.\n break;\n }\n }\n return requestsInInvalidationWindow;\n }\n\n /**\n * Given a LayoutInvalidation trace event, determines if it was dispatched\n * because fonts were changed and if so returns the information of all network\n * request with which the fonts were possibly fetched, if any. The computed\n * network requests are cached for the corresponding prepaint event, meaning\n * that other LayoutInvalidation events that correspond to the same prepaint\n * are not processed and the cached network requests for the prepaint is\n * returned instead.\n */\n getFontChangeRootCause(\n layoutInvalidation: Types.TraceEvents.TraceEventLayoutInvalidationTracking|\n Types.TraceEvents.TraceEventScheduleStyleInvalidationTracking,\n nextPrePaint: Types.TraceEvents.TraceEventPrePaint, modelData: TraceParseData): FontChange[]|null {\n if (layoutInvalidation.args.data.reason !== Types.TraceEvents.LayoutInvalidationReason.FONTS_CHANGED) {\n return null;\n }\n // Prevent computing the result of this function multiple times per PrePaint event.\n const fontRequestsForPrepaint = fontRequestsByPrePaint.get(nextPrePaint);\n if (fontRequestsForPrepaint !== undefined) {\n return fontRequestsForPrepaint;\n }\n\n const fontRequestsInThisPrepaint =\n this.getFontRequestsInInvalidationWindow(this.requestsInInvalidationWindow(layoutInvalidation, modelData));\n fontRequestsByPrePaint.set(nextPrePaint, fontRequestsInThisPrepaint);\n return fontRequestsInThisPrepaint;\n }\n\n /**\n * Given the requests that arrived within a 500ms window before the layout invalidation, returns the font\n * requests of them.\n */\n getFontRequestsInInvalidationWindow(requestsInInvalidationWindow: RootCauseRequest[]): FontChange[] {\n const fontRequests: FontChange[] = [];\n\n // Get all requests finished within the valid window.\n for (let i = 0; i < requestsInInvalidationWindow.length; i++) {\n const fontRequest = requestsInInvalidationWindow[i] as FontChange;\n if (!fontRequest.request.args.data.mimeType.startsWith('font')) {\n continue;\n }\n\n const fontFace = this.#protocolInterface.fontFaceForSource(fontRequest.request.args.data.url);\n if (!fontFace || fontFace.fontDisplay === 'optional') {\n // Setting font-display to optional is part of what the developer\n // can do to avoid layout shifts due to FOIT/FOUT, as such we cannot\n // suggest any actionable insight here.\n continue;\n }\n fontRequest.fontFace = fontFace;\n fontRequests.push(fontRequest);\n }\n return fontRequests;\n }\n\n /**\n * Given a LayoutInvalidation trace event, determines if it arrived within a 500ms window before the layout\n * invalidation and if so returns the information of all network request, if any. The computed network\n * requests are cached for the corresponding prepaint event, meaning that other LayoutInvalidation events\n * that correspond to the same prepaint are not processed and the cached network requests for the prepaint is\n * returned instead.\n */\n getRenderBlockRootCause(\n layoutInvalidation: Types.TraceEvents.TraceEventLayoutInvalidationTracking|\n Types.TraceEvents.TraceEventScheduleStyleInvalidationTracking,\n nextPrePaint: Types.TraceEvents.TraceEventPrePaint, modelData: TraceParseData): RenderBlockingRequest[]|null {\n // Prevent computing the result of this function multiple times per PrePaint event.\n const renderBlocksInPrepaint = renderBlocksByPrePaint.get(nextPrePaint);\n if (renderBlocksInPrepaint !== undefined) {\n return renderBlocksInPrepaint;\n }\n\n const renderBlocksInThisPrepaint =\n getRenderBlockRequestsInInvalidationWindow(this.requestsInInvalidationWindow(layoutInvalidation, modelData));\n renderBlocksByPrePaint.set(nextPrePaint, renderBlocksInThisPrepaint);\n return renderBlocksInThisPrepaint;\n }\n\n /**\n * Returns a function that retrieves the active value of a given\n * CSS property within the matched styles of the param node.\n * The first occurence within the matched styles is returned and the\n * value is looked up in the following order, which follows CSS\n * specificity:\n * 1. Inline styles.\n * 2. CSS rules matching this node, from all applicable stylesheets.\n * 3. Attribute defined styles.\n */\n async nodeMatchedStylesPropertyGetter(node: Protocol.DOM.Node): Promise<((property: string) => string | null)> {\n const response = await this.#protocolInterface.getMatchedStylesForNode(node.nodeId);\n\n function cssPropertyValueGetter(cssProperty: string): string|null {\n let prop = response.inlineStyle?.cssProperties.find(prop => prop.name === cssProperty);\n if (prop) {\n return prop.value;\n }\n\n for (const {rule} of response.matchedCSSRules || []) {\n const prop = rule.style.cssProperties.find(prop => prop.name === cssProperty);\n if (prop) {\n return prop.value;\n }\n }\n\n prop = response.attributesStyle?.cssProperties.find(prop => prop.name === cssProperty);\n if (prop) {\n return prop.value;\n }\n\n return null;\n }\n return cssPropertyValueGetter;\n }\n\n /**\n * Returns the CSS dimensions set to the node from its matched styles.\n */\n async getNodeAuthoredDimensions(node: Protocol.DOM.Node): Promise<CSSDimensions> {\n const authoredDimensions: CSSDimensions = {};\n\n const cssMatchedRulesGetter = await this.nodeMatchedStylesPropertyGetter(node);\n if (!cssMatchedRulesGetter) {\n return authoredDimensions;\n }\n\n const attributesFlat = node.attributes || [];\n const attributes = [];\n for (let i = 0; i < attributesFlat.length; i += 2) {\n attributes.push({name: attributesFlat[i], value: attributesFlat[i + 1]});\n }\n\n const htmlHeight = attributes.find(attr => attr.name === 'height' && htmlAttributeIsExplicit(attr));\n const htmlWidth = attributes.find(attr => attr.name === 'width' && htmlAttributeIsExplicit(attr));\n\n const cssExplicitAspectRatio = cssMatchedRulesGetter('aspect-ratio') || undefined;\n\n if (htmlHeight && htmlWidth && cssExplicitAspectRatio) {\n return {height: htmlHeight.value, width: htmlWidth.value, aspectRatio: cssExplicitAspectRatio};\n }\n\n const cssHeight = cssMatchedRulesGetter('height') || undefined;\n const cssWidth = cssMatchedRulesGetter('width') || undefined;\n return {height: cssHeight, width: cssWidth, aspectRatio: cssExplicitAspectRatio};\n }\n}\n\n/**\n * Given the requests that arrived within a 500ms window before the layout invalidation, returns the render\n * block requests of them.\n */\nfunction getRenderBlockRequestsInInvalidationWindow(requestsInInvalidationWindow: RootCauseRequest[]):\n RenderBlockingRequest[] {\n const renderBlockingRequests: RenderBlockingRequest[] = [];\n\n // Get all requests finished within the valid window.\n for (let i = 0; i < requestsInInvalidationWindow.length; i++) {\n const mainFrameId = requestsInInvalidationWindow[i].request.args.data.frame;\n if (!networkRequestIsRenderBlockingInFrame(requestsInInvalidationWindow[i].request, mainFrameId)) {\n continue;\n }\n renderBlockingRequests.push(requestsInInvalidationWindow[i] as RenderBlockingRequest);\n }\n return renderBlockingRequests;\n}\n\nfunction firstIframeInDOMTree(root: Protocol.DOM.Node): Protocol.DOM.Node|null {\n if (root.nodeName === 'IFRAME') {\n return root;\n }\n const children = root.children;\n if (!children) {\n return null;\n }\n for (const child of children) {\n const iFrameInChild = firstIframeInDOMTree(child);\n if (iFrameInChild) {\n return iFrameInChild;\n }\n }\n return null;\n}\n\nfunction cssPropertyIsExplicitlySet(propertyValue: string): boolean {\n return !['auto', 'initial', 'unset', 'inherit'].includes(propertyValue);\n}\n\nfunction htmlAttributeIsExplicit(attr: {value: string}): boolean {\n return parseInt(attr.value, 10) >= 0;\n}\n\nfunction computedStyleHasBackroundImage(computedStyle: Map<string, string>): boolean {\n const CSS_URL_REGEX = /^url\\(\"([^\"]+)\"\\)$/;\n const backgroundImage = computedStyle.get('background-image');\n if (!backgroundImage) {\n return false;\n }\n return CSS_URL_REGEX.test(backgroundImage);\n}\n\nfunction computedStyleHasFixedPosition(computedStyle: Map<string, string>): boolean {\n const position = computedStyle.get('position');\n if (!position) {\n return false;\n }\n return position === 'fixed' || position === 'absolute';\n}\n\nfunction getNodeComputedDimensions(computedStyle: Map<string, string>): CSSDimensions {\n const computedDimensions: CSSDimensions = {};\n computedDimensions.height = computedStyle.get('height');\n computedDimensions.width = computedStyle.get('width');\n computedDimensions.aspectRatio = computedStyle.get('aspect-ratio');\n return computedDimensions;\n}\n\n/**\n * Determines if a node is a media element and is not fixed positioned\n * (i.e. \"position: fixed;\" or \"position: absolute;\")\n */\nasync function nodeIsUnfixedMedia(node: Protocol.DOM.Node, computedStyle: Map<string, string>): Promise<boolean> {\n const localName = node.localName;\n const isBackgroundImage = computedStyleHasBackroundImage(computedStyle);\n if (localName !== 'img' && localName !== 'video' && !isBackgroundImage) {\n // Not a media element.\n return false;\n }\n const isFixed = computedStyleHasFixedPosition(computedStyle);\n return !isFixed;\n}\n\n/**\n * Determines if a CSS dimensions object explicitly defines both width and height\n * (i.e. not set to auto, inherit, etc.)\n */\nfunction dimensionsAreExplicit(dimensions: CSSDimensions): boolean {\n const {height, width, aspectRatio} = dimensions;\n\n const explicitHeight = Boolean(height && cssPropertyIsExplicitlySet(height));\n const explicitWidth = Boolean(width && cssPropertyIsExplicitlySet(width));\n const explicitAspectRatio = Boolean(aspectRatio && cssPropertyIsExplicitlySet(aspectRatio));\n\n const explicitWithAR = (explicitHeight || explicitWidth) && explicitAspectRatio;\n return (explicitHeight && explicitWidth) || explicitWithAR;\n}\n\n/**\n * Given an array of layout shift and PrePaint events, returns a mapping from\n * PrePaint events to layout shifts dispatched within it.\n */\nfunction getShiftsByPrePaintEvents(\n layoutShifts: Types.TraceEvents.TraceEventLayoutShift[],\n prePaintEvents: Types.TraceEvents.TraceEventPrePaint[],\n ): Map<Types.TraceEvents.TraceEventPrePaint, Types.TraceEvents.TraceEventLayoutShift[]> {\n // Maps from PrePaint events to LayoutShifts that occured in each one.\n const shiftsByPrePaint = new Map<Types.TraceEvents.TraceEventPrePaint, Types.TraceEvents.TraceEventLayoutShift[]>();\n\n // Associate all shifts to their corresponding PrePaint.\n for (const prePaintEvent of prePaintEvents) {\n const firstShiftIndex =\n Platform.ArrayUtilities.nearestIndexFromBeginning(layoutShifts, shift => shift.ts >= prePaintEvent.ts);\n if (firstShiftIndex === null) {\n // No layout shifts registered after this PrePaint start. Continue.\n continue;\n }\n for (let i = firstShiftIndex; i < layoutShifts.length; i++) {\n const shift = layoutShifts[i];\n if (shift.ts >= prePaintEvent.ts && shift.ts <= prePaintEvent.ts + prePaintEvent.dur) {\n const shiftsInPrePaint = Platform.MapUtilities.getWithDefault(shiftsByPrePaint, prePaintEvent, () => []);\n shiftsInPrePaint.push(shift);\n }\n if (shift.ts > prePaintEvent.ts + prePaintEvent.dur) {\n // Reached the end of this PrePaint. Continue to the next one.\n break;\n }\n }\n }\n return shiftsByPrePaint;\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type * as Protocol from '../../../generated/protocol.js';
2
+ import { LayoutShiftRootCauses } from './LayoutShift.js';
3
+ export type RootCauseProtocolInterface = {
4
+ getInitiatorForRequest(url: string): Protocol.Network.Initiator | null;
5
+ pushNodesByBackendIdsToFrontend(backendNodeIds: Protocol.DOM.BackendNodeId[]): Promise<Protocol.DOM.NodeId[]>;
6
+ getNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.DOM.Node>;
7
+ getComputedStyleForNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.CSS.CSSComputedStyleProperty[]>;
8
+ getMatchedStylesForNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.CSS.GetMatchedStylesForNodeResponse>;
9
+ fontFaceForSource(url: string): Protocol.CSS.FontFace | undefined;
10
+ };
11
+ export declare class RootCauses {
12
+ readonly layoutShifts: LayoutShiftRootCauses;
13
+ constructor(protocolInterface: RootCauseProtocolInterface);
14
+ }
@@ -0,0 +1,11 @@
1
+ // Copyright 2023 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 { LayoutShiftRootCauses } from './LayoutShift.js';
5
+ export class RootCauses {
6
+ layoutShifts;
7
+ constructor(protocolInterface) {
8
+ this.layoutShifts = new LayoutShiftRootCauses(protocolInterface);
9
+ }
10
+ }
11
+ //# sourceMappingURL=RootCauses.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RootCauses.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/root-causes/RootCauses.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAI7B,OAAO,EAAC,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AAWvD,MAAM,OAAO,UAAU;IACZ,YAAY,CAAwB;IAE7C,YAAY,iBAA6C;QACvD,IAAI,CAAC,YAAY,GAAG,IAAI,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;IACnE,CAAC;CACF","sourcesContent":["// Copyright 2023 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 Protocol from '../../../generated/protocol.js';\n\nimport {LayoutShiftRootCauses} from './LayoutShift.js';\n\nexport type RootCauseProtocolInterface = {\n getInitiatorForRequest(url: string): Protocol.Network.Initiator|null,\n pushNodesByBackendIdsToFrontend(backendNodeIds: Protocol.DOM.BackendNodeId[]): Promise<Protocol.DOM.NodeId[]>,\n getNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.DOM.Node>,\n getComputedStyleForNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.CSS.CSSComputedStyleProperty[]>,\n getMatchedStylesForNode(nodeId: Protocol.DOM.NodeId): Promise<Protocol.CSS.GetMatchedStylesForNodeResponse>,\n fontFaceForSource(url: string): Protocol.CSS.FontFace|undefined,\n};\n\nexport class RootCauses {\n readonly layoutShifts: LayoutShiftRootCauses;\n\n constructor(protocolInterface: RootCauseProtocolInterface) {\n this.layoutShifts = new LayoutShiftRootCauses(protocolInterface);\n }\n}\n"]}