devtools-tracing 1.0.0

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 (397) hide show
  1. package/generate.ts +643 -0
  2. package/index.ts +16 -0
  3. package/lib/front_end/core/common/App.ts +7 -0
  4. package/lib/front_end/core/common/AppProvider.ts +32 -0
  5. package/lib/front_end/core/common/Base64.ts +47 -0
  6. package/lib/front_end/core/common/CharacterIdMap.ts +30 -0
  7. package/lib/front_end/core/common/Color.ts +2506 -0
  8. package/lib/front_end/core/common/ColorConverter.ts +402 -0
  9. package/lib/front_end/core/common/ColorUtils.ts +252 -0
  10. package/lib/front_end/core/common/Console.ts +114 -0
  11. package/lib/front_end/core/common/Debouncer.ts +15 -0
  12. package/lib/front_end/core/common/EventTarget.ts +52 -0
  13. package/lib/front_end/core/common/Gzip.ts +74 -0
  14. package/lib/front_end/core/common/JavaScriptMetaData.ts +29 -0
  15. package/lib/front_end/core/common/Lazy.ts +31 -0
  16. package/lib/front_end/core/common/Linkifier.ts +55 -0
  17. package/lib/front_end/core/common/MapWithDefault.ts +26 -0
  18. package/lib/front_end/core/common/Mutex.ts +55 -0
  19. package/lib/front_end/core/common/Object.ts +145 -0
  20. package/lib/front_end/core/common/ParsedURL.ts +554 -0
  21. package/lib/front_end/core/common/Progress.ts +180 -0
  22. package/lib/front_end/core/common/QueryParamHandler.ts +7 -0
  23. package/lib/front_end/core/common/ResolverBase.ts +85 -0
  24. package/lib/front_end/core/common/ResourceType.ts +588 -0
  25. package/lib/front_end/core/common/ReturnToPanel.ts +17 -0
  26. package/lib/front_end/core/common/Revealer.ts +192 -0
  27. package/lib/front_end/core/common/Runnable.ts +41 -0
  28. package/lib/front_end/core/common/SegmentedRange.ts +87 -0
  29. package/lib/front_end/core/common/SettingRegistration.ts +339 -0
  30. package/lib/front_end/core/common/Settings.ts +1497 -0
  31. package/lib/front_end/core/common/SimpleHistoryManager.ts +124 -0
  32. package/lib/front_end/core/common/StringOutputStream.ts +26 -0
  33. package/lib/front_end/core/common/TextDictionary.ts +48 -0
  34. package/lib/front_end/core/common/Throttler.ts +99 -0
  35. package/lib/front_end/core/common/Trie.ts +152 -0
  36. package/lib/front_end/core/common/Worker.ts +60 -0
  37. package/lib/front_end/core/common/common.ts +81 -0
  38. package/lib/front_end/core/host/AidaClient.ts +733 -0
  39. package/lib/front_end/core/host/GdpClient.ts +316 -0
  40. package/lib/front_end/core/host/InspectorFrontendHost.ts +648 -0
  41. package/lib/front_end/core/host/InspectorFrontendHostAPI.ts +551 -0
  42. package/lib/front_end/core/host/Platform.ts +76 -0
  43. package/lib/front_end/core/host/ResourceLoader.ts +282 -0
  44. package/lib/front_end/core/host/UserMetrics.ts +1230 -0
  45. package/lib/front_end/core/host/host.ts +23 -0
  46. package/lib/front_end/core/i18n/ByteUtilities.ts +82 -0
  47. package/lib/front_end/core/i18n/DevToolsLocale.ts +87 -0
  48. package/lib/front_end/core/i18n/NumberFormatter.ts +82 -0
  49. package/lib/front_end/core/i18n/i18n.ts +17 -0
  50. package/lib/front_end/core/i18n/i18nImpl.ts +204 -0
  51. package/lib/front_end/core/i18n/i18nTypes.ts +10 -0
  52. package/lib/front_end/core/i18n/locales.js +14 -0
  53. package/lib/front_end/core/i18n/time-utilities.ts +174 -0
  54. package/lib/front_end/core/platform/ArrayUtilities.ts +271 -0
  55. package/lib/front_end/core/platform/Brand.ts +23 -0
  56. package/lib/front_end/core/platform/Constructor.ts +10 -0
  57. package/lib/front_end/core/platform/DOMUtilities.ts +138 -0
  58. package/lib/front_end/core/platform/DateUtilities.ts +15 -0
  59. package/lib/front_end/core/platform/DevToolsPath.ts +53 -0
  60. package/lib/front_end/core/platform/KeyboardUtilities.ts +38 -0
  61. package/lib/front_end/core/platform/MapUtilities.ts +95 -0
  62. package/lib/front_end/core/platform/MimeType.ts +175 -0
  63. package/lib/front_end/core/platform/NumberUtilities.ts +80 -0
  64. package/lib/front_end/core/platform/StringUtilities.ts +588 -0
  65. package/lib/front_end/core/platform/Timing.ts +17 -0
  66. package/lib/front_end/core/platform/TypedArrayUtilities.ts +189 -0
  67. package/lib/front_end/core/platform/TypescriptUtilities.ts +86 -0
  68. package/lib/front_end/core/platform/UIString.ts +39 -0
  69. package/lib/front_end/core/platform/UserVisibleError.ts +28 -0
  70. package/lib/front_end/core/platform/platform.ts +45 -0
  71. package/lib/front_end/core/protocol_client/ConnectionTransport.ts +26 -0
  72. package/lib/front_end/core/protocol_client/InspectorBackend.ts +1050 -0
  73. package/lib/front_end/core/protocol_client/NodeURL.ts +42 -0
  74. package/lib/front_end/core/protocol_client/protocol_client.ts +13 -0
  75. package/lib/front_end/core/root/Runtime.ts +609 -0
  76. package/lib/front_end/core/root/root.ts +6 -0
  77. package/lib/front_end/core/sdk/AccessibilityModel.ts +353 -0
  78. package/lib/front_end/core/sdk/AnimationModel.ts +1041 -0
  79. package/lib/front_end/core/sdk/AutofillModel.ts +184 -0
  80. package/lib/front_end/core/sdk/CPUProfilerModel.ts +148 -0
  81. package/lib/front_end/core/sdk/CPUThrottlingManager.ts +282 -0
  82. package/lib/front_end/core/sdk/CSSContainerQuery.ts +139 -0
  83. package/lib/front_end/core/sdk/CSSFontFace.ts +40 -0
  84. package/lib/front_end/core/sdk/CSSLayer.ts +30 -0
  85. package/lib/front_end/core/sdk/CSSMatchedStyles.ts +1646 -0
  86. package/lib/front_end/core/sdk/CSSMedia.ts +121 -0
  87. package/lib/front_end/core/sdk/CSSMetadata.ts +1647 -0
  88. package/lib/front_end/core/sdk/CSSModel.ts +1128 -0
  89. package/lib/front_end/core/sdk/CSSProperty.ts +384 -0
  90. package/lib/front_end/core/sdk/CSSPropertyParser.ts +681 -0
  91. package/lib/front_end/core/sdk/CSSPropertyParserMatchers.ts +1395 -0
  92. package/lib/front_end/core/sdk/CSSQuery.ts +72 -0
  93. package/lib/front_end/core/sdk/CSSRule.ts +465 -0
  94. package/lib/front_end/core/sdk/CSSScope.ts +30 -0
  95. package/lib/front_end/core/sdk/CSSStartingStyle.ts +29 -0
  96. package/lib/front_end/core/sdk/CSSStyleDeclaration.ts +313 -0
  97. package/lib/front_end/core/sdk/CSSStyleSheetHeader.ts +196 -0
  98. package/lib/front_end/core/sdk/CSSSupports.ts +33 -0
  99. package/lib/front_end/core/sdk/CategorizedBreakpoint.ts +64 -0
  100. package/lib/front_end/core/sdk/ChildTargetManager.ts +314 -0
  101. package/lib/front_end/core/sdk/CompilerSourceMappingContentProvider.ts +62 -0
  102. package/lib/front_end/core/sdk/Connections.ts +293 -0
  103. package/lib/front_end/core/sdk/ConsoleModel.ts +808 -0
  104. package/lib/front_end/core/sdk/ConsoleModelTypes.ts +15 -0
  105. package/lib/front_end/core/sdk/Cookie.ts +319 -0
  106. package/lib/front_end/core/sdk/CookieModel.ts +239 -0
  107. package/lib/front_end/core/sdk/CookieParser.ts +185 -0
  108. package/lib/front_end/core/sdk/DOMDebuggerModel.ts +787 -0
  109. package/lib/front_end/core/sdk/DOMModel.ts +1961 -0
  110. package/lib/front_end/core/sdk/DebuggerModel.ts +1605 -0
  111. package/lib/front_end/core/sdk/EmulationModel.ts +648 -0
  112. package/lib/front_end/core/sdk/EnhancedTracesParser.ts +515 -0
  113. package/lib/front_end/core/sdk/EventBreakpointsModel.ts +183 -0
  114. package/lib/front_end/core/sdk/FrameAssociated.ts +11 -0
  115. package/lib/front_end/core/sdk/FrameManager.ts +259 -0
  116. package/lib/front_end/core/sdk/HeapProfilerModel.ts +225 -0
  117. package/lib/front_end/core/sdk/HttpReasonPhraseStrings.ts +77 -0
  118. package/lib/front_end/core/sdk/IOModel.ts +91 -0
  119. package/lib/front_end/core/sdk/IsolateManager.ts +257 -0
  120. package/lib/front_end/core/sdk/IssuesModel.ts +70 -0
  121. package/lib/front_end/core/sdk/LayerTreeBase.ts +169 -0
  122. package/lib/front_end/core/sdk/LogModel.ts +56 -0
  123. package/lib/front_end/core/sdk/NetworkManager.ts +2823 -0
  124. package/lib/front_end/core/sdk/NetworkRequest.ts +2253 -0
  125. package/lib/front_end/core/sdk/OverlayColorGenerator.ts +52 -0
  126. package/lib/front_end/core/sdk/OverlayModel.ts +1011 -0
  127. package/lib/front_end/core/sdk/OverlayPersistentHighlighter.ts +522 -0
  128. package/lib/front_end/core/sdk/PageLoad.ts +35 -0
  129. package/lib/front_end/core/sdk/PageResourceLoader.ts +435 -0
  130. package/lib/front_end/core/sdk/PaintProfiler.ts +110 -0
  131. package/lib/front_end/core/sdk/PerformanceMetricsModel.ts +84 -0
  132. package/lib/front_end/core/sdk/PreloadingModel.ts +863 -0
  133. package/lib/front_end/core/sdk/RehydratingConnection.ts +386 -0
  134. package/lib/front_end/core/sdk/RehydratingObject.ts +66 -0
  135. package/lib/front_end/core/sdk/RemoteObject.ts +1160 -0
  136. package/lib/front_end/core/sdk/Resource.ts +232 -0
  137. package/lib/front_end/core/sdk/ResourceTreeModel.ts +1160 -0
  138. package/lib/front_end/core/sdk/RuntimeModel.ts +732 -0
  139. package/lib/front_end/core/sdk/SDKModel.ts +65 -0
  140. package/lib/front_end/core/sdk/ScopeTreeCache.ts +45 -0
  141. package/lib/front_end/core/sdk/ScreenCaptureModel.ts +255 -0
  142. package/lib/front_end/core/sdk/Script.ts +534 -0
  143. package/lib/front_end/core/sdk/SecurityOriginManager.ts +76 -0
  144. package/lib/front_end/core/sdk/ServerSentEvents.ts +80 -0
  145. package/lib/front_end/core/sdk/ServerSentEventsProtocol.ts +122 -0
  146. package/lib/front_end/core/sdk/ServerTiming.ts +260 -0
  147. package/lib/front_end/core/sdk/ServiceWorkerCacheModel.ts +377 -0
  148. package/lib/front_end/core/sdk/ServiceWorkerManager.ts +605 -0
  149. package/lib/front_end/core/sdk/SourceMap.ts +867 -0
  150. package/lib/front_end/core/sdk/SourceMapCache.ts +54 -0
  151. package/lib/front_end/core/sdk/SourceMapFunctionRanges.ts +156 -0
  152. package/lib/front_end/core/sdk/SourceMapManager.ts +239 -0
  153. package/lib/front_end/core/sdk/SourceMapScopeChainEntry.ts +189 -0
  154. package/lib/front_end/core/sdk/SourceMapScopesInfo.ts +508 -0
  155. package/lib/front_end/core/sdk/StorageBucketsModel.ts +204 -0
  156. package/lib/front_end/core/sdk/StorageKeyManager.ts +98 -0
  157. package/lib/front_end/core/sdk/Target.ts +332 -0
  158. package/lib/front_end/core/sdk/TargetManager.ts +453 -0
  159. package/lib/front_end/core/sdk/TraceObject.ts +61 -0
  160. package/lib/front_end/core/sdk/WebAuthnModel.ts +104 -0
  161. package/lib/front_end/core/sdk/sdk.ts +174 -0
  162. package/lib/front_end/entrypoints/formatter_worker/FormatterActions.ts +59 -0
  163. package/lib/front_end/generated/InspectorBackendCommands.js +1617 -0
  164. package/lib/front_end/generated/SupportedCSSProperties.js +7512 -0
  165. package/lib/front_end/generated/protocol-proxy-api.d.ts +5022 -0
  166. package/lib/front_end/generated/protocol.ts +22014 -0
  167. package/lib/front_end/models/cpu_profile/CPUProfileDataModel.ts +571 -0
  168. package/lib/front_end/models/cpu_profile/ProfileTreeModel.ts +103 -0
  169. package/lib/front_end/models/cpu_profile/cpu_profile.ts +11 -0
  170. package/lib/front_end/models/formatter/FormatterWorkerPool.ts +219 -0
  171. package/lib/front_end/models/formatter/ScriptFormatter.ts +112 -0
  172. package/lib/front_end/models/formatter/formatter.ts +8 -0
  173. package/lib/front_end/models/text_utils/CodeMirrorUtils.ts +37 -0
  174. package/lib/front_end/models/text_utils/ContentData.ts +199 -0
  175. package/lib/front_end/models/text_utils/ContentProvider.ts +68 -0
  176. package/lib/front_end/models/text_utils/StaticContentProvider.ts +49 -0
  177. package/lib/front_end/models/text_utils/StreamingContentData.ts +108 -0
  178. package/lib/front_end/models/text_utils/Text.ts +90 -0
  179. package/lib/front_end/models/text_utils/TextCursor.ts +44 -0
  180. package/lib/front_end/models/text_utils/TextRange.ts +266 -0
  181. package/lib/front_end/models/text_utils/TextUtils.ts +401 -0
  182. package/lib/front_end/models/text_utils/WasmDisassembly.ts +87 -0
  183. package/lib/front_end/models/text_utils/text_utils.ts +27 -0
  184. package/lib/front_end/models/trace/EntityMapper.ts +141 -0
  185. package/lib/front_end/models/trace/EventsSerializer.ts +101 -0
  186. package/lib/front_end/models/trace/LanternComputationData.ts +438 -0
  187. package/lib/front_end/models/trace/ModelImpl.ts +236 -0
  188. package/lib/front_end/models/trace/Name.ts +136 -0
  189. package/lib/front_end/models/trace/Processor.ts +652 -0
  190. package/lib/front_end/models/trace/Styles.ts +1138 -0
  191. package/lib/front_end/models/trace/extras/FilmStrip.ts +78 -0
  192. package/lib/front_end/models/trace/extras/MainThreadActivity.ts +86 -0
  193. package/lib/front_end/models/trace/extras/ScriptDuplication.ts +236 -0
  194. package/lib/front_end/models/trace/extras/StackTraceForEvent.ts +203 -0
  195. package/lib/front_end/models/trace/extras/ThirdParties.ts +164 -0
  196. package/lib/front_end/models/trace/extras/TraceFilter.ts +62 -0
  197. package/lib/front_end/models/trace/extras/TraceTree.ts +701 -0
  198. package/lib/front_end/models/trace/extras/extras.ts +11 -0
  199. package/lib/front_end/models/trace/handlers/AnimationFramesHandler.ts +128 -0
  200. package/lib/front_end/models/trace/handlers/AnimationHandler.ts +36 -0
  201. package/lib/front_end/models/trace/handlers/AsyncJSCallsHandler.ts +239 -0
  202. package/lib/front_end/models/trace/handlers/AuctionWorkletsHandler.ts +183 -0
  203. package/lib/front_end/models/trace/handlers/DOMStatsHandler.ts +31 -0
  204. package/lib/front_end/models/trace/handlers/ExtensionTraceDataHandler.ts +306 -0
  205. package/lib/front_end/models/trace/handlers/FlowsHandler.ts +175 -0
  206. package/lib/front_end/models/trace/handlers/FramesHandler.ts +571 -0
  207. package/lib/front_end/models/trace/handlers/GPUHandler.ts +50 -0
  208. package/lib/front_end/models/trace/handlers/ImagePaintingHandler.ts +183 -0
  209. package/lib/front_end/models/trace/handlers/InitiatorsHandler.ts +193 -0
  210. package/lib/front_end/models/trace/handlers/InvalidationsHandler.ts +168 -0
  211. package/lib/front_end/models/trace/handlers/LargestImagePaintHandler.ts +109 -0
  212. package/lib/front_end/models/trace/handlers/LargestTextPaintHandler.ts +35 -0
  213. package/lib/front_end/models/trace/handlers/LayerTreeHandler.ts +123 -0
  214. package/lib/front_end/models/trace/handlers/LayoutShiftsHandler.ts +573 -0
  215. package/lib/front_end/models/trace/handlers/MemoryHandler.ts +31 -0
  216. package/lib/front_end/models/trace/handlers/MetaHandler.ts +525 -0
  217. package/lib/front_end/models/trace/handlers/ModelHandlers.ts +34 -0
  218. package/lib/front_end/models/trace/handlers/NetworkRequestsHandler.ts +672 -0
  219. package/lib/front_end/models/trace/handlers/PageFramesHandler.ts +52 -0
  220. package/lib/front_end/models/trace/handlers/PageLoadMetricsHandler.ts +460 -0
  221. package/lib/front_end/models/trace/handlers/RendererHandler.ts +428 -0
  222. package/lib/front_end/models/trace/handlers/SamplesHandler.ts +271 -0
  223. package/lib/front_end/models/trace/handlers/ScreenshotsHandler.ts +122 -0
  224. package/lib/front_end/models/trace/handlers/ScriptsHandler.ts +336 -0
  225. package/lib/front_end/models/trace/handlers/SelectorStatsHandler.ts +110 -0
  226. package/lib/front_end/models/trace/handlers/Threads.ts +139 -0
  227. package/lib/front_end/models/trace/handlers/UserInteractionsHandler.ts +400 -0
  228. package/lib/front_end/models/trace/handlers/UserTimingsHandler.ts +233 -0
  229. package/lib/front_end/models/trace/handlers/WarningsHandler.ts +162 -0
  230. package/lib/front_end/models/trace/handlers/WorkersHandler.ts +45 -0
  231. package/lib/front_end/models/trace/handlers/handlers.ts +8 -0
  232. package/lib/front_end/models/trace/handlers/helpers.ts +196 -0
  233. package/lib/front_end/models/trace/handlers/types.ts +75 -0
  234. package/lib/front_end/models/trace/helpers/Extensions.ts +54 -0
  235. package/lib/front_end/models/trace/helpers/Network.ts +129 -0
  236. package/lib/front_end/models/trace/helpers/SamplesIntegrator.ts +544 -0
  237. package/lib/front_end/models/trace/helpers/SyntheticEvents.ts +87 -0
  238. package/lib/front_end/models/trace/helpers/Timing.ts +248 -0
  239. package/lib/front_end/models/trace/helpers/Trace.ts +928 -0
  240. package/lib/front_end/models/trace/helpers/TreeHelpers.ts +320 -0
  241. package/lib/front_end/models/trace/helpers/helpers.ts +11 -0
  242. package/lib/front_end/models/trace/insights/CLSCulprits.ts +668 -0
  243. package/lib/front_end/models/trace/insights/Cache.ts +269 -0
  244. package/lib/front_end/models/trace/insights/Common.ts +453 -0
  245. package/lib/front_end/models/trace/insights/DOMSize.ts +223 -0
  246. package/lib/front_end/models/trace/insights/DocumentLatency.ts +319 -0
  247. package/lib/front_end/models/trace/insights/DuplicatedJavaScript.ts +126 -0
  248. package/lib/front_end/models/trace/insights/FontDisplay.ts +119 -0
  249. package/lib/front_end/models/trace/insights/ForcedReflow.ts +220 -0
  250. package/lib/front_end/models/trace/insights/INPBreakdown.ts +171 -0
  251. package/lib/front_end/models/trace/insights/ImageDelivery.ts +348 -0
  252. package/lib/front_end/models/trace/insights/LCPBreakdown.ts +268 -0
  253. package/lib/front_end/models/trace/insights/LCPDiscovery.ts +237 -0
  254. package/lib/front_end/models/trace/insights/LegacyJavaScript.ts +138 -0
  255. package/lib/front_end/models/trace/insights/Models.ts +22 -0
  256. package/lib/front_end/models/trace/insights/ModernHTTP.ts +257 -0
  257. package/lib/front_end/models/trace/insights/NetworkDependencyTree.ts +726 -0
  258. package/lib/front_end/models/trace/insights/RenderBlocking.ts +257 -0
  259. package/lib/front_end/models/trace/insights/SlowCSSSelector.ts +175 -0
  260. package/lib/front_end/models/trace/insights/Statistics.ts +101 -0
  261. package/lib/front_end/models/trace/insights/ThirdParties.ts +130 -0
  262. package/lib/front_end/models/trace/insights/Viewport.ts +138 -0
  263. package/lib/front_end/models/trace/insights/insights.ts +10 -0
  264. package/lib/front_end/models/trace/insights/types.ts +157 -0
  265. package/lib/front_end/models/trace/lantern/core/LanternError.ts +7 -0
  266. package/lib/front_end/models/trace/lantern/core/NetworkAnalyzer.ts +619 -0
  267. package/lib/front_end/models/trace/lantern/core/core.ts +6 -0
  268. package/lib/front_end/models/trace/lantern/graph/BaseNode.ts +345 -0
  269. package/lib/front_end/models/trace/lantern/graph/CPUNode.ts +80 -0
  270. package/lib/front_end/models/trace/lantern/graph/NetworkNode.ts +101 -0
  271. package/lib/front_end/models/trace/lantern/graph/PageDependencyGraph.ts +636 -0
  272. package/lib/front_end/models/trace/lantern/graph/graph.ts +8 -0
  273. package/lib/front_end/models/trace/lantern/lantern.ts +17 -0
  274. package/lib/front_end/models/trace/lantern/metrics/FirstContentfulPaint.ts +187 -0
  275. package/lib/front_end/models/trace/lantern/metrics/Interactive.ts +88 -0
  276. package/lib/front_end/models/trace/lantern/metrics/LargestContentfulPaint.ts +92 -0
  277. package/lib/front_end/models/trace/lantern/metrics/MaxPotentialFID.ts +72 -0
  278. package/lib/front_end/models/trace/lantern/metrics/Metric.ts +126 -0
  279. package/lib/front_end/models/trace/lantern/metrics/SpeedIndex.ts +126 -0
  280. package/lib/front_end/models/trace/lantern/metrics/TBTUtils.ts +82 -0
  281. package/lib/front_end/models/trace/lantern/metrics/TotalBlockingTime.ts +112 -0
  282. package/lib/front_end/models/trace/lantern/metrics/metrics.ts +12 -0
  283. package/lib/front_end/models/trace/lantern/simulation/ConnectionPool.ts +150 -0
  284. package/lib/front_end/models/trace/lantern/simulation/Constants.ts +46 -0
  285. package/lib/front_end/models/trace/lantern/simulation/DNSCache.ts +61 -0
  286. package/lib/front_end/models/trace/lantern/simulation/SimulationTimingMap.ts +196 -0
  287. package/lib/front_end/models/trace/lantern/simulation/Simulator.ts +556 -0
  288. package/lib/front_end/models/trace/lantern/simulation/TCPConnection.ts +192 -0
  289. package/lib/front_end/models/trace/lantern/simulation/simulation.ts +10 -0
  290. package/lib/front_end/models/trace/lantern/types/Lantern.ts +220 -0
  291. package/lib/front_end/models/trace/lantern/types/types.ts +5 -0
  292. package/lib/front_end/models/trace/trace.ts +33 -0
  293. package/lib/front_end/models/trace/types/Configuration.ts +110 -0
  294. package/lib/front_end/models/trace/types/Extensions.ts +136 -0
  295. package/lib/front_end/models/trace/types/File.ts +281 -0
  296. package/lib/front_end/models/trace/types/Overlays.ts +138 -0
  297. package/lib/front_end/models/trace/types/Timing.ts +30 -0
  298. package/lib/front_end/models/trace/types/TraceEvents.ts +3277 -0
  299. package/lib/front_end/models/trace/types/types.ts +10 -0
  300. package/lib/front_end/third_party/i18n/LICENSE +202 -0
  301. package/lib/front_end/third_party/i18n/README.chromium +15 -0
  302. package/lib/front_end/third_party/i18n/i18n-impl.ts +61 -0
  303. package/lib/front_end/third_party/i18n/i18n.ts +11 -0
  304. package/lib/front_end/third_party/i18n/localized-string-set.ts +129 -0
  305. package/lib/front_end/third_party/intl-messageformat/LICENSE +33 -0
  306. package/lib/front_end/third_party/intl-messageformat/README.chromium +24 -0
  307. package/lib/front_end/third_party/intl-messageformat/intl-messageformat-tsconfig.json +16 -0
  308. package/lib/front_end/third_party/intl-messageformat/intl-messageformat.ts +6 -0
  309. package/lib/front_end/third_party/intl-messageformat/package/LICENSE.md +33 -0
  310. package/lib/front_end/third_party/intl-messageformat/package/README.md +3 -0
  311. package/lib/front_end/third_party/intl-messageformat/package/index.d.ts +6 -0
  312. package/lib/front_end/third_party/intl-messageformat/package/index.d.ts.map +1 -0
  313. package/lib/front_end/third_party/intl-messageformat/package/index.js +13 -0
  314. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.d.ts +5 -0
  315. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.esm.js +1710 -0
  316. package/lib/front_end/third_party/intl-messageformat/package/intl-messageformat.iife.js +1815 -0
  317. package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts +6 -0
  318. package/lib/front_end/third_party/intl-messageformat/package/lib/index.d.ts.map +1 -0
  319. package/lib/front_end/third_party/intl-messageformat/package/lib/index.js +10 -0
  320. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts +34 -0
  321. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.d.ts.map +1 -0
  322. package/lib/front_end/third_party/intl-messageformat/package/lib/src/core.js +229 -0
  323. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts +28 -0
  324. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.d.ts.map +1 -0
  325. package/lib/front_end/third_party/intl-messageformat/package/lib/src/error.js +48 -0
  326. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts +34 -0
  327. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.d.ts.map +1 -0
  328. package/lib/front_end/third_party/intl-messageformat/package/lib/src/formatters.js +179 -0
  329. package/lib/front_end/third_party/intl-messageformat/package/package.json +42 -0
  330. package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts +34 -0
  331. package/lib/front_end/third_party/intl-messageformat/package/src/core.d.ts.map +1 -0
  332. package/lib/front_end/third_party/intl-messageformat/package/src/core.js +230 -0
  333. package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts +28 -0
  334. package/lib/front_end/third_party/intl-messageformat/package/src/error.d.ts.map +1 -0
  335. package/lib/front_end/third_party/intl-messageformat/package/src/error.js +51 -0
  336. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts +34 -0
  337. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.d.ts.map +1 -0
  338. package/lib/front_end/third_party/intl-messageformat/package/src/formatters.js +182 -0
  339. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/error.d.ts +79 -0
  340. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/index.d.ts +15 -0
  341. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/parser.d.ts +153 -0
  342. package/lib/front_end/third_party/intl-messageformat/package/src/icu-messageformat-parser/types.d.ts +139 -0
  343. package/lib/front_end/third_party/legacy-javascript/LICENSE +202 -0
  344. package/lib/front_end/third_party/legacy-javascript/README.chromium +13 -0
  345. package/lib/front_end/third_party/legacy-javascript/legacy-javascript-tsconfig.json +8 -0
  346. package/lib/front_end/third_party/legacy-javascript/legacy-javascript.ts +3 -0
  347. package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.d.ts +18 -0
  348. package/lib/front_end/third_party/legacy-javascript/lib/legacy-javascript.js +943 -0
  349. package/lib/front_end/third_party/legacy-javascript/package.json +8 -0
  350. package/lib/front_end/third_party/legacy-javascript/rebuild.sh +9 -0
  351. package/lib/front_end/third_party/third-party-web/LICENSE +20 -0
  352. package/lib/front_end/third_party/third-party-web/README.chromium +13 -0
  353. package/lib/front_end/third_party/third-party-web/lib/nostats-subset.d.ts +2 -0
  354. package/lib/front_end/third_party/third-party-web/lib/nostats-subset.js +149 -0
  355. package/lib/front_end/third_party/third-party-web/package/LICENSE +20 -0
  356. package/lib/front_end/third_party/third-party-web/package/README.md +929 -0
  357. package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive-nostats.json +1 -0
  358. package/lib/front_end/third_party/third-party-web/package/dist/entities-httparchive.json +1 -0
  359. package/lib/front_end/third_party/third-party-web/package/dist/entities-nostats.json +1 -0
  360. package/lib/front_end/third_party/third-party-web/package/dist/entities.json +1 -0
  361. package/lib/front_end/third_party/third-party-web/package/facades.md +46 -0
  362. package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.d.ts +1 -0
  363. package/lib/front_end/third_party/third-party-web/package/httparchive-nostats-subset.js +1 -0
  364. package/lib/front_end/third_party/third-party-web/package/httparchive-subset.d.ts +1 -0
  365. package/lib/front_end/third_party/third-party-web/package/httparchive-subset.js +1 -0
  366. package/lib/front_end/third_party/third-party-web/package/lib/__snapshots__/index.test.js.snap +1006 -0
  367. package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.js +139 -0
  368. package/lib/front_end/third_party/third-party-web/package/lib/create-entity-finder-api.test.js +44 -0
  369. package/lib/front_end/third_party/third-party-web/package/lib/entities.test.js +27 -0
  370. package/lib/front_end/third_party/third-party-web/package/lib/index.d.ts +34 -0
  371. package/lib/front_end/third_party/third-party-web/package/lib/index.js +3 -0
  372. package/lib/front_end/third_party/third-party-web/package/lib/index.test.js +246 -0
  373. package/lib/front_end/third_party/third-party-web/package/lib/markdown/faqs.partial.md +36 -0
  374. package/lib/front_end/third_party/third-party-web/package/lib/markdown/goals.partial.md +9 -0
  375. package/lib/front_end/third_party/third-party-web/package/lib/markdown/methodology.partial.md +5 -0
  376. package/lib/front_end/third_party/third-party-web/package/lib/markdown/template.md +151 -0
  377. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-02-01.md +1 -0
  378. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-03-01.md +1 -0
  379. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-06.md +1 -0
  380. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2019-05-13.md +14 -0
  381. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2021-01-01.md +1 -0
  382. package/lib/front_end/third_party/third-party-web/package/lib/markdown/updates/2024-07-01.md +3 -0
  383. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.d.ts +1 -0
  384. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive-nostats.js +3 -0
  385. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.d.ts +1 -0
  386. package/lib/front_end/third_party/third-party-web/package/lib/subsets/httparchive.js +3 -0
  387. package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.d.ts +1 -0
  388. package/lib/front_end/third_party/third-party-web/package/lib/subsets/nostats.js +3 -0
  389. package/lib/front_end/third_party/third-party-web/package/nostats-subset.d.ts +1 -0
  390. package/lib/front_end/third_party/third-party-web/package/nostats-subset.js +1 -0
  391. package/lib/front_end/third_party/third-party-web/package/package.json +46 -0
  392. package/lib/front_end/third_party/third-party-web/package.json +8 -0
  393. package/lib/front_end/third_party/third-party-web/rebuild.sh +13 -0
  394. package/lib/front_end/third_party/third-party-web/third-party-web-tsconfig.json +8 -0
  395. package/lib/front_end/third_party/third-party-web/third-party-web.ts +3 -0
  396. package/package.json +24 -0
  397. package/patches/chrome-devtools-frontend+1.0.1533544.patch +187 -0
@@ -0,0 +1,78 @@
1
+ // Copyright 2023 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ //
5
+ import * as Platform from '../../../core/platform/platform.js';
6
+ import type * as Handlers from '../handlers/handlers.js';
7
+ import type * as Types from '../types/types.js';
8
+
9
+ export interface Data {
10
+ zeroTime: Types.Timing.Micro;
11
+ spanTime: Types.Timing.Micro;
12
+ frames: readonly Frame[];
13
+ }
14
+
15
+ export interface Frame {
16
+ screenshotEvent: Types.Events.LegacySyntheticScreenshot|Types.Events.Screenshot;
17
+ index: number;
18
+ }
19
+
20
+ export type HandlersWithFilmStrip = Handlers.Types.HandlersWithMeta<{
21
+ // eslint-disable-next-line @typescript-eslint/naming-convention
22
+ Screenshots: typeof Handlers.ModelHandlers.Screenshots,
23
+ }>;
24
+
25
+ export type HandlerDataWithScreenshots = Handlers.Types.EnabledHandlerDataWithMeta<{
26
+ // eslint-disable-next-line @typescript-eslint/naming-convention
27
+ Screenshots: typeof Handlers.ModelHandlers.Screenshots,
28
+ }>;
29
+
30
+ // Cache film strips based on:
31
+ // 1. The trace parsed data object
32
+ // 2. The start time.
33
+ const filmStripCache = new WeakMap<HandlerDataWithScreenshots, Map<Types.Timing.Micro, Data>>();
34
+
35
+ export function fromHandlerData(data: HandlerDataWithScreenshots, customZeroTime?: Types.Timing.Micro): Data {
36
+ const frames: Frame[] = [];
37
+
38
+ const zeroTime = typeof customZeroTime !== 'undefined' ? customZeroTime : data.Meta.traceBounds.min;
39
+ const spanTime = data.Meta.traceBounds.range;
40
+ const fromCache = filmStripCache.get(data)?.get(zeroTime);
41
+ if (fromCache) {
42
+ return fromCache;
43
+ }
44
+
45
+ const screenshots = data.Screenshots.screenshots ?? data.Screenshots.legacySyntheticScreenshots ?? [];
46
+
47
+ for (const screenshotEvent of screenshots) {
48
+ if (screenshotEvent.ts < zeroTime) {
49
+ continue;
50
+ }
51
+ const frame: Frame = {
52
+ index: frames.length,
53
+ screenshotEvent,
54
+ };
55
+ frames.push(frame);
56
+ }
57
+
58
+ const result: Data = {
59
+ zeroTime,
60
+ spanTime,
61
+ frames: Array.from(frames),
62
+ };
63
+
64
+ const cachedForData =
65
+ Platform.MapUtilities.getWithDefault(filmStripCache, data, () => new Map<Types.Timing.Micro, Data>());
66
+ cachedForData.set(zeroTime, result);
67
+
68
+ return result;
69
+ }
70
+
71
+ export function frameClosestToTimestamp(filmStrip: Data, searchTimestamp: Types.Timing.Micro): Frame|null {
72
+ const closestFrameIndexBeforeTimestamp = Platform.ArrayUtilities.nearestIndexFromEnd(
73
+ filmStrip.frames, frame => frame.screenshotEvent.ts < searchTimestamp);
74
+ if (closestFrameIndexBeforeTimestamp === null) {
75
+ return null;
76
+ }
77
+ return filmStrip.frames[closestFrameIndexBeforeTimestamp];
78
+ }
@@ -0,0 +1,86 @@
1
+ // Copyright 2023 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+ import * as Helpers from '../helpers/helpers.js';
5
+ import * as Types from '../types/types.js';
6
+
7
+ const IDLE_FUNCTION_CALL_NAMES = new Set([
8
+ '(program)',
9
+ '(idle)',
10
+ '(root)',
11
+ ]);
12
+
13
+ export function calculateWindow(
14
+ traceBounds: Types.Timing.TraceWindowMicro,
15
+ mainThreadEntries: readonly Types.Events.Event[]): Types.Timing.TraceWindowMicro {
16
+ if (!mainThreadEntries.length) {
17
+ return traceBounds;
18
+ }
19
+ const entriesWithIdleRemoved = mainThreadEntries.filter(entry => {
20
+ if (Types.Events.isProfileCall(entry) &&
21
+ (IDLE_FUNCTION_CALL_NAMES.has(entry.callFrame.functionName) || !entry.callFrame.functionName)) {
22
+ return false;
23
+ }
24
+ return true;
25
+ });
26
+
27
+ if (entriesWithIdleRemoved.length === 0) {
28
+ return traceBounds;
29
+ }
30
+ /**
31
+ * Calculates regions of low utilization and returns the index of the event
32
+ * that is the first event that should be included.
33
+ **/
34
+ function findLowUtilizationRegion(startIndex: number, stopIndex: number): number {
35
+ const threshold = 0.1;
36
+
37
+ let cutIndex = startIndex;
38
+ const entryAtCut = entriesWithIdleRemoved[cutIndex];
39
+ const timings = Helpers.Timing.eventTimingsMicroSeconds(entryAtCut);
40
+ let cutTime = (timings.startTime + timings.endTime) / 2;
41
+ let usedTime = 0;
42
+ const step = Math.sign(stopIndex - startIndex);
43
+ for (let i = startIndex; i !== stopIndex; i += step) {
44
+ const task = entriesWithIdleRemoved[i];
45
+ const taskTimings = Helpers.Timing.eventTimingsMicroSeconds(task);
46
+ const taskTime = (taskTimings.startTime + taskTimings.endTime) / 2;
47
+ const interval = Math.abs(cutTime - taskTime);
48
+ if (usedTime < threshold * interval) {
49
+ cutIndex = i;
50
+ cutTime = taskTime;
51
+ usedTime = 0;
52
+ }
53
+ usedTime += taskTimings.duration;
54
+ }
55
+ return cutIndex;
56
+ }
57
+ const rightIndex = findLowUtilizationRegion(entriesWithIdleRemoved.length - 1, 0);
58
+ const leftIndex = findLowUtilizationRegion(0, rightIndex);
59
+ const leftTimings = Helpers.Timing.eventTimingsMicroSeconds(entriesWithIdleRemoved[leftIndex]);
60
+ const rightTimings = Helpers.Timing.eventTimingsMicroSeconds(entriesWithIdleRemoved[rightIndex]);
61
+
62
+ let leftTime = leftTimings.startTime;
63
+ let rightTime = rightTimings.endTime;
64
+ const zoomedInSpan = rightTime - leftTime;
65
+
66
+ if (zoomedInSpan < traceBounds.range * 0.1) {
67
+ // If the area we have chosen to zoom into is less than 10% of the entire
68
+ // span, we bail and show the entire trace. It would not be so useful to
69
+ // the user to zoom in on such a small area; we assume they have
70
+ // purposefully recorded a trace that contains empty periods of time.
71
+ return traceBounds;
72
+ }
73
+
74
+ // Adjust the left time down by 5%, and the right time up by 5%, so that
75
+ // we give the range we want to zoom a bit of breathing space. At the
76
+ // same time, ensure that we do not stray beyond the bounds of the
77
+ // min/max time of the entire trace.
78
+ leftTime = Types.Timing.Micro(Math.max(leftTime - 0.05 * zoomedInSpan, traceBounds.min));
79
+ rightTime = Types.Timing.Micro(Math.min(rightTime + 0.05 * zoomedInSpan, traceBounds.max));
80
+
81
+ return {
82
+ min: leftTime,
83
+ max: rightTime,
84
+ range: Types.Timing.Micro(rightTime - leftTime),
85
+ };
86
+ }
@@ -0,0 +1,236 @@
1
+ // Copyright 2025 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Handlers from '../handlers/handlers.js';
6
+
7
+ // Ignore modules smaller than an absolute threshold.
8
+ const ABSOLUTE_SIZE_THRESHOLD_BYTES = 1024 * 0.5;
9
+ // Ignore modules smaller than a % size of largest copy of the module.
10
+ const RELATIVE_SIZE_THRESHOLD = 0.1;
11
+
12
+ interface SourceData {
13
+ source: string;
14
+ resourceSize: number;
15
+ }
16
+
17
+ export function normalizeSource(source: string): string {
18
+ // Trim trailing question mark - b/c webpack.
19
+ source = source.replace(/\?$/, '');
20
+
21
+ // Normalize paths for dependencies by only keeping everything after the last `node_modules`.
22
+ const lastNodeModulesIndex = source.lastIndexOf('node_modules');
23
+ if (lastNodeModulesIndex !== -1) {
24
+ source = source.substring(lastNodeModulesIndex);
25
+ }
26
+
27
+ return source;
28
+ }
29
+
30
+ function shouldIgnoreSource(source: string): boolean {
31
+ // Ignore bundle overhead.
32
+ if (source.includes('webpack/bootstrap')) {
33
+ return true;
34
+ }
35
+ if (source.includes('(webpack)/buildin')) {
36
+ return true;
37
+ }
38
+
39
+ // Ignore webpack module shims, i.e. aliases of the form `module.exports = window.jQuery`
40
+ if (source.includes('external ')) {
41
+ return true;
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ /**
48
+ * The key is a source map `sources` entry (these are URLs/file paths), but normalized
49
+ * via `normalizeSource`.
50
+ *
51
+ * The value is an object with an entry for every script that has a source map which
52
+ * denotes that this source was used, along with the estimated resource size it takes
53
+ * up in the script.
54
+ */
55
+ export type ScriptDuplication = Map<string, {
56
+ /**
57
+ * This is the sum of all (but one) `attributedSize` in `scripts`.
58
+ *
59
+ * One copy of this module is treated as the canonical version - the rest will
60
+ * have non-zero `wastedBytes`. The canonical copy is the first entry of
61
+ * `scripts`.
62
+ *
63
+ * In the case of all copies being the same version, all sizes are
64
+ * equal and the selection doesn't matter (ignoring compression ratios). When
65
+ * the copies are different versions, it does matter. Ideally the newest
66
+ * version would be the canonical copy, but version information is not present.
67
+ * Instead, size is used as a heuristic for latest version. This makes the
68
+ * value here conserative in its estimation.
69
+ */
70
+ estimatedDuplicateBytes: number,
71
+ duplicates: Array<{
72
+ script: Handlers.ModelHandlers.Scripts.Script,
73
+ /**
74
+ * The number of bytes in the script bundle that map back to this module,
75
+ * in terms of estimated impact on transfer size.
76
+ */
77
+ attributedSize: number,
78
+ }>,
79
+ }>;
80
+
81
+ /**
82
+ * Sorts each array within @see ScriptDuplication by attributedSize, drops information
83
+ * on sources that are too small, and calculates esimatedDuplicateBytes.
84
+ */
85
+ export function normalizeDuplication(duplication: ScriptDuplication): void {
86
+ for (const [key, data] of duplication) {
87
+ // Sort by resource size.
88
+ data.duplicates.sort((a, b) => b.attributedSize - a.attributedSize);
89
+
90
+ // Ignore modules smaller than a % size of largest.
91
+ if (data.duplicates.length > 1) {
92
+ const largestResourceSize = data.duplicates[0].attributedSize;
93
+ data.duplicates = data.duplicates.filter(duplicate => {
94
+ const percentSize = duplicate.attributedSize / largestResourceSize;
95
+ return percentSize >= RELATIVE_SIZE_THRESHOLD;
96
+ });
97
+ }
98
+
99
+ // Ignore modules smaller than an absolute threshold.
100
+ data.duplicates = data.duplicates.filter(duplicate => duplicate.attributedSize >= ABSOLUTE_SIZE_THRESHOLD_BYTES);
101
+
102
+ // Delete any that now don't have multiple entries.
103
+ if (data.duplicates.length <= 1) {
104
+ duplication.delete(key);
105
+ continue;
106
+ }
107
+
108
+ data.estimatedDuplicateBytes = data.duplicates.slice(1).reduce((acc, cur) => acc + cur.attributedSize, 0);
109
+ }
110
+ }
111
+
112
+ function indexOfOrLength(haystack: string, needle: string, startPosition = 0): number {
113
+ const index = haystack.indexOf(needle, startPosition);
114
+ return index === -1 ? haystack.length : index;
115
+ }
116
+
117
+ export function getNodeModuleName(source: string): string {
118
+ const sourceSplit = source.split('node_modules/');
119
+ source = sourceSplit[sourceSplit.length - 1];
120
+
121
+ const indexFirstSlash = indexOfOrLength(source, '/');
122
+ if (source[0] === '@') {
123
+ return source.slice(0, indexOfOrLength(source, '/', indexFirstSlash + 1));
124
+ }
125
+
126
+ return source.slice(0, indexFirstSlash);
127
+ }
128
+
129
+ function groupByNodeModules(duplication: ScriptDuplication): ScriptDuplication {
130
+ const groupedDuplication: ScriptDuplication = new Map();
131
+ for (const [source, data] of duplication) {
132
+ if (!source.includes('node_modules')) {
133
+ groupedDuplication.set(source, data);
134
+ continue;
135
+ }
136
+
137
+ const nodeModuleKey = 'node_modules/' + getNodeModuleName(source);
138
+ const aggregatedData = groupedDuplication.get(nodeModuleKey) ?? {
139
+ duplicates: [],
140
+ // This is calculated in normalizeDuplication.
141
+ estimatedDuplicateBytes: 0,
142
+ };
143
+ groupedDuplication.set(nodeModuleKey, aggregatedData);
144
+
145
+ for (const {script, attributedSize} of data.duplicates) {
146
+ let duplicate = aggregatedData.duplicates.find(d => d.script === script);
147
+ if (!duplicate) {
148
+ duplicate = {script, attributedSize: 0};
149
+ aggregatedData.duplicates.push(duplicate);
150
+ }
151
+ duplicate.attributedSize += attributedSize;
152
+ }
153
+ }
154
+
155
+ return groupedDuplication;
156
+ }
157
+
158
+ /**
159
+ * Sort by estimated savings.
160
+ */
161
+ function sorted(duplication: ScriptDuplication): ScriptDuplication {
162
+ return new Map([...duplication].sort((a, b) => b[1].estimatedDuplicateBytes - a[1].estimatedDuplicateBytes));
163
+ }
164
+
165
+ /**
166
+ * Returns 2 @see ScriptDuplication for the given collection of script contents + source maps:
167
+ *
168
+ * 1. `duplication` keys correspond to authored files
169
+ * 2. `duplication` keys correspond to authored files, except all files within the same
170
+ * node_module package are aggregated under the same entry.
171
+ */
172
+ export function computeScriptDuplication(
173
+ scriptsData: Handlers.ModelHandlers.Scripts.ScriptsData, compressionRatios: Map<string, number>):
174
+ {duplication: ScriptDuplication, duplicationGroupedByNodeModules: ScriptDuplication} {
175
+ const sourceDatasMap = new Map<Handlers.ModelHandlers.Scripts.Script, SourceData[]>();
176
+
177
+ // Determine size of each `sources` entry.
178
+ for (const script of scriptsData.scripts) {
179
+ if (!script.content || !script.sourceMap) {
180
+ continue;
181
+ }
182
+
183
+ const sizes = Handlers.ModelHandlers.Scripts.getScriptGeneratedSizes(script);
184
+ if (!sizes) {
185
+ continue;
186
+ }
187
+
188
+ if ('errorMessage' in sizes) {
189
+ console.error(sizes.errorMessage);
190
+ continue;
191
+ }
192
+
193
+ const sourceDataArray: SourceData[] = [];
194
+ sourceDatasMap.set(script, sourceDataArray);
195
+
196
+ const sources = script.sourceMap.sourceURLs();
197
+ for (let i = 0; i < sources.length; i++) {
198
+ if (shouldIgnoreSource(sources[i])) {
199
+ continue;
200
+ }
201
+
202
+ const sourceSize = sizes.files[sources[i]];
203
+ sourceDataArray.push({
204
+ source: normalizeSource(sources[i]),
205
+ resourceSize: sourceSize,
206
+ });
207
+ }
208
+ }
209
+
210
+ const duplication: ScriptDuplication = new Map();
211
+ for (const [script, sourceDataArray] of sourceDatasMap) {
212
+ for (const sourceData of sourceDataArray) {
213
+ let data = duplication.get(sourceData.source);
214
+ if (!data) {
215
+ data = {estimatedDuplicateBytes: 0, duplicates: []};
216
+ duplication.set(sourceData.source, data);
217
+ }
218
+ const compressionRatio = script.request ? compressionRatios.get(script.request?.args.data.requestId) ?? 1 : 1;
219
+ const transferSize = Math.round(sourceData.resourceSize * compressionRatio);
220
+ data.duplicates.push({
221
+ script,
222
+ attributedSize: transferSize,
223
+ });
224
+ }
225
+ }
226
+
227
+ const duplicationGroupedByNodeModules = groupByNodeModules(duplication);
228
+
229
+ normalizeDuplication(duplication);
230
+ normalizeDuplication(duplicationGroupedByNodeModules);
231
+
232
+ return {
233
+ duplication: sorted(duplication),
234
+ duplicationGroupedByNodeModules: sorted(duplicationGroupedByNodeModules),
235
+ };
236
+ }
@@ -0,0 +1,203 @@
1
+ // Copyright 2024 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import type * as Protocol from '../../../generated/protocol.js';
6
+ import type * as Handlers from '../handlers/handlers.js';
7
+ import * as Helpers from '../helpers/helpers.js';
8
+ import * as Types from '../types/types.js';
9
+
10
+ export const stackTraceForEventInTrace =
11
+ new Map<Handlers.Types.HandlerData, Map<Types.Events.Event, Protocol.Runtime.StackTrace>>();
12
+
13
+ export function clearCacheForTrace(data: Handlers.Types.HandlerData): void {
14
+ stackTraceForEventInTrace.delete(data);
15
+ }
16
+ /**
17
+ * This util builds a stack trace that includes async calls for a given
18
+ * event. It leverages data we collect from sampling to deduce sync
19
+ * stacks and trace event instrumentation on the V8 debugger to stitch
20
+ * them together.
21
+ */
22
+ export function get(event: Types.Events.Event, data: Handlers.Types.HandlerData): Protocol.Runtime.StackTrace|null {
23
+ let cacheForTrace = stackTraceForEventInTrace.get(data);
24
+ if (!cacheForTrace) {
25
+ cacheForTrace = new Map();
26
+ stackTraceForEventInTrace.set(data, cacheForTrace);
27
+ }
28
+ const resultFromCache = cacheForTrace.get(event);
29
+ if (resultFromCache) {
30
+ return resultFromCache;
31
+ }
32
+ let result: Protocol.Runtime.StackTrace|null = null;
33
+ if (Types.Extensions.isSyntheticExtensionEntry(event)) {
34
+ result = getForExtensionEntry(event, data);
35
+ } else if (Types.Events.isPerformanceMeasureBegin(event)) {
36
+ result = getForPerformanceMeasure(event, data);
37
+ } else {
38
+ result = getForEvent(event, data);
39
+ const payloadCallFrames =
40
+ getTraceEventPayloadStackAsProtocolCallFrame(event).filter(callFrame => !isNativeJSFunction(callFrame));
41
+ // If the event has a payload stack trace, replace the synchronous
42
+ // portion of the calculated stack with the payload's call frames.
43
+ // We do this because trace payload call frames contain call
44
+ // locations, unlike profile call frames obtained with getForEvent
45
+ // (which contain function declaration locations).
46
+ // This way the user knows which exact JS location triggered an
47
+ // event.
48
+ if (!result.callFrames.length) {
49
+ result.callFrames = payloadCallFrames;
50
+ } else {
51
+ for (let i = 0; i < payloadCallFrames.length && i < result.callFrames.length; i++) {
52
+ result.callFrames[i] = payloadCallFrames[i];
53
+ }
54
+ }
55
+ }
56
+ if (result) {
57
+ cacheForTrace.set(event, result);
58
+ }
59
+ return result;
60
+ }
61
+
62
+ /**
63
+ * Fallback method to obtain a stack trace using the parsed event tree
64
+ * hierarchy. This shouldn't be called outside of this file, use `get`
65
+ * instead to ensure the correct event in the tree hierarchy is used.
66
+ */
67
+ function getForEvent(event: Types.Events.Event, data: Handlers.Types.HandlerData): Protocol.Runtime.StackTrace {
68
+ // When working with a CPU profile the renderer handler won't have
69
+ // entries in its tree.
70
+ const entryToNode = data.Renderer.entryToNode.size > 0 ? data.Renderer.entryToNode : data.Samples.entryToNode;
71
+ const topStackTrace: Protocol.Runtime.StackTrace = {callFrames: []};
72
+ let stackTrace: Protocol.Runtime.StackTrace = topStackTrace;
73
+ let currentEntry: Types.Events.SyntheticProfileCall;
74
+ let node: Helpers.TreeHelpers.TraceEntryNode|null|undefined = entryToNode.get(event);
75
+ const traceCache = stackTraceForEventInTrace.get(data) || new Map<Types.Events.Event, Protocol.Runtime.StackTrace>();
76
+ stackTraceForEventInTrace.set(data, traceCache);
77
+ // Move up this node's ancestor tree appending JS frames to its
78
+ // stack trace. If an async caller is detected, move up in the async
79
+ // stack instead.
80
+ while (node) {
81
+ if (!Types.Events.isProfileCall(node.entry)) {
82
+ const maybeAsyncParent = data.AsyncJSCalls.runEntryPointToScheduler.get(node.entry);
83
+ if (!maybeAsyncParent) {
84
+ node = node.parent;
85
+ continue;
86
+ }
87
+ const maybeAsyncParentNode = maybeAsyncParent && entryToNode.get(maybeAsyncParent.scheduler);
88
+ if (maybeAsyncParentNode) {
89
+ stackTrace = addAsyncParentToStack(stackTrace, maybeAsyncParent.taskName);
90
+ node = maybeAsyncParentNode;
91
+ }
92
+ continue;
93
+ }
94
+ currentEntry = node.entry;
95
+ // First check if this entry was processed before.
96
+ const stackTraceFromCache = traceCache.get(node.entry);
97
+ if (stackTraceFromCache) {
98
+ stackTrace.callFrames.push(...stackTraceFromCache.callFrames.filter(callFrame => !isNativeJSFunction(callFrame)));
99
+ stackTrace.parent = stackTraceFromCache.parent;
100
+ // Only set the description to the cache value if we didn't
101
+ // compute it in the previous iteration, since the async stack
102
+ // trace descriptions / taskNames is only extracted when jumping
103
+ // to the async parent, and that might not have happened when
104
+ // the cached value was computed (e.g. the cached value
105
+ // computation started at some point inside the parent stack
106
+ // trace).
107
+ stackTrace.description = stackTrace.description || stackTraceFromCache.description;
108
+ break;
109
+ }
110
+
111
+ if (!isNativeJSFunction(currentEntry.callFrame)) {
112
+ stackTrace.callFrames.push(currentEntry.callFrame);
113
+ }
114
+ const maybeAsyncParentEvent = data.AsyncJSCalls.asyncCallToScheduler.get(currentEntry);
115
+ const maybeAsyncParentNode = maybeAsyncParentEvent && entryToNode.get(maybeAsyncParentEvent.scheduler);
116
+ if (maybeAsyncParentNode) {
117
+ stackTrace = addAsyncParentToStack(stackTrace, maybeAsyncParentEvent.taskName);
118
+ node = maybeAsyncParentNode;
119
+ continue;
120
+ }
121
+ node = node.parent;
122
+ }
123
+ return topStackTrace;
124
+ }
125
+
126
+ function addAsyncParentToStack(stackTrace: Protocol.Runtime.StackTrace, taskName: string): Protocol.Runtime.StackTrace {
127
+ const parent: Protocol.Runtime.StackTrace = {callFrames: []};
128
+ // The Protocol.Runtime.StackTrace type is recursive, so we
129
+ // move one level deeper in it as we walk up the ancestor tree.
130
+ stackTrace.parent = parent;
131
+ // Note: this description effectively corresponds to the name
132
+ // of the task that scheduled the stack trace we are jumping
133
+ // FROM, so it would make sense that it was set to that stack
134
+ // trace instead of the one we are jumping TO. However, the
135
+ // JS presentation utils we use to present async stack traces
136
+ // assume the description is added to the stack trace that
137
+ // scheduled the async task, so we build the data that way.
138
+ parent.description = taskName;
139
+ return parent;
140
+ }
141
+
142
+ /**
143
+ * Finds the JS call in which an extension entry was injected (the
144
+ * code location that called the extension API), and returns its stack
145
+ * trace.
146
+ */
147
+ function getForExtensionEntry(event: Types.Extensions.SyntheticExtensionEntry, data: Handlers.Types.HandlerData):
148
+ Protocol.Runtime.StackTrace|null {
149
+ const rawEvent: Types.Events.Event = event.rawSourceEvent;
150
+ if (Types.Events.isPerformanceMeasureBegin(rawEvent)) {
151
+ return getForPerformanceMeasure(rawEvent, data);
152
+ }
153
+ if (!rawEvent) {
154
+ return null;
155
+ }
156
+ return get(rawEvent, data);
157
+ }
158
+
159
+ /**
160
+ * Gets the raw event for a user timing and obtains its stack trace.
161
+ */
162
+ function getForPerformanceMeasure(
163
+ event: Types.Events.PerformanceMeasureBegin, data: Handlers.Types.HandlerData): Protocol.Runtime.StackTrace|null {
164
+ let rawEvent: Types.Events.Event|undefined = event;
165
+ if (event.args.traceId === undefined) {
166
+ return null;
167
+ }
168
+ // performance.measure calls dispatch 2 events: one for the call
169
+ // itself and another to represent the measured entry in the trace
170
+ // timeline. They are connected via a common traceId. At this
171
+ // point `rawEvent` corresponds to the second case, we must
172
+ // encounter the event for the call itself to obtain its callstack.
173
+ rawEvent = data.UserTimings.measureTraceByTraceId.get(event.args.traceId);
174
+ if (!rawEvent) {
175
+ return null;
176
+ }
177
+ return get(rawEvent, data);
178
+ }
179
+ /**
180
+ * Determines if a function is a native JS API (like setTimeout,
181
+ * requestAnimationFrame, consoleTask.run. etc.). This is useful to
182
+ * discard stack frames corresponding to the JS scheduler function
183
+ * itself, since it's already being used as title of async stack traces
184
+ * taken from the async `taskName`. This is also consistent with the
185
+ * behaviour of the stack trace in the sources
186
+ * panel.
187
+ */
188
+ function isNativeJSFunction({columnNumber, lineNumber, url, scriptId}: Protocol.Runtime.CallFrame): boolean {
189
+ return lineNumber === -1 && columnNumber === -1 && url === '' && scriptId === '0';
190
+ }
191
+
192
+ /**
193
+ * Converts a stack trace from a trace event's payload into an array of
194
+ * Protocol.Runtime.CallFrame.
195
+ */
196
+ function getTraceEventPayloadStackAsProtocolCallFrame(event: Types.Events.Event): Protocol.Runtime.CallFrame[] {
197
+ const payloadCallStack = Helpers.Trace.getZeroIndexedStackTraceInEventPayload(event) || [];
198
+ const callFrames: Protocol.Runtime.CallFrame[] = [];
199
+ for (const frame of payloadCallStack) {
200
+ callFrames.push({...frame, scriptId: String(frame.scriptId) as Protocol.Runtime.ScriptId});
201
+ }
202
+ return callFrames;
203
+ }