@paulirish/trace_engine 0.0.50 → 0.0.51

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 (225) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/core/platform/Constructor.d.ts +2 -2
  3. package/core/platform/Constructor.js.map +1 -1
  4. package/core/platform/StringUtilities.d.ts +2 -5
  5. package/core/platform/StringUtilities.js +0 -3
  6. package/core/platform/StringUtilities.js.map +1 -1
  7. package/core/platform/TypescriptUtilities.d.ts +1 -1
  8. package/core/platform/TypescriptUtilities.js +1 -1
  9. package/core/platform/TypescriptUtilities.js.map +1 -1
  10. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  11. package/core/platform/platform-tsconfig.json +2 -3
  12. package/core/platform/platform.d.ts +1 -2
  13. package/core/platform/platform.js +1 -2
  14. package/core/platform/platform.js.map +1 -1
  15. package/generated/protocol.d.ts +156 -31
  16. package/locales/af.json +63 -3
  17. package/locales/am.json +63 -3
  18. package/locales/ar.json +63 -3
  19. package/locales/as.json +63 -3
  20. package/locales/az.json +63 -3
  21. package/locales/be.json +64 -4
  22. package/locales/bg.json +62 -2
  23. package/locales/bn.json +63 -3
  24. package/locales/bs.json +63 -3
  25. package/locales/ca.json +62 -2
  26. package/locales/cs.json +62 -2
  27. package/locales/cy.json +63 -3
  28. package/locales/da.json +63 -3
  29. package/locales/de.json +63 -3
  30. package/locales/el.json +62 -2
  31. package/locales/en-GB.json +63 -3
  32. package/locales/en-US.json +55 -22
  33. package/locales/en-XL.json +55 -22
  34. package/locales/es-419.json +63 -3
  35. package/locales/es.json +64 -4
  36. package/locales/et.json +64 -4
  37. package/locales/eu.json +79 -19
  38. package/locales/fa.json +62 -2
  39. package/locales/fi.json +63 -3
  40. package/locales/fil.json +63 -3
  41. package/locales/fr-CA.json +63 -3
  42. package/locales/fr.json +63 -3
  43. package/locales/gl.json +62 -2
  44. package/locales/gu.json +63 -3
  45. package/locales/he.json +63 -3
  46. package/locales/hi.json +62 -2
  47. package/locales/hr.json +63 -3
  48. package/locales/hu.json +62 -2
  49. package/locales/hy.json +63 -3
  50. package/locales/id.json +62 -2
  51. package/locales/is.json +64 -4
  52. package/locales/it.json +64 -4
  53. package/locales/ja.json +63 -3
  54. package/locales/ka.json +63 -3
  55. package/locales/kk.json +62 -2
  56. package/locales/km.json +62 -2
  57. package/locales/kn.json +63 -3
  58. package/locales/ko.json +63 -3
  59. package/locales/ky.json +63 -3
  60. package/locales/lo.json +63 -3
  61. package/locales/lt.json +62 -2
  62. package/locales/lv.json +62 -2
  63. package/locales/mk.json +62 -2
  64. package/locales/ml.json +63 -3
  65. package/locales/mn.json +63 -3
  66. package/locales/mr.json +64 -4
  67. package/locales/ms.json +63 -3
  68. package/locales/my.json +63 -3
  69. package/locales/ne.json +64 -4
  70. package/locales/nl.json +63 -3
  71. package/locales/no.json +62 -2
  72. package/locales/or.json +63 -3
  73. package/locales/pa.json +62 -2
  74. package/locales/pl.json +62 -2
  75. package/locales/pt-PT.json +62 -2
  76. package/locales/pt.json +63 -3
  77. package/locales/ro.json +63 -3
  78. package/locales/ru.json +63 -3
  79. package/locales/si.json +63 -3
  80. package/locales/sk.json +63 -3
  81. package/locales/sl.json +62 -2
  82. package/locales/sq.json +63 -3
  83. package/locales/sr-Latn.json +62 -2
  84. package/locales/sr.json +62 -2
  85. package/locales/sv.json +62 -2
  86. package/locales/sw.json +63 -3
  87. package/locales/ta.json +66 -6
  88. package/locales/te.json +63 -3
  89. package/locales/th.json +63 -3
  90. package/locales/tr.json +63 -3
  91. package/locales/uk.json +63 -3
  92. package/locales/ur.json +64 -4
  93. package/locales/uz.json +62 -2
  94. package/locales/vi.json +62 -2
  95. package/locales/zh-HK.json +63 -3
  96. package/locales/zh-TW.json +63 -3
  97. package/locales/zh.json +62 -2
  98. package/locales/zu.json +63 -3
  99. package/models/cpu_profile/CPUProfileDataModel.d.ts +8 -0
  100. package/models/cpu_profile/CPUProfileDataModel.js.map +1 -1
  101. package/models/cpu_profile/cpu_profile-tsconfig.json +2 -2
  102. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  103. package/models/trace/Processor.d.ts +1 -1
  104. package/models/trace/Processor.js +94 -74
  105. package/models/trace/Processor.js.map +1 -1
  106. package/models/trace/TracingManager.js.map +1 -1
  107. package/models/trace/bundle-tsconfig.json +1 -1
  108. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +20 -2
  109. package/models/trace/extras/ScriptDuplication.d.ts +11 -15
  110. package/models/trace/extras/ScriptDuplication.js +59 -77
  111. package/models/trace/extras/ScriptDuplication.js.map +1 -1
  112. package/models/trace/extras/ThirdParties.d.ts +6 -13
  113. package/models/trace/extras/ThirdParties.js +69 -133
  114. package/models/trace/extras/ThirdParties.js.map +1 -1
  115. package/models/trace/extras/TraceTree.d.ts +15 -3
  116. package/models/trace/extras/TraceTree.js +36 -8
  117. package/models/trace/extras/TraceTree.js.map +1 -1
  118. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  119. package/models/trace/extras/extras-tsconfig.json +2 -2
  120. package/models/trace/extras/extras.d.ts +880 -787
  121. package/models/trace/extras/extras.js +880 -787
  122. package/models/trace/handlers/AsyncJSCallsHandler.js +36 -4
  123. package/models/trace/handlers/AsyncJSCallsHandler.js.map +1 -1
  124. package/models/trace/handlers/InvalidationsHandler.js +1 -0
  125. package/models/trace/handlers/InvalidationsHandler.js.map +1 -1
  126. package/models/trace/handlers/ModelHandlers.d.ts +0 -1
  127. package/models/trace/handlers/ModelHandlers.js +0 -1
  128. package/models/trace/handlers/ModelHandlers.js.map +1 -1
  129. package/models/trace/handlers/NetworkRequestsHandler.js +1 -1
  130. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  131. package/models/trace/handlers/RendererHandler.d.ts +1 -1
  132. package/models/trace/handlers/RendererHandler.js +2 -2
  133. package/models/trace/handlers/RendererHandler.js.map +1 -1
  134. package/models/trace/handlers/ScreenshotsHandler.js +3 -1
  135. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  136. package/models/trace/handlers/ScriptsHandler.d.ts +12 -0
  137. package/models/trace/handlers/ScriptsHandler.js +93 -1
  138. package/models/trace/handlers/ScriptsHandler.js.map +1 -1
  139. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  140. package/models/trace/handlers/handlers-tsconfig.json +2 -3
  141. package/models/trace/helpers/Network.d.ts +5 -0
  142. package/models/trace/helpers/Network.js +17 -0
  143. package/models/trace/helpers/Network.js.map +1 -1
  144. package/models/trace/helpers/SamplesIntegrator.js +19 -23
  145. package/models/trace/helpers/SamplesIntegrator.js.map +1 -1
  146. package/models/trace/helpers/SyntheticEvents.d.ts +0 -1
  147. package/models/trace/helpers/SyntheticEvents.js +0 -4
  148. package/models/trace/helpers/SyntheticEvents.js.map +1 -1
  149. package/models/trace/helpers/Trace.d.ts +2 -1
  150. package/models/trace/helpers/Trace.js +101 -1
  151. package/models/trace/helpers/Trace.js.map +1 -1
  152. package/models/trace/helpers/TreeHelpers.d.ts +2 -5
  153. package/models/trace/helpers/TreeHelpers.js +0 -4
  154. package/models/trace/helpers/TreeHelpers.js.map +1 -1
  155. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  156. package/models/trace/helpers/helpers-tsconfig.json +2 -2
  157. package/models/trace/insights/{UseCache.d.ts → Cache.d.ts} +2 -2
  158. package/models/trace/insights/{UseCache.js → Cache.js} +11 -5
  159. package/models/trace/insights/Cache.js.map +1 -0
  160. package/models/trace/insights/Common.d.ts +21 -2
  161. package/models/trace/insights/Common.js +86 -2
  162. package/models/trace/insights/Common.js.map +1 -1
  163. package/models/trace/insights/DocumentLatency.js +2 -8
  164. package/models/trace/insights/DocumentLatency.js.map +1 -1
  165. package/models/trace/insights/DuplicatedJavaScript.d.ts +7 -4
  166. package/models/trace/insights/DuplicatedJavaScript.js +25 -5
  167. package/models/trace/insights/DuplicatedJavaScript.js.map +1 -1
  168. package/models/trace/insights/ForcedReflow.d.ts +5 -1
  169. package/models/trace/insights/ForcedReflow.js +6 -2
  170. package/models/trace/insights/ForcedReflow.js.map +1 -1
  171. package/models/trace/insights/InteractionToNextPaint.d.ts +1 -0
  172. package/models/trace/insights/InteractionToNextPaint.js +3 -0
  173. package/models/trace/insights/InteractionToNextPaint.js.map +1 -1
  174. package/models/trace/insights/LegacyJavaScript.d.ts +32 -0
  175. package/models/trace/insights/LegacyJavaScript.js +77 -0
  176. package/models/trace/insights/LegacyJavaScript.js.map +1 -0
  177. package/models/trace/insights/Models.d.ts +3 -1
  178. package/models/trace/insights/Models.js +3 -1
  179. package/models/trace/insights/Models.js.map +1 -1
  180. package/models/trace/insights/ModernHTTP.d.ts +51 -0
  181. package/models/trace/insights/ModernHTTP.js +187 -0
  182. package/models/trace/insights/ModernHTTP.js.map +1 -0
  183. package/models/trace/insights/NetworkDependencyTree.js +1 -1
  184. package/models/trace/insights/NetworkDependencyTree.js.map +1 -1
  185. package/models/trace/insights/ThirdParties.d.ts +1 -5
  186. package/models/trace/insights/ThirdParties.js +8 -21
  187. package/models/trace/insights/ThirdParties.js.map +1 -1
  188. package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  189. package/models/trace/insights/insights-tsconfig.json +8 -3
  190. package/models/trace/insights/types.d.ts +1 -0
  191. package/models/trace/insights/types.js.map +1 -1
  192. package/models/trace/lantern/core/core-tsconfig.json +2 -2
  193. package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  194. package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  195. package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  196. package/models/trace/lantern/graph/graph-tsconfig.json +2 -2
  197. package/models/trace/lantern/lantern-tsconfig.json +2 -2
  198. package/models/trace/lantern/metrics/Metric.d.ts +4 -4
  199. package/models/trace/lantern/metrics/Metric.js +4 -6
  200. package/models/trace/lantern/metrics/Metric.js.map +1 -1
  201. package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  202. package/models/trace/lantern/metrics/metrics-tsconfig.json +2 -2
  203. package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  204. package/models/trace/lantern/simulation/simulation-tsconfig.json +2 -2
  205. package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  206. package/models/trace/lantern/types/types-tsconfig.json +2 -2
  207. package/models/trace/trace-tsconfig.json +2 -2
  208. package/models/trace/types/Configuration.d.ts +2 -0
  209. package/models/trace/types/Configuration.js.map +1 -1
  210. package/models/trace/types/TraceEvents.d.ts +28 -50
  211. package/models/trace/types/TraceEvents.js +8 -23
  212. package/models/trace/types/TraceEvents.js.map +1 -1
  213. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  214. package/models/trace/types/types-tsconfig.json +2 -2
  215. package/package.json +3 -2
  216. package/test/test-trace-engine.mjs +19 -17
  217. package/third_party/legacy-javascript/legacy-javascript.d.ts +1 -0
  218. package/third_party/legacy-javascript/legacy-javascript.js +1 -0
  219. package/core/platform/ServerTiming.d.ts +0 -31
  220. package/core/platform/ServerTiming.js +0 -212
  221. package/core/platform/ServerTiming.js.map +0 -1
  222. package/models/trace/handlers/ServerTimingsHandler.d.ts +0 -9
  223. package/models/trace/handlers/ServerTimingsHandler.js +0 -106
  224. package/models/trace/handlers/ServerTimingsHandler.js.map +0 -1
  225. package/models/trace/insights/UseCache.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"RendererHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/RendererHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAA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G,UAAU,CAAC,IAAI,GAAG,QAAQ,GAAG,KAAK,CAAC,EAAE,GAAG,IAAI;gBACrG,KAAK,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,mEAAmE;QACnE,SAAS;QACT,UAAU,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;QAC9D,OAAO,IAAI,CAAC;IACd,CAAC;IAED,mEAAmE;IACnE,wDAAwD;IACxD,MAAM,iBAAiB,GAAmC;QACxD,GAAG,KAAK;QACR,EAAE,uCAA6B;QAC/B,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;KAC3B,CAAC;IAEF,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC3C,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["// Copyright 2022 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 * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as auctionWorkletsData} from './AuctionWorkletsHandler.js';\nimport * as HandlerHelpers from './helpers.js';\nimport {data as metaHandlerData, type FrameProcessData} from './MetaHandler.js';\nimport {data as networkRequestHandlerData} from './NetworkRequestsHandler.js';\nimport {data as samplesHandlerData} from './SamplesHandler.js';\nimport type {HandlerName} from './types.js';\n\n/**\n * This handler builds the hierarchy of trace events and profile calls\n * on each thread on each process.\n *\n * Throughout the code, trace events and profile calls are referred to\n * as \"entries\", but note they are different types of data. Trace events\n * come directly from the backend and it's the type the engine commonly\n * refers to. Profile calls on the other hand are built in the frontend,\n * and, for compatibility purposes, typed as an extension to the trace\n * event type.\n */\n\nconst processes = new Map<Types.Events.ProcessID, RendererProcess>();\n\nlet entityMappings: HandlerHelpers.EntityMappings = {\n eventsByEntity: new Map<HandlerHelpers.Entity, Types.Events.Event[]>(),\n entityByEvent: new Map<Types.Events.Event, HandlerHelpers.Entity>(),\n createdEntityCache: new Map<string, HandlerHelpers.Entity>(),\n};\n\n// We track the compositor tile worker thread name events so that at the end we\n// can return these keyed by the process ID. These are used in the frontend to\n// show the user the rasterization thread(s) on the main frame as tracks.\nconst compositorTileWorkers = Array<{\n pid: Types.Events.ProcessID,\n tid: Types.Events.ThreadID,\n}>();\nconst entryToNode = new Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>();\nlet allTraceEntries: Types.Events.Event[] = [];\n\nconst completeEventStack: (Types.Events.SyntheticComplete)[] = [];\n\nlet config: Types.Configuration.Configuration = Types.Configuration.defaults();\n\nconst makeRendererProcess = (): RendererProcess => ({\n url: null,\n isOnMainFrame: false,\n threads: new Map(),\n});\n\nconst makeRendererThread = (): RendererThread => ({\n name: null,\n entries: [],\n profileCalls: [],\n layoutEvents: [],\n updateLayoutTreeEvents: [],\n});\n\nconst getOrCreateRendererProcess =\n (processes: Map<Types.Events.ProcessID, RendererProcess>, pid: Types.Events.ProcessID): RendererProcess => {\n return Platform.MapUtilities.getWithDefault(processes, pid, makeRendererProcess);\n };\n\nconst getOrCreateRendererThread = (process: RendererProcess, tid: Types.Events.ThreadID): RendererThread => {\n return Platform.MapUtilities.getWithDefault(process.threads, tid, makeRendererThread);\n};\n\nexport function handleUserConfig(userConfig: Types.Configuration.Configuration): void {\n config = userConfig;\n}\n\nexport function reset(): void {\n processes.clear();\n entryToNode.clear();\n entityMappings.eventsByEntity.clear();\n entityMappings.entityByEvent.clear();\n entityMappings.createdEntityCache.clear();\n allTraceEntries.length = 0;\n completeEventStack.length = 0;\n compositorTileWorkers.length = 0;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isThreadName(event) && event.args.name?.startsWith('CompositorTileWorker')) {\n compositorTileWorkers.push({\n pid: event.pid,\n tid: event.tid,\n });\n }\n\n if (Types.Events.isBegin(event) || Types.Events.isEnd(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n const completeEvent = makeCompleteEvent(event);\n if (!completeEvent) {\n return;\n }\n thread.entries.push(completeEvent);\n allTraceEntries.push(completeEvent);\n return;\n }\n\n if (Types.Events.isInstant(event) || Types.Events.isComplete(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.entries.push(event);\n allTraceEntries.push(event);\n }\n\n if (Types.Events.isLayout(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.layoutEvents.push(event);\n }\n\n if (Types.Events.isUpdateLayoutTree(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.updateLayoutTreeEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n const {mainFrameId, rendererProcessesByFrame, threadsInProcess} = metaHandlerData();\n entityMappings = networkRequestHandlerData().entityMappings;\n\n assignMeta(processes, mainFrameId, rendererProcessesByFrame, threadsInProcess);\n sanitizeProcesses(processes);\n buildHierarchy(processes);\n sanitizeThreads(processes);\n Helpers.Trace.sortTraceEventsInPlace(allTraceEntries);\n}\n\nexport function data(): RendererHandlerData {\n return {\n processes: new Map(processes),\n compositorTileWorkers: new Map(gatherCompositorThreads()),\n entryToNode: new Map(entryToNode),\n allTraceEntries: [...allTraceEntries],\n entityMappings: {\n entityByEvent: new Map(entityMappings.entityByEvent),\n eventsByEntity: new Map(entityMappings.eventsByEntity),\n createdEntityCache: new Map(entityMappings.createdEntityCache),\n },\n };\n}\n\nfunction gatherCompositorThreads(): Map<Types.Events.ProcessID, Types.Events.ThreadID[]> {\n const threadsByProcess = new Map<Types.Events.ProcessID, Types.Events.ThreadID[]>();\n for (const worker of compositorTileWorkers) {\n const byProcess = threadsByProcess.get(worker.pid) || [];\n byProcess.push(worker.tid);\n threadsByProcess.set(worker.pid, byProcess);\n }\n return threadsByProcess;\n}\n\n/**\n * Steps through all the renderer processes we've located so far in the meta\n * handler, obtaining their URL, checking whether they are the main frame, and\n * collecting each one of their threads' name. This meta handler's data is\n * assigned to the renderer handler's data.\n */\nexport function assignMeta(\n processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,\n rendererProcessesByFrame: FrameProcessData,\n threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {\n assignOrigin(processes, rendererProcessesByFrame);\n assignIsMainFrame(processes, mainFrameId, rendererProcessesByFrame);\n assignThreadName(processes, rendererProcessesByFrame, threadsInProcess);\n}\n\n/**\n * Assigns origins to all threads in all processes.\n * @see assignMeta\n */\nexport function assignOrigin(\n processes: Map<Types.Events.ProcessID, RendererProcess>, rendererProcessesByFrame: FrameProcessData): void {\n for (const renderProcessesByPid of rendererProcessesByFrame.values()) {\n for (const [pid, processWindows] of renderProcessesByPid) {\n for (const processInfo of processWindows.flat()) {\n const process = getOrCreateRendererProcess(processes, pid);\n // Sometimes a single process is responsible with rendering multiple\n // frames at the same time. For example, see https://crbug.com/1334563.\n // When this happens, we'd still like to assign a single url per process\n // so: 1) use the first frame rendered by this process as the url source\n // and 2) if the last url is \"about:blank\", use the next frame's url,\n // data from about:blank is irrelevant.\n if (process.url === null || process.url === 'about:blank') {\n // If we are here, it's because we care about this process and the URL. But before we store\n // it, we check if it is a valid URL by trying to create a URL object. If it isn't, we won't\n // set it, and this process will be filtered out later.\n try {\n new URL(processInfo.frame.url);\n process.url = processInfo.frame.url;\n } catch {\n process.url = null;\n }\n }\n }\n }\n }\n}\n\n/**\n * Assigns whether or not a thread is the main frame to all threads in all processes.\n * @see assignMeta\n */\nexport function assignIsMainFrame(\n processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,\n rendererProcessesByFrame: FrameProcessData): void {\n for (const [frameId, renderProcessesByPid] of rendererProcessesByFrame) {\n for (const [pid] of renderProcessesByPid) {\n const process = getOrCreateRendererProcess(processes, pid);\n // We have this go in one direction; once a renderer has been flagged as\n // being on the main frame, we don't unset it to false if were to show up\n // in a subframe. Equally, if we already saw this renderer in a subframe,\n // but it becomes the main frame, the flag would get updated.\n if (frameId === mainFrameId) {\n process.isOnMainFrame = true;\n }\n }\n }\n}\n\n/**\n * Assigns the thread name to all threads in all processes.\n * @see assignMeta\n */\nexport function assignThreadName(\n processes: Map<Types.Events.ProcessID, RendererProcess>, rendererProcessesByFrame: FrameProcessData,\n threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {\n for (const [pid, process] of processes) {\n for (const [tid, threadInfo] of threadsInProcess.get(pid) ?? []) {\n const thread = getOrCreateRendererThread(process, tid);\n thread.name = threadInfo?.args.name ?? `${tid}`;\n }\n }\n}\n\n/**\n * Removes unneeded trace data opportunistically stored while handling events.\n * This currently does the following:\n * - Deletes processes with an unknown origin.\n */\nexport function sanitizeProcesses(processes: Map<Types.Events.ProcessID, RendererProcess>): void {\n const auctionWorklets = auctionWorkletsData().worklets;\n const metaData = metaHandlerData();\n if (metaData.traceIsGeneric) {\n return;\n }\n for (const [pid, process] of processes) {\n // If the process had no url, or if it had a malformed url that could not be\n // parsed for some reason, or if it's an \"about:\" origin, delete it.\n // This is done because we don't really care about processes for which we\n // can't provide actionable insights to the user (e.g. about:blank pages).\n //\n // There is one exception; AuctionWorklet processes get parsed in a\n // separate handler, so at this point we check to see if the process has\n // been found by the AuctionWorkletsHandler, and if so we update the URL.\n // This ensures that we keep this process around and do not drop it due to\n // the lack of a URL.\n if (process.url === null) {\n const maybeWorklet = auctionWorklets.get(pid);\n if (maybeWorklet) {\n process.url = maybeWorklet.host;\n } else {\n processes.delete(pid);\n }\n continue;\n }\n }\n}\n\n/**\n * Removes unneeded trace data opportunistically stored while handling events.\n * This currently does the following:\n * - Deletes threads with no roots.\n */\nexport function sanitizeThreads(processes: Map<Types.Events.ProcessID, RendererProcess>): void {\n for (const [, process] of processes) {\n for (const [tid, thread] of process.threads) {\n // If the thread has no roots, delete it. Otherwise, there's going to\n // be space taken, even though nothing is rendered in the track manager.\n if (!thread.tree?.roots.size) {\n process.threads.delete(tid);\n }\n }\n }\n}\n\n/**\n * Creates a hierarchical structure from the trace events. Each thread in each\n * process will contribute to their own individual hierarchy.\n *\n * The trace data comes in as a contiguous array of events, against which we\n * make a couple of assumptions:\n *\n * 1. Events are temporally-ordered in terms of start time (though they're\n * not necessarily ordered as such in the data stream).\n * 2. If event B's start and end times are within event A's time boundaries\n * we assume that A is the parent of B.\n *\n * Therefore we expect to reformulate something like:\n *\n * [ Task A ][ Task B ][ Task C ][ Task D ][ Task E ]\n *\n * Into something hierarchically-arranged like below:\n *\n * |------------- Task A -------------||-- Task E --|\n * |-- Task B --||-- Task D --|\n * |- Task C -|\n */\nexport function buildHierarchy(\n processes: Map<Types.Events.ProcessID, RendererProcess>,\n options?: {filter: {has: (name: Types.Events.Name) => boolean}}): void {\n const samplesData = samplesHandlerData();\n for (const [pid, process] of processes) {\n for (const [tid, thread] of process.threads) {\n if (!thread.entries.length) {\n thread.tree = Helpers.TreeHelpers.makeEmptyTraceEntryTree();\n continue;\n }\n // Step 1. Massage the data.\n Helpers.Trace.sortTraceEventsInPlace(thread.entries);\n // Step 2. Inject profile calls from samples\n const samplesDataForThread = samplesData.profilesInProcess.get(pid)?.get(tid);\n if (samplesDataForThread) {\n const cpuProfile = samplesDataForThread.parsedProfile;\n const samplesIntegrator = cpuProfile &&\n new Helpers.SamplesIntegrator.SamplesIntegrator(\n cpuProfile, samplesDataForThread.profileId, pid, tid, config);\n const profileCalls = samplesIntegrator?.buildProfileCalls(thread.entries);\n if (samplesIntegrator && profileCalls) {\n allTraceEntries = [...allTraceEntries, ...profileCalls];\n thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, profileCalls);\n thread.profileCalls = profileCalls;\n // We'll also inject the instant JSSample events (in debug mode only)\n const jsSamples = samplesIntegrator.jsSampleEvents;\n if (jsSamples) {\n allTraceEntries = [...allTraceEntries, ...jsSamples];\n thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, jsSamples);\n }\n }\n }\n // Step 3. Build the tree.\n const treeData = Helpers.TreeHelpers.treify(thread.entries, options);\n thread.tree = treeData.tree;\n // Update the entryToNode map with the entries from this thread\n for (const [entry, node] of treeData.entryToNode) {\n entryToNode.set(entry, node);\n // Entity mapping is unrelated to the tree, but calling here as we need to call on every node anyway.\n HandlerHelpers.addEventToEntityMapping(entry, entityMappings);\n }\n }\n }\n}\n\nexport function makeCompleteEvent(event: Types.Events.Begin|Types.Events.End): Types.Events.SyntheticComplete|null {\n if (Types.Events.isEnd(event)) {\n // Quietly ignore unbalanced close events, they're legit (we could\n // have missed start one).\n const beginEvent = completeEventStack.pop();\n if (!beginEvent) {\n return null;\n }\n if (beginEvent.name !== event.name || beginEvent.cat !== event.cat) {\n console.error(\n 'Begin/End events mismatch at ' + beginEvent.ts + ' (' + beginEvent.name + ') vs. ' + event.ts + ' (' +\n event.name + ')');\n return null;\n }\n // Update the begin event's duration using the timestamp of the end\n // event.\n beginEvent.dur = Types.Timing.Micro(event.ts - beginEvent.ts);\n return null;\n }\n\n // Create a synthetic event using the begin event, when we find the\n // matching end event later we will update its duration.\n const syntheticComplete: Types.Events.SyntheticComplete = {\n ...event,\n ph: Types.Events.Phase.COMPLETE,\n dur: Types.Timing.Micro(0),\n };\n\n completeEventStack.push(syntheticComplete);\n return syntheticComplete;\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'Samples', 'AuctionWorklets', 'NetworkRequests'];\n}\n\nexport interface RendererHandlerData {\n processes: Map<Types.Events.ProcessID, RendererProcess>;\n /**\n * A map of all compositor workers (which we show in the UI as Rasterizers)\n * by the process ID.\n */\n compositorTileWorkers: Map<Types.Events.ProcessID, Types.Events.ThreadID[]>;\n entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;\n /**\n * All trace events and synthetic profile calls made from\n * samples.\n */\n allTraceEntries: Types.Events.Event[];\n entityMappings: HandlerHelpers.EntityMappings;\n}\n\nexport interface RendererProcess {\n // In an ideal world this would be modelled as a URL, but URLs cannot be sent\n // between the main thread and workers, so we have to store it as a string.\n url: string|null;\n isOnMainFrame: boolean;\n threads: Map<Types.Events.ThreadID, RendererThread>;\n}\n\nexport interface RendererThread {\n name: string|null;\n /**\n * Contains trace events and synthetic profile calls made from\n * samples.\n */\n entries: Types.Events.Event[];\n profileCalls: Types.Events.SyntheticProfileCall[];\n layoutEvents: Types.Events.Layout[];\n updateLayoutTreeEvents: Types.Events.UpdateLayoutTree[];\n tree?: Helpers.TreeHelpers.TraceEntryTree;\n}\n"]}
1
+ {"version":3,"file":"RendererHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/RendererHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAC/D,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,mBAAmB,EAAC,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,cAAc,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAwB,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAC,IAAI,IAAI,yBAAyB,EAAC,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAC,IAAI,IAAI,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAG/D;;;;;;;;;;GAUG;AAEH,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2C,CAAC;AAErE,IAAI,cA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AC3B,CAAC;IAEF,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAC3C,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AACnE,CAAC","sourcesContent":["// Copyright 2022 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 * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport {data as auctionWorkletsData} from './AuctionWorkletsHandler.js';\nimport * as HandlerHelpers from './helpers.js';\nimport {data as metaHandlerData, type FrameProcessData} from './MetaHandler.js';\nimport {data as networkRequestHandlerData} from './NetworkRequestsHandler.js';\nimport {data as samplesHandlerData} from './SamplesHandler.js';\nimport type {HandlerName} from './types.js';\n\n/**\n * This handler builds the hierarchy of trace events and profile calls\n * on each thread on each process.\n *\n * Throughout the code, trace events and profile calls are referred to\n * as \"entries\", but note they are different types of data. Trace events\n * come directly from the backend and it's the type the engine commonly\n * refers to. Profile calls on the other hand are built in the frontend,\n * and, for compatibility purposes, typed as an extension to the trace\n * event type.\n */\n\nconst processes = new Map<Types.Events.ProcessID, RendererProcess>();\n\nlet entityMappings: HandlerHelpers.EntityMappings = {\n eventsByEntity: new Map<HandlerHelpers.Entity, Types.Events.Event[]>(),\n entityByEvent: new Map<Types.Events.Event, HandlerHelpers.Entity>(),\n createdEntityCache: new Map<string, HandlerHelpers.Entity>(),\n};\n\n// We track the compositor tile worker thread name events so that at the end we\n// can return these keyed by the process ID. These are used in the frontend to\n// show the user the rasterization thread(s) on the main frame as tracks.\nconst compositorTileWorkers = Array<{\n pid: Types.Events.ProcessID,\n tid: Types.Events.ThreadID,\n}>();\nconst entryToNode = new Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>();\nlet allTraceEntries: Types.Events.Event[] = [];\n\nconst completeEventStack: (Types.Events.SyntheticComplete)[] = [];\n\nlet config: Types.Configuration.Configuration = Types.Configuration.defaults();\n\nconst makeRendererProcess = (): RendererProcess => ({\n url: null,\n isOnMainFrame: false,\n threads: new Map(),\n});\n\nconst makeRendererThread = (): RendererThread => ({\n name: null,\n entries: [],\n profileCalls: [],\n layoutEvents: [],\n updateLayoutTreeEvents: [],\n});\n\nconst getOrCreateRendererProcess =\n (processes: Map<Types.Events.ProcessID, RendererProcess>, pid: Types.Events.ProcessID): RendererProcess => {\n return Platform.MapUtilities.getWithDefault(processes, pid, makeRendererProcess);\n };\n\nconst getOrCreateRendererThread = (process: RendererProcess, tid: Types.Events.ThreadID): RendererThread => {\n return Platform.MapUtilities.getWithDefault(process.threads, tid, makeRendererThread);\n};\n\nexport function handleUserConfig(userConfig: Types.Configuration.Configuration): void {\n config = userConfig;\n}\n\nexport function reset(): void {\n processes.clear();\n entryToNode.clear();\n entityMappings.eventsByEntity.clear();\n entityMappings.entityByEvent.clear();\n entityMappings.createdEntityCache.clear();\n allTraceEntries.length = 0;\n completeEventStack.length = 0;\n compositorTileWorkers.length = 0;\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isThreadName(event) && event.args.name?.startsWith('CompositorTileWorker')) {\n compositorTileWorkers.push({\n pid: event.pid,\n tid: event.tid,\n });\n }\n\n if (Types.Events.isBegin(event) || Types.Events.isEnd(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n const completeEvent = makeCompleteEvent(event);\n if (!completeEvent) {\n return;\n }\n thread.entries.push(completeEvent);\n allTraceEntries.push(completeEvent);\n return;\n }\n\n if (Types.Events.isInstant(event) || Types.Events.isComplete(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.entries.push(event);\n allTraceEntries.push(event);\n }\n\n if (Types.Events.isLayout(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.layoutEvents.push(event);\n }\n\n if (Types.Events.isUpdateLayoutTree(event)) {\n const process = getOrCreateRendererProcess(processes, event.pid);\n const thread = getOrCreateRendererThread(process, event.tid);\n thread.updateLayoutTreeEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n const {mainFrameId, rendererProcessesByFrame, threadsInProcess} = metaHandlerData();\n entityMappings = networkRequestHandlerData().entityMappings;\n\n assignMeta(processes, mainFrameId, rendererProcessesByFrame, threadsInProcess);\n sanitizeProcesses(processes);\n buildHierarchy(processes);\n sanitizeThreads(processes);\n Helpers.Trace.sortTraceEventsInPlace(allTraceEntries);\n}\n\nexport function data(): RendererHandlerData {\n return {\n processes: new Map(processes),\n compositorTileWorkers: new Map(gatherCompositorThreads()),\n entryToNode: new Map(entryToNode),\n allTraceEntries: [...allTraceEntries],\n entityMappings: {\n entityByEvent: new Map(entityMappings.entityByEvent),\n eventsByEntity: new Map(entityMappings.eventsByEntity),\n createdEntityCache: new Map(entityMappings.createdEntityCache),\n },\n };\n}\n\nfunction gatherCompositorThreads(): Map<Types.Events.ProcessID, Types.Events.ThreadID[]> {\n const threadsByProcess = new Map<Types.Events.ProcessID, Types.Events.ThreadID[]>();\n for (const worker of compositorTileWorkers) {\n const byProcess = threadsByProcess.get(worker.pid) || [];\n byProcess.push(worker.tid);\n threadsByProcess.set(worker.pid, byProcess);\n }\n return threadsByProcess;\n}\n\n/**\n * Steps through all the renderer processes we've located so far in the meta\n * handler, obtaining their URL, checking whether they are the main frame, and\n * collecting each one of their threads' name. This meta handler's data is\n * assigned to the renderer handler's data.\n */\nexport function assignMeta(\n processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,\n rendererProcessesByFrame: FrameProcessData,\n threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {\n assignOrigin(processes, rendererProcessesByFrame);\n assignIsMainFrame(processes, mainFrameId, rendererProcessesByFrame);\n assignThreadName(processes, threadsInProcess);\n}\n\n/**\n * Assigns origins to all threads in all processes.\n * @see assignMeta\n */\nexport function assignOrigin(\n processes: Map<Types.Events.ProcessID, RendererProcess>, rendererProcessesByFrame: FrameProcessData): void {\n for (const renderProcessesByPid of rendererProcessesByFrame.values()) {\n for (const [pid, processWindows] of renderProcessesByPid) {\n for (const processInfo of processWindows.flat()) {\n const process = getOrCreateRendererProcess(processes, pid);\n // Sometimes a single process is responsible with rendering multiple\n // frames at the same time. For example, see https://crbug.com/1334563.\n // When this happens, we'd still like to assign a single url per process\n // so: 1) use the first frame rendered by this process as the url source\n // and 2) if the last url is \"about:blank\", use the next frame's url,\n // data from about:blank is irrelevant.\n if (process.url === null || process.url === 'about:blank') {\n // If we are here, it's because we care about this process and the URL. But before we store\n // it, we check if it is a valid URL by trying to create a URL object. If it isn't, we won't\n // set it, and this process will be filtered out later.\n try {\n new URL(processInfo.frame.url);\n process.url = processInfo.frame.url;\n } catch {\n process.url = null;\n }\n }\n }\n }\n }\n}\n\n/**\n * Assigns whether or not a thread is the main frame to all threads in all processes.\n * @see assignMeta\n */\nexport function assignIsMainFrame(\n processes: Map<Types.Events.ProcessID, RendererProcess>, mainFrameId: string,\n rendererProcessesByFrame: FrameProcessData): void {\n for (const [frameId, renderProcessesByPid] of rendererProcessesByFrame) {\n for (const [pid] of renderProcessesByPid) {\n const process = getOrCreateRendererProcess(processes, pid);\n // We have this go in one direction; once a renderer has been flagged as\n // being on the main frame, we don't unset it to false if were to show up\n // in a subframe. Equally, if we already saw this renderer in a subframe,\n // but it becomes the main frame, the flag would get updated.\n if (frameId === mainFrameId) {\n process.isOnMainFrame = true;\n }\n }\n }\n}\n\n/**\n * Assigns the thread name to all threads in all processes.\n * @see assignMeta\n */\nexport function assignThreadName(\n processes: Map<Types.Events.ProcessID, RendererProcess>,\n threadsInProcess: Map<Types.Events.ProcessID, Map<Types.Events.ThreadID, Types.Events.ThreadName>>): void {\n for (const [pid, process] of processes) {\n for (const [tid, threadInfo] of threadsInProcess.get(pid) ?? []) {\n const thread = getOrCreateRendererThread(process, tid);\n thread.name = threadInfo?.args.name ?? `${tid}`;\n }\n }\n}\n\n/**\n * Removes unneeded trace data opportunistically stored while handling events.\n * This currently does the following:\n * - Deletes processes with an unknown origin.\n */\nexport function sanitizeProcesses(processes: Map<Types.Events.ProcessID, RendererProcess>): void {\n const auctionWorklets = auctionWorkletsData().worklets;\n const metaData = metaHandlerData();\n if (metaData.traceIsGeneric) {\n return;\n }\n for (const [pid, process] of processes) {\n // If the process had no url, or if it had a malformed url that could not be\n // parsed for some reason, or if it's an \"about:\" origin, delete it.\n // This is done because we don't really care about processes for which we\n // can't provide actionable insights to the user (e.g. about:blank pages).\n //\n // There is one exception; AuctionWorklet processes get parsed in a\n // separate handler, so at this point we check to see if the process has\n // been found by the AuctionWorkletsHandler, and if so we update the URL.\n // This ensures that we keep this process around and do not drop it due to\n // the lack of a URL.\n if (process.url === null) {\n const maybeWorklet = auctionWorklets.get(pid);\n if (maybeWorklet) {\n process.url = maybeWorklet.host;\n } else {\n processes.delete(pid);\n }\n continue;\n }\n }\n}\n\n/**\n * Removes unneeded trace data opportunistically stored while handling events.\n * This currently does the following:\n * - Deletes threads with no roots.\n */\nexport function sanitizeThreads(processes: Map<Types.Events.ProcessID, RendererProcess>): void {\n for (const [, process] of processes) {\n for (const [tid, thread] of process.threads) {\n // If the thread has no roots, delete it. Otherwise, there's going to\n // be space taken, even though nothing is rendered in the track manager.\n if (!thread.tree?.roots.size) {\n process.threads.delete(tid);\n }\n }\n }\n}\n\n/**\n * Creates a hierarchical structure from the trace events. Each thread in each\n * process will contribute to their own individual hierarchy.\n *\n * The trace data comes in as a contiguous array of events, against which we\n * make a couple of assumptions:\n *\n * 1. Events are temporally-ordered in terms of start time (though they're\n * not necessarily ordered as such in the data stream).\n * 2. If event B's start and end times are within event A's time boundaries\n * we assume that A is the parent of B.\n *\n * Therefore we expect to reformulate something like:\n *\n * [ Task A ][ Task B ][ Task C ][ Task D ][ Task E ]\n *\n * Into something hierarchically-arranged like below:\n *\n * |------------- Task A -------------||-- Task E --|\n * |-- Task B --||-- Task D --|\n * |- Task C -|\n */\nexport function buildHierarchy(\n processes: Map<Types.Events.ProcessID, RendererProcess>,\n options?: {filter: {has: (name: Types.Events.Name) => boolean}}): void {\n const samplesData = samplesHandlerData();\n for (const [pid, process] of processes) {\n for (const [tid, thread] of process.threads) {\n if (!thread.entries.length) {\n thread.tree = Helpers.TreeHelpers.makeEmptyTraceEntryTree();\n continue;\n }\n // Step 1. Massage the data.\n Helpers.Trace.sortTraceEventsInPlace(thread.entries);\n // Step 2. Inject profile calls from samples\n const samplesDataForThread = samplesData.profilesInProcess.get(pid)?.get(tid);\n if (samplesDataForThread) {\n const cpuProfile = samplesDataForThread.parsedProfile;\n const samplesIntegrator = cpuProfile &&\n new Helpers.SamplesIntegrator.SamplesIntegrator(\n cpuProfile, samplesDataForThread.profileId, pid, tid, config);\n const profileCalls = samplesIntegrator?.buildProfileCalls(thread.entries);\n if (samplesIntegrator && profileCalls) {\n allTraceEntries = [...allTraceEntries, ...profileCalls];\n thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, profileCalls);\n thread.profileCalls = profileCalls;\n // We'll also inject the instant JSSample events (in debug mode only)\n const jsSamples = samplesIntegrator.jsSampleEvents;\n if (jsSamples) {\n allTraceEntries = [...allTraceEntries, ...jsSamples];\n thread.entries = Helpers.Trace.mergeEventsInOrder(thread.entries, jsSamples);\n }\n }\n }\n // Step 3. Build the tree.\n const treeData = Helpers.TreeHelpers.treify(thread.entries, options);\n thread.tree = treeData.tree;\n // Update the entryToNode map with the entries from this thread\n for (const [entry, node] of treeData.entryToNode) {\n entryToNode.set(entry, node);\n // Entity mapping is unrelated to the tree, but calling here as we need to call on every node anyway.\n HandlerHelpers.addEventToEntityMapping(entry, entityMappings);\n }\n }\n }\n}\n\nexport function makeCompleteEvent(event: Types.Events.Begin|Types.Events.End): Types.Events.SyntheticComplete|null {\n if (Types.Events.isEnd(event)) {\n // Quietly ignore unbalanced close events, they're legit (we could\n // have missed start one).\n const beginEvent = completeEventStack.pop();\n if (!beginEvent) {\n return null;\n }\n if (beginEvent.name !== event.name || beginEvent.cat !== event.cat) {\n console.error(\n 'Begin/End events mismatch at ' + beginEvent.ts + ' (' + beginEvent.name + ') vs. ' + event.ts + ' (' +\n event.name + ')');\n return null;\n }\n // Update the begin event's duration using the timestamp of the end\n // event.\n beginEvent.dur = Types.Timing.Micro(event.ts - beginEvent.ts);\n return null;\n }\n\n // Create a synthetic event using the begin event, when we find the\n // matching end event later we will update its duration.\n const syntheticComplete: Types.Events.SyntheticComplete = {\n ...event,\n ph: Types.Events.Phase.COMPLETE,\n dur: Types.Timing.Micro(0),\n };\n\n completeEventStack.push(syntheticComplete);\n return syntheticComplete;\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'Samples', 'AuctionWorklets', 'NetworkRequests'];\n}\n\nexport interface RendererHandlerData {\n processes: Map<Types.Events.ProcessID, RendererProcess>;\n /**\n * A map of all compositor workers (which we show in the UI as Rasterizers)\n * by the process ID.\n */\n compositorTileWorkers: Map<Types.Events.ProcessID, Types.Events.ThreadID[]>;\n entryToNode: Map<Types.Events.Event, Helpers.TreeHelpers.TraceEntryNode>;\n /**\n * All trace events and synthetic profile calls made from\n * samples.\n */\n allTraceEntries: Types.Events.Event[];\n entityMappings: HandlerHelpers.EntityMappings;\n}\n\nexport interface RendererProcess {\n // In an ideal world this would be modelled as a URL, but URLs cannot be sent\n // between the main thread and workers, so we have to store it as a string.\n url: string|null;\n isOnMainFrame: boolean;\n threads: Map<Types.Events.ThreadID, RendererThread>;\n}\n\nexport interface RendererThread {\n name: string|null;\n /**\n * Contains trace events and synthetic profile calls made from\n * samples.\n */\n entries: Types.Events.Event[];\n profileCalls: Types.Events.SyntheticProfileCall[];\n layoutEvents: Types.Events.Layout[];\n updateLayoutTreeEvents: Types.Events.UpdateLayoutTree[];\n tree?: Helpers.TreeHelpers.TraceEntryTree;\n}\n"]}
@@ -31,7 +31,9 @@ export function handleEvent(event) {
31
31
  export async function finalize() {
32
32
  const pipelineReporterEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(unpairedAsyncEvents);
33
33
  frameSequenceToTs = Object.fromEntries(pipelineReporterEvents.map(evt => {
34
- const frameSequenceId = evt.args.data.beginEvent.args.chrome_frame_reporter.frame_sequence;
34
+ const args = evt.args.data.beginEvent.args;
35
+ const frameReporter = 'frame_reporter' in args ? args.frame_reporter : args.chrome_frame_reporter;
36
+ const frameSequenceId = frameReporter.frame_sequence;
35
37
  const presentationTs = Types.Timing.Micro(evt.ts + evt.dur);
36
38
  return [frameSequenceId, presentationTs];
37
39
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"ScreenshotsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScreenshotsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,qFAAqF;AACrF,qEAAqE;AACrE,MAAM,mBAAmB,GAAoC,EAAE,CAAC;AAEhE,MAAM,sBAAsB,GAAoC,EAAE,CAAC;AACnE,MAAM,sBAAsB,GAA8B,EAAE,CAAC;AAC7D,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAC1E,IAAI,iBAAiB,GAAuC,EAAE,CAAC;AAE/D,MAAM,UAAU,KAAK;IACnB,mBAAmB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,iBAAiB,GAAG,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,K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,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2022 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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\n\n// Each thread contains events. Events indicate the thread and process IDs, which are\n// used to store the event in the correct process thread entry below.\nconst unpairedAsyncEvents: Types.Events.PipelineReporter[] = [];\n\nconst legacyScreenshotEvents: Types.Events.LegacyScreenshot[] = [];\nconst modernScreenshotEvents: Types.Events.Screenshot[] = [];\nconst syntheticScreenshots: Types.Events.LegacySyntheticScreenshot[] = [];\nlet frameSequenceToTs: Record<string, Types.Timing.Micro> = {};\n\nexport function reset(): void {\n unpairedAsyncEvents.length = 0;\n legacyScreenshotEvents.length = 0;\n syntheticScreenshots.length = 0;\n modernScreenshotEvents.length = 0;\n frameSequenceToTs = {};\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isLegacyScreenshot(event)) {\n legacyScreenshotEvents.push(event);\n } else if (Types.Events.isScreenshot(event)) {\n modernScreenshotEvents.push(event);\n } else if (Types.Events.isPipelineReporter(event)) {\n unpairedAsyncEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n const pipelineReporterEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(unpairedAsyncEvents);\n\n frameSequenceToTs = Object.fromEntries(pipelineReporterEvents.map(evt => {\n const frameSequenceId = evt.args.data.beginEvent.args.chrome_frame_reporter.frame_sequence;\n const presentationTs = Types.Timing.Micro(evt.ts + evt.dur);\n return [frameSequenceId, presentationTs];\n }));\n\n for (const snapshotEvent of legacyScreenshotEvents) {\n const {cat, name, ph, pid, tid} = snapshotEvent;\n const syntheticEvent = Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<\n Types.Events.LegacySyntheticScreenshot>({\n rawSourceEvent: snapshotEvent,\n cat,\n name,\n ph,\n pid,\n tid,\n // TODO(paulirish, crbug.com/41363012): investigate why getPresentationTimestamp(snapshotEvent) seems less accurate. Resolve screenshot timing inaccuracy.\n // `getPresentationTimestamp(snapshotEvent) - snapshotEvent.ts` is how many microsec the screenshot should be adjusted to the right/later\n ts: snapshotEvent.ts,\n args: {\n dataUri: `data:image/jpg;base64,${snapshotEvent.args.snapshot}`,\n },\n });\n syntheticScreenshots.push(syntheticEvent);\n }\n}\n\nexport function screenshotImageDataUri(event: Types.Events.LegacySyntheticScreenshot|Types.Events.Screenshot): string {\n if (Types.Events.isLegacySyntheticScreenshot(event)) {\n return event.args.dataUri;\n }\n return `data:image/jpg;base64,${event.args.snapshot}`;\n}\n\n/**\n * Correct the screenshot timestamps\n * The screenshot 'snapshot object' trace event has the \"frame sequence number\" attached as an ID.\n * We match that up with the \"PipelineReporter\" trace events as they terminate at presentation.\n * Presentation == when the pixels hit the screen. AKA Swap on the GPU\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction getPresentationTimestamp(screenshotEvent: Types.Events.LegacyScreenshot): Types.Timing.Micro {\n const frameSequence = parseInt(screenshotEvent.id, 16);\n // If it's 1, then it's an old trace (before https://crrev.com/c/4957973) and cannot be corrected.\n if (frameSequence === 1) {\n return screenshotEvent.ts;\n }\n // The screenshot trace event's `ts` reflects the \"expected display time\" which is ESTIMATE.\n // It is set by the compositor frame sink from the `expected_display_time`, which is based on a previously known\n // frame start PLUS the vsync interval (eg 16.6ms)\n const updatedTs = frameSequenceToTs[frameSequence];\n // Do we always find a match? No...\n // We generally don't match the very first screenshot and, sometimes, the last\n // The very first screenshot is requested immediately (even if nothing is painting). As a result there's no compositor\n // instrumentation running alongside.\n // The last one is sometimes missing as because the trace terminates right before the associated PipelineReporter is emitted.\n return updatedTs ?? screenshotEvent.ts;\n}\n\nexport interface Data {\n // These are nullable because in January 2025 a CL in Chromium\n // crrev.com/c/6197645 landed which changed the format of screenshots. For a\n // given trace, it can have either \"legacy\" screenshot events, or \"modern\"\n // screenshot events, but no trace can ever contain both.\n // So, if either of these arrays are empty, we instead return `null`. This forces consumers to check the presence of the array.\n // Traces can have no screenshots if the trace category is not enabled, so it\n // is possible for a trace to return null for both of these arrays.\n legacySyntheticScreenshots: Types.Events.LegacySyntheticScreenshot[]|null;\n screenshots: Types.Events.Screenshot[]|null;\n}\n// TODO(crbug/41484172): should be readonly\nexport function data(): Data {\n return {\n legacySyntheticScreenshots: syntheticScreenshots.length ? syntheticScreenshots : null,\n screenshots: modernScreenshotEvents.length ? modernScreenshotEvents : null,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n"]}
1
+ {"version":3,"file":"ScreenshotsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScreenshotsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAC;AACjD,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAI3C,qFAAqF;AACrF,qEAAqE;AACrE,MAAM,mBAAmB,GAAoC,EAAE,CAAC;AAEhE,MAAM,sBAAsB,GAAoC,EAAE,CAAC;AACnE,MAAM,sBAAsB,GAA8B,EAAE,CAAC;AAC7D,MAAM,oBAAoB,GAA6C,EAAE,CAAC;AAC1E,IAAI,iBAAiB,GAAuC,EAAE,CAAC;AAE/D,MAAM,UAAU,KAAK;IACnB,mBAAmB,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;IAChC,sBAAsB,CAAC,MAAM,GAAG,CAAC,CAAC;IAClC,iBAAiB,GAAG,EAAE,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,KAAK,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK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rF,WAAW,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,IAAI;KAC3E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC","sourcesContent":["// Copyright 2022 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 Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\n\n// Each thread contains events. Events indicate the thread and process IDs, which are\n// used to store the event in the correct process thread entry below.\nconst unpairedAsyncEvents: Types.Events.PipelineReporter[] = [];\n\nconst legacyScreenshotEvents: Types.Events.LegacyScreenshot[] = [];\nconst modernScreenshotEvents: Types.Events.Screenshot[] = [];\nconst syntheticScreenshots: Types.Events.LegacySyntheticScreenshot[] = [];\nlet frameSequenceToTs: Record<string, Types.Timing.Micro> = {};\n\nexport function reset(): void {\n unpairedAsyncEvents.length = 0;\n legacyScreenshotEvents.length = 0;\n syntheticScreenshots.length = 0;\n modernScreenshotEvents.length = 0;\n frameSequenceToTs = {};\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n if (Types.Events.isLegacyScreenshot(event)) {\n legacyScreenshotEvents.push(event);\n } else if (Types.Events.isScreenshot(event)) {\n modernScreenshotEvents.push(event);\n } else if (Types.Events.isPipelineReporter(event)) {\n unpairedAsyncEvents.push(event);\n }\n}\n\nexport async function finalize(): Promise<void> {\n const pipelineReporterEvents = Helpers.Trace.createMatchedSortedSyntheticEvents(unpairedAsyncEvents);\n\n frameSequenceToTs = Object.fromEntries(pipelineReporterEvents.map(evt => {\n const args = evt.args.data.beginEvent.args;\n const frameReporter = 'frame_reporter' in args ? args.frame_reporter : args.chrome_frame_reporter;\n const frameSequenceId = frameReporter.frame_sequence;\n const presentationTs = Types.Timing.Micro(evt.ts + evt.dur);\n return [frameSequenceId, presentationTs];\n }));\n\n for (const snapshotEvent of legacyScreenshotEvents) {\n const {cat, name, ph, pid, tid} = snapshotEvent;\n const syntheticEvent = Helpers.SyntheticEvents.SyntheticEventsManager.registerSyntheticEvent<\n Types.Events.LegacySyntheticScreenshot>({\n rawSourceEvent: snapshotEvent,\n cat,\n name,\n ph,\n pid,\n tid,\n // TODO(paulirish, crbug.com/41363012): investigate why getPresentationTimestamp(snapshotEvent) seems less accurate. Resolve screenshot timing inaccuracy.\n // `getPresentationTimestamp(snapshotEvent) - snapshotEvent.ts` is how many microsec the screenshot should be adjusted to the right/later\n ts: snapshotEvent.ts,\n args: {\n dataUri: `data:image/jpg;base64,${snapshotEvent.args.snapshot}`,\n },\n });\n syntheticScreenshots.push(syntheticEvent);\n }\n}\n\nexport function screenshotImageDataUri(event: Types.Events.LegacySyntheticScreenshot|Types.Events.Screenshot): string {\n if (Types.Events.isLegacySyntheticScreenshot(event)) {\n return event.args.dataUri;\n }\n return `data:image/jpg;base64,${event.args.snapshot}`;\n}\n\n/**\n * Correct the screenshot timestamps\n * The screenshot 'snapshot object' trace event has the \"frame sequence number\" attached as an ID.\n * We match that up with the \"PipelineReporter\" trace events as they terminate at presentation.\n * Presentation == when the pixels hit the screen. AKA Swap on the GPU\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nfunction getPresentationTimestamp(screenshotEvent: Types.Events.LegacyScreenshot): Types.Timing.Micro {\n const frameSequence = parseInt(screenshotEvent.id, 16);\n // If it's 1, then it's an old trace (before https://crrev.com/c/4957973) and cannot be corrected.\n if (frameSequence === 1) {\n return screenshotEvent.ts;\n }\n // The screenshot trace event's `ts` reflects the \"expected display time\" which is ESTIMATE.\n // It is set by the compositor frame sink from the `expected_display_time`, which is based on a previously known\n // frame start PLUS the vsync interval (eg 16.6ms)\n const updatedTs = frameSequenceToTs[frameSequence];\n // Do we always find a match? No...\n // We generally don't match the very first screenshot and, sometimes, the last\n // The very first screenshot is requested immediately (even if nothing is painting). As a result there's no compositor\n // instrumentation running alongside.\n // The last one is sometimes missing as because the trace terminates right before the associated PipelineReporter is emitted.\n return updatedTs ?? screenshotEvent.ts;\n}\n\nexport interface Data {\n // These are nullable because in January 2025 a CL in Chromium\n // crrev.com/c/6197645 landed which changed the format of screenshots. For a\n // given trace, it can have either \"legacy\" screenshot events, or \"modern\"\n // screenshot events, but no trace can ever contain both.\n // So, if either of these arrays are empty, we instead return `null`. This forces consumers to check the presence of the array.\n // Traces can have no screenshots if the trace category is not enabled, so it\n // is possible for a trace to return null for both of these arrays.\n legacySyntheticScreenshots: Types.Events.LegacySyntheticScreenshot[]|null;\n screenshots: Types.Events.Screenshot[]|null;\n}\n// TODO(crbug/41484172): should be readonly\nexport function data(): Data {\n return {\n legacySyntheticScreenshots: syntheticScreenshots.length ? syntheticScreenshots : null,\n screenshots: modernScreenshotEvents.length ? modernScreenshotEvents : null,\n };\n}\n\nexport function deps(): HandlerName[] {\n return ['Meta'];\n}\n"]}
@@ -11,6 +11,7 @@ export interface Script {
11
11
  scriptId: Protocol.Runtime.ScriptId;
12
12
  frame: string;
13
13
  ts: Types.Timing.Micro;
14
+ inline: boolean;
14
15
  url?: string;
15
16
  sourceUrl?: string;
16
17
  content?: string;
@@ -18,9 +19,20 @@ export interface Script {
18
19
  sourceMapUrl?: string;
19
20
  sourceMap?: any;
20
21
  request?: Types.Events.SyntheticNetworkRequest;
22
+ /** Lazily generated - use getScriptGeneratedSizes to access. */
23
+ sizes?: GeneratedFileSizes;
21
24
  }
25
+ type GeneratedFileSizes = {
26
+ errorMessage: string;
27
+ } | {
28
+ files: Record<string, number>;
29
+ unmappedBytes: number;
30
+ totalBytes: number;
31
+ };
22
32
  export declare function deps(): HandlerName[];
23
33
  export declare function reset(): void;
24
34
  export declare function handleEvent(event: Types.Events.Event): void;
35
+ export declare function getScriptGeneratedSizes(script: Script): GeneratedFileSizes | null;
25
36
  export declare function finalize(options: Types.Configuration.ParseOptions): Promise<void>;
26
37
  export declare function data(): ScriptsData;
38
+ export {};
@@ -36,7 +36,7 @@ export function handleEvent(event) {
36
36
  return;
37
37
  }
38
38
  if (Types.Events.isV8SourceRundownEvent(event)) {
39
- const { isolate, scriptId, url, sourceUrl, sourceMapUrl } = event.args.data;
39
+ const { isolate, scriptId, url, sourceUrl, sourceMapUrl, startLine, startColumn } = event.args.data;
40
40
  const script = getOrMakeScript(isolate, scriptId);
41
41
  script.url = url;
42
42
  if (sourceUrl) {
@@ -45,6 +45,7 @@ export function handleEvent(event) {
45
45
  if (sourceMapUrl) {
46
46
  script.sourceMapUrl = sourceMapUrl;
47
47
  }
48
+ script.inline = Boolean(startLine || startColumn);
48
49
  return;
49
50
  }
50
51
  if (Types.Events.isV8SourceRundownSourcesScriptCatchupEvent(event)) {
@@ -72,6 +73,96 @@ function findFrame(meta, frameId) {
72
73
  function findNetworkRequest(networkRequests, script) {
73
74
  return networkRequests.find(request => request.args.data.url === script.url) ?? null;
74
75
  }
76
+ function computeMappingEndColumns(map) {
77
+ const result = new Map();
78
+ const mappings = map.mappings();
79
+ for (let i = 0; i < mappings.length - 1; i++) {
80
+ const mapping = mappings[i];
81
+ const nextMapping = mappings[i + 1];
82
+ if (mapping.lineNumber === nextMapping.lineNumber) {
83
+ result.set(mapping, nextMapping.columnNumber);
84
+ }
85
+ }
86
+ // Now, all but the last mapping on each line will have a value in this map.
87
+ return result;
88
+ }
89
+ /**
90
+ * Using a script's contents and source map, attribute every generated byte to an authored source file.
91
+ */
92
+ function computeGeneratedFileSizes(script) {
93
+ if (!script.sourceMap) {
94
+ throw new Error('expected source map');
95
+ }
96
+ const map = script.sourceMap;
97
+ const content = script.content ?? '';
98
+ const contentLength = content.length;
99
+ const lines = content.split('\n');
100
+ const files = {};
101
+ const totalBytes = contentLength;
102
+ let unmappedBytes = totalBytes;
103
+ const mappingEndCols = computeMappingEndColumns(script.sourceMap);
104
+ for (const mapping of map.mappings()) {
105
+ const source = mapping.sourceURL;
106
+ const lineNum = mapping.lineNumber;
107
+ const colNum = mapping.columnNumber;
108
+ const lastColNum = mappingEndCols.get(mapping);
109
+ // Webpack sometimes emits null mappings.
110
+ // https://github.com/mozilla/source-map/pull/303
111
+ if (!source) {
112
+ continue;
113
+ }
114
+ // Lines and columns are zero-based indices. Visually, lines are shown as a 1-based index.
115
+ const line = lines[lineNum];
116
+ if (line === null || line === undefined) {
117
+ const errorMessage = `${map.url()} mapping for line out of bounds: ${lineNum + 1}`;
118
+ return { errorMessage };
119
+ }
120
+ if (colNum > line.length) {
121
+ const errorMessage = `${map.url()} mapping for column out of bounds: ${lineNum + 1}:${colNum}`;
122
+ return { errorMessage };
123
+ }
124
+ let mappingLength = 0;
125
+ if (lastColNum !== undefined) {
126
+ if (lastColNum > line.length) {
127
+ const errorMessage = `${map.url()} mapping for last column out of bounds: ${lineNum + 1}:${lastColNum}`;
128
+ return { errorMessage };
129
+ }
130
+ mappingLength = lastColNum - colNum;
131
+ }
132
+ else {
133
+ // Add +1 to account for the newline.
134
+ mappingLength = line.length - colNum + 1;
135
+ }
136
+ files[source] = (files[source] || 0) + mappingLength;
137
+ unmappedBytes -= mappingLength;
138
+ }
139
+ return {
140
+ files,
141
+ unmappedBytes,
142
+ totalBytes,
143
+ };
144
+ }
145
+ export function getScriptGeneratedSizes(script) {
146
+ if (script.sourceMap && !script.sizes) {
147
+ script.sizes = computeGeneratedFileSizes(script);
148
+ }
149
+ return script.sizes ?? null;
150
+ }
151
+ function findCachedRawSourceMap(sourceMapUrl, options) {
152
+ if (!sourceMapUrl) {
153
+ return;
154
+ }
155
+ // If loading from disk, check the metadata for source maps.
156
+ // The metadata doesn't store data url source maps.
157
+ const isDataUrl = sourceMapUrl.startsWith('data:');
158
+ if (!options.isFreshRecording && options.metadata?.sourceMaps && !isDataUrl) {
159
+ const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === sourceMapUrl);
160
+ if (cachedSourceMap) {
161
+ return cachedSourceMap.sourceMap;
162
+ }
163
+ }
164
+ return;
165
+ }
75
166
  export async function finalize(options) {
76
167
  const networkRequests = [...networkRequestsHandlerData().byId.values()];
77
168
  for (const script of scriptById.values()) {
@@ -111,6 +202,7 @@ export async function finalize(options) {
111
202
  scriptUrl: sourceUrl,
112
203
  sourceMapUrl: sourceMapUrl,
113
204
  frame: script.frame,
205
+ cachedRawSourceMap: findCachedRawSourceMap(sourceMapUrl, options),
114
206
  };
115
207
  const promise = options.resolveSourceMap(params).then(sourceMap => {
116
208
  if (sourceMap) {
@@ -1 +1 @@
1
- {"version":3,"file":"ScriptsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScriptsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAI/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAC,IAAI,IAAI,0BAA0B,EAAC,MAAM,6BAA6B,CAAC;AAG/E,SAAS,WAAW,CAAC,IAAY,EAAE,GAAW;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACrH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AAqBD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE7C,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU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C,SAA4C,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;QACnF,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,SAAS;QACX,CAAC;QAED,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QAEnC,MAAM,MAAM,GAA+C;YACzD,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,SAAS,EAAE,SAA4C;YACvD,YAAY,EAAE,YAA+C;YAC7D,KAAK,EAAE,MAAM,CAAC,KAA8B;SAC7C,CAAC;QACF,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAChE,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\n// eslint-disable-next-line rulesdir/no-imports-in-directory\nimport type * as SDK from '../../../core/sdk/sdk.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData, type MetaHandlerData} from './MetaHandler.js';\nimport {data as networkRequestsHandlerData} from './NetworkRequestsHandler.js';\nimport type {HandlerName} from './types.js';\n\nfunction completeURL(base: string, url: string): string|null {\n if (url.startsWith('data:') || url.startsWith('blob:') || url.startsWith('javascript:') || url.startsWith('mailto:')) {\n return url;\n }\n\n try {\n return new URL(url, base).href;\n } catch {}\n\n return null;\n}\n\nexport interface ScriptsData {\n /** Note: this is only populated when the \"Enhanced Traces\" feature is enabled. */\n scripts: Script[];\n}\n\nexport interface Script {\n isolate: string;\n scriptId: Protocol.Runtime.ScriptId;\n frame: string;\n ts: Types.Timing.Micro;\n url?: string;\n sourceUrl?: string;\n content?: string;\n /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url. */\n sourceMapUrl?: string;\n sourceMap?: SDK.SourceMap.SourceMap;\n request?: Types.Events.SyntheticNetworkRequest;\n}\n\nconst scriptById = new Map<string, Script>();\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'NetworkRequests'];\n}\n\nexport function reset(): void {\n scriptById.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n const getOrMakeScript = (isolate: string, scriptIdAsNumber: number): Script => {\n const scriptId = String(scriptIdAsNumber) as Protocol.Runtime.ScriptId;\n const key = `${isolate}.${scriptId}`;\n return Platform.MapUtilities.getWithDefault(\n scriptById, key, () => ({isolate, scriptId, frame: '', ts: 0} as Script));\n };\n\n if (Types.Events.isTargetRundownEvent(event) && event.args.data) {\n const {isolate, scriptId, frame} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.frame = frame;\n script.ts = event.ts;\n\n return;\n }\n\n if (Types.Events.isV8SourceRundownEvent(event)) {\n const {isolate, scriptId, url, sourceUrl, sourceMapUrl} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.url = url;\n if (sourceUrl) {\n script.sourceUrl = sourceUrl;\n }\n if (sourceMapUrl) {\n script.sourceMapUrl = sourceMapUrl;\n }\n return;\n }\n\n if (Types.Events.isV8SourceRundownSourcesScriptCatchupEvent(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = sourceText;\n return;\n }\n\n if (Types.Events.isV8SourceRundownSourcesLargeScriptCatchupEvent(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = (script.content ?? '') + sourceText;\n return;\n }\n}\n\nfunction findFrame(meta: MetaHandlerData, frameId: string): Types.Events.TraceFrame|null {\n for (const frames of meta.frameByProcessId?.values()) {\n const frame = frames.get(frameId);\n if (frame) {\n return frame;\n }\n }\n\n return null;\n}\n\nfunction findNetworkRequest(networkRequests: Types.Events.SyntheticNetworkRequest[], script: Script):\n Types.Events.SyntheticNetworkRequest|null {\n return networkRequests.find(request => request.args.data.url === script.url) ?? null;\n}\n\nexport async function finalize(options: Types.Configuration.ParseOptions): Promise<void> {\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\n\n const meta = metaHandlerData();\n\n const promises = [];\n for (const script of scriptById.values()) {\n // No frame or url means the script came from somewhere we don't care about.\n // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,\n // so aren't ignored.\n if (!script.frame || !script.url || !script.sourceMapUrl) {\n continue;\n }\n\n const frameUrl = findFrame(meta, script.frame)?.url as Platform.DevToolsPath.UrlString | undefined;\n if (!frameUrl) {\n continue;\n }\n\n // If there is a `sourceURL` magic comment, resolve the compiledUrl against the frame url.\n // example: `// #sourceURL=foo.js` for target frame https://www.example.com/home -> https://www.example.com/home/foo.js\n let sourceUrl = script.url;\n if (script.sourceUrl) {\n sourceUrl = completeURL(frameUrl, script.sourceUrl) ?? script.sourceUrl;\n }\n\n // Resolve the source map url. The value given by v8 may be relative, so resolve it here.\n // This process should match the one in `SourceMapManager.attachSourceMap`.\n const sourceMapUrl =\n completeURL(sourceUrl as Platform.DevToolsPath.UrlString, script.sourceMapUrl);\n if (!sourceMapUrl) {\n continue;\n }\n\n script.sourceMapUrl = sourceMapUrl;\n\n const params: Types.Configuration.ResolveSourceMapParams = {\n scriptId: script.scriptId,\n scriptUrl: sourceUrl as Platform.DevToolsPath.UrlString,\n sourceMapUrl: sourceMapUrl as Platform.DevToolsPath.UrlString,\n frame: script.frame as Protocol.Page.FrameId,\n };\n const promise = options.resolveSourceMap(params).then(sourceMap => {\n if (sourceMap) {\n script.sourceMap = sourceMap;\n }\n });\n promises.push(promise);\n }\n await Promise.all(promises);\n}\n\nexport function data(): ScriptsData {\n return {\n scripts: [...scriptById.values()],\n };\n}\n"]}
1
+ {"version":3,"file":"ScriptsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/ScriptsHandler.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAE7B,OAAO,KAAK,QAAQ,MAAM,oCAAoC,CAAC;AAI/D,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,IAAI,IAAI,eAAe,EAAuB,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAC,IAAI,IAAI,0BAA0B,EAAC,MAAM,6BAA6B,CAAC;AAG/E,SAAS,WAAW,CAAC,IAAY,EAAE,GAAW;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QACrH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AA4BD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;AAE7C,MAAM,UAAU,IAAI;IAClB,OAAO,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,KAAK;IACnB,UAAU,CAAC,KAAK,EAAE,CAAC;AACrB,CAAC;AAED,MAAM,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Q;YACzB,SAAS,EAAE,SAA4C;YACvD,YAAY,EAAE,YAA+C;YAC7D,KAAK,EAAE,MAAM,CAAC,KAA8B;YAC5C,kBAAkB,EAAE,sBAAsB,CAAC,YAAY,EAAE,OAAO,CAAC;SAClE,CAAC;QACF,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAChE,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;KAClC,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2025 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\n// eslint-disable-next-line rulesdir/no-imports-in-directory\nimport type * as SDK from '../../../core/sdk/sdk.js';\nimport type * as Protocol from '../../../generated/protocol.js';\nimport * as Types from '../types/types.js';\n\nimport {data as metaHandlerData, type MetaHandlerData} from './MetaHandler.js';\nimport {data as networkRequestsHandlerData} from './NetworkRequestsHandler.js';\nimport type {HandlerName} from './types.js';\n\nfunction completeURL(base: string, url: string): string|null {\n if (url.startsWith('data:') || url.startsWith('blob:') || url.startsWith('javascript:') || url.startsWith('mailto:')) {\n return url;\n }\n\n try {\n return new URL(url, base).href;\n } catch {}\n\n return null;\n}\n\nexport interface ScriptsData {\n /** Note: this is only populated when the \"Enhanced Traces\" feature is enabled. */\n scripts: Script[];\n}\n\nexport interface Script {\n isolate: string;\n scriptId: Protocol.Runtime.ScriptId;\n frame: string;\n ts: Types.Timing.Micro;\n inline: boolean;\n url?: string;\n sourceUrl?: string;\n content?: string;\n /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url. */\n sourceMapUrl?: string;\n sourceMap?: SDK.SourceMap.SourceMap;\n request?: Types.Events.SyntheticNetworkRequest;\n /** Lazily generated - use getScriptGeneratedSizes to access. */\n sizes?: GeneratedFileSizes;\n}\n\ntype GeneratedFileSizes = {\n errorMessage: string,\n}|{files: Record<string, number>, unmappedBytes: number, totalBytes: number};\n\nconst scriptById = new Map<string, Script>();\n\nexport function deps(): HandlerName[] {\n return ['Meta', 'NetworkRequests'];\n}\n\nexport function reset(): void {\n scriptById.clear();\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n const getOrMakeScript = (isolate: string, scriptIdAsNumber: number): Script => {\n const scriptId = String(scriptIdAsNumber) as Protocol.Runtime.ScriptId;\n const key = `${isolate}.${scriptId}`;\n return Platform.MapUtilities.getWithDefault(\n scriptById, key, () => ({isolate, scriptId, frame: '', ts: 0} as Script));\n };\n\n if (Types.Events.isTargetRundownEvent(event) && event.args.data) {\n const {isolate, scriptId, frame} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.frame = frame;\n script.ts = event.ts;\n\n return;\n }\n\n if (Types.Events.isV8SourceRundownEvent(event)) {\n const {isolate, scriptId, url, sourceUrl, sourceMapUrl, startLine, startColumn} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.url = url;\n if (sourceUrl) {\n script.sourceUrl = sourceUrl;\n }\n if (sourceMapUrl) {\n script.sourceMapUrl = sourceMapUrl;\n }\n script.inline = Boolean(startLine || startColumn);\n return;\n }\n\n if (Types.Events.isV8SourceRundownSourcesScriptCatchupEvent(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = sourceText;\n return;\n }\n\n if (Types.Events.isV8SourceRundownSourcesLargeScriptCatchupEvent(event)) {\n const {isolate, scriptId, sourceText} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.content = (script.content ?? '') + sourceText;\n return;\n }\n}\n\nfunction findFrame(meta: MetaHandlerData, frameId: string): Types.Events.TraceFrame|null {\n for (const frames of meta.frameByProcessId?.values()) {\n const frame = frames.get(frameId);\n if (frame) {\n return frame;\n }\n }\n\n return null;\n}\n\nfunction findNetworkRequest(networkRequests: Types.Events.SyntheticNetworkRequest[], script: Script):\n Types.Events.SyntheticNetworkRequest|null {\n return networkRequests.find(request => request.args.data.url === script.url) ?? null;\n}\n\nfunction computeMappingEndColumns(map: SDK.SourceMap.SourceMap): Map<SDK.SourceMap.SourceMapEntry, number> {\n const result = new Map<SDK.SourceMap.SourceMapEntry, number>();\n\n const mappings = map.mappings();\n for (let i = 0; i < mappings.length - 1; i++) {\n const mapping = mappings[i];\n const nextMapping = mappings[i + 1];\n if (mapping.lineNumber === nextMapping.lineNumber) {\n result.set(mapping, nextMapping.columnNumber);\n }\n }\n\n // Now, all but the last mapping on each line will have a value in this map.\n return result;\n}\n\n/**\n * Using a script's contents and source map, attribute every generated byte to an authored source file.\n */\nfunction computeGeneratedFileSizes(script: Script): GeneratedFileSizes {\n if (!script.sourceMap) {\n throw new Error('expected source map');\n }\n\n const map = script.sourceMap;\n const content = script.content ?? '';\n const contentLength = content.length;\n const lines = content.split('\\n');\n const files: Record<string, number> = {};\n const totalBytes = contentLength;\n let unmappedBytes = totalBytes;\n\n const mappingEndCols = computeMappingEndColumns(script.sourceMap);\n\n for (const mapping of map.mappings()) {\n const source = mapping.sourceURL;\n const lineNum = mapping.lineNumber;\n const colNum = mapping.columnNumber;\n const lastColNum = mappingEndCols.get(mapping);\n\n // Webpack sometimes emits null mappings.\n // https://github.com/mozilla/source-map/pull/303\n if (!source) {\n continue;\n }\n\n // Lines and columns are zero-based indices. Visually, lines are shown as a 1-based index.\n\n const line = lines[lineNum];\n if (line === null || line === undefined) {\n const errorMessage = `${map.url()} mapping for line out of bounds: ${lineNum + 1}`;\n return {errorMessage};\n }\n\n if (colNum > line.length) {\n const errorMessage = `${map.url()} mapping for column out of bounds: ${lineNum + 1}:${colNum}`;\n return {errorMessage};\n }\n\n let mappingLength = 0;\n if (lastColNum !== undefined) {\n if (lastColNum > line.length) {\n const errorMessage = `${map.url()} mapping for last column out of bounds: ${lineNum + 1}:${lastColNum}`;\n return {errorMessage};\n }\n mappingLength = lastColNum - colNum;\n } else {\n // Add +1 to account for the newline.\n mappingLength = line.length - colNum + 1;\n }\n files[source] = (files[source] || 0) + mappingLength;\n unmappedBytes -= mappingLength;\n }\n\n return {\n files,\n unmappedBytes,\n totalBytes,\n };\n}\n\nexport function getScriptGeneratedSizes(script: Script): GeneratedFileSizes|null {\n if (script.sourceMap && !script.sizes) {\n script.sizes = computeGeneratedFileSizes(script);\n }\n\n return script.sizes ?? null;\n}\n\nfunction findCachedRawSourceMap(\n sourceMapUrl: string, options: Types.Configuration.ParseOptions): SDK.SourceMap.SourceMapV3|undefined {\n if (!sourceMapUrl) {\n return;\n }\n\n // If loading from disk, check the metadata for source maps.\n // The metadata doesn't store data url source maps.\n const isDataUrl = sourceMapUrl.startsWith('data:');\n if (!options.isFreshRecording && options.metadata?.sourceMaps && !isDataUrl) {\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === sourceMapUrl);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n }\n\n return;\n}\n\nexport async function finalize(options: Types.Configuration.ParseOptions): Promise<void> {\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\n\n const meta = metaHandlerData();\n\n const promises = [];\n for (const script of scriptById.values()) {\n // No frame or url means the script came from somewhere we don't care about.\n // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,\n // so aren't ignored.\n if (!script.frame || !script.url || !script.sourceMapUrl) {\n continue;\n }\n\n const frameUrl = findFrame(meta, script.frame)?.url as Platform.DevToolsPath.UrlString | undefined;\n if (!frameUrl) {\n continue;\n }\n\n // If there is a `sourceURL` magic comment, resolve the compiledUrl against the frame url.\n // example: `// #sourceURL=foo.js` for target frame https://www.example.com/home -> https://www.example.com/home/foo.js\n let sourceUrl = script.url;\n if (script.sourceUrl) {\n sourceUrl = completeURL(frameUrl, script.sourceUrl) ?? script.sourceUrl;\n }\n\n // Resolve the source map url. The value given by v8 may be relative, so resolve it here.\n // This process should match the one in `SourceMapManager.attachSourceMap`.\n const sourceMapUrl =\n completeURL(sourceUrl as Platform.DevToolsPath.UrlString, script.sourceMapUrl);\n if (!sourceMapUrl) {\n continue;\n }\n\n script.sourceMapUrl = sourceMapUrl;\n\n const params: Types.Configuration.ResolveSourceMapParams = {\n scriptId: script.scriptId,\n scriptUrl: sourceUrl as Platform.DevToolsPath.UrlString,\n sourceMapUrl: sourceMapUrl as Platform.DevToolsPath.UrlString,\n frame: script.frame as Protocol.Page.FrameId,\n cachedRawSourceMap: findCachedRawSourceMap(sourceMapUrl, options),\n };\n const promise = options.resolveSourceMap(params).then(sourceMap => {\n if (sourceMap) {\n script.sourceMap = sourceMap;\n }\n });\n promises.push(promise);\n }\n await Promise.all(promises);\n}\n\nexport function data(): ScriptsData {\n return {\n scripts: [...scriptById.values()],\n };\n}\n"]}
@@ -18,6 +18,7 @@
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
20
  "noUnusedLocals": false,
21
+ "noUnusedParameters": true,
21
22
  "outDir": ".",
22
23
  "rootDir": "../../../../../../../front_end/models/trace/handlers",
23
24
  "skipLibCheck": true,
@@ -32,8 +33,7 @@
32
33
  "../../../../../../../front_end/models/trace/handlers/handlers.ts",
33
34
  "../../../../../../../front_end/legacy/legacy-defs.d.ts",
34
35
  "../../../../../../../front_end/global_typings/global_defs.d.ts",
35
- "../../../../../../../node_modules/@types/filesystem/index.d.ts",
36
- "../../../../../../../node_modules/@types/wicg-task-scheduling/index.d.ts"
36
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts"
37
37
  ],
38
38
  "references": [
39
39
  {
@@ -18,6 +18,7 @@
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
20
  "noUnusedLocals": false,
21
+ "noUnusedParameters": true,
21
22
  "outDir": ".",
22
23
  "rootDir": "../../../../../../../front_end/models/trace/handlers",
23
24
  "skipLibCheck": true,
@@ -56,7 +57,6 @@
56
57
  "../../../../../../../front_end/models/trace/handlers/ScreenshotsHandler.ts",
57
58
  "../../../../../../../front_end/models/trace/handlers/ScriptsHandler.ts",
58
59
  "../../../../../../../front_end/models/trace/handlers/SelectorStatsHandler.ts",
59
- "../../../../../../../front_end/models/trace/handlers/ServerTimingsHandler.ts",
60
60
  "../../../../../../../front_end/models/trace/handlers/Threads.ts",
61
61
  "../../../../../../../front_end/models/trace/handlers/UserInteractionsHandler.ts",
62
62
  "../../../../../../../front_end/models/trace/handlers/UserTimingsHandler.ts",
@@ -66,8 +66,7 @@
66
66
  "../../../../../../../front_end/models/trace/handlers/types.ts",
67
67
  "../../../../../../../front_end/legacy/legacy-defs.d.ts",
68
68
  "../../../../../../../front_end/global_typings/global_defs.d.ts",
69
- "../../../../../../../node_modules/@types/filesystem/index.d.ts",
70
- "../../../../../../../node_modules/@types/wicg-task-scheduling/index.d.ts"
69
+ "../../../../../../../node_modules/@types/filesystem/index.d.ts"
71
70
  ],
72
71
  "references": [
73
72
  {
@@ -19,3 +19,8 @@ export declare const NON_NETWORK_SCHEMES: string[];
19
19
  * {no-cache: true, no-store: true, max-age: 0, no-transform: true, private: true}
20
20
  */
21
21
  export declare function parseCacheControl(header: string | null): CacheControl | null;
22
+ /**
23
+ * Is the host localhost-enough to satisfy the "secure context" definition
24
+ * https://github.com/GoogleChrome/lighthouse/pull/11766#discussion_r582340683
25
+ */
26
+ export declare function isSyntheticNetworkRequestLocalhost(event: SyntheticNetworkRequest): boolean;
@@ -83,4 +83,21 @@ export function parseCacheControl(header) {
83
83
  }
84
84
  return cacheControlOptions;
85
85
  }
86
+ const SECURE_LOCALHOST_DOMAINS = ['localhost', '127.0.0.1'];
87
+ /**
88
+ * Is the host localhost-enough to satisfy the "secure context" definition
89
+ * https://github.com/GoogleChrome/lighthouse/pull/11766#discussion_r582340683
90
+ */
91
+ export function isSyntheticNetworkRequestLocalhost(event) {
92
+ try {
93
+ const hostname = new URL(event.args.data.url).hostname;
94
+ // Any hostname terminating in `.localhost` is considered to be local.
95
+ // https://w3c.github.io/webappsec-secure-contexts/#localhost
96
+ // This method doesn't consider IPs that resolve to loopback, IPv6 or other loopback edgecases
97
+ return SECURE_LOCALHOST_DOMAINS.includes(hostname) || hostname.endsWith('.localhost');
98
+ }
99
+ catch {
100
+ return false;
101
+ }
102
+ }
86
103
  //# sourceMappingURL=Network.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Network.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/Network.ts"],"names":[],"mappings":"AAMA,6DAA6D;AAC7D,oCAAoC;AACpC,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAC/E,cAAc;AACd,6EAA6E;AAC7E,8EAA8E;AAC9E,0DAA0D;AAC1D,2EAA2E;AAC3E,4EAA4E;AAC5E,iCAAiC;AACjC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAiB;IACzD,cAAc;IACd,mCAAmC;IACnC,sBAAsB;CACvB,CAAC,CAAC;AAEH,MAAM,UAAU,4CAA4C,CAAC,KAA8B;IACzF,OAAO,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAoC;;;;CAI1E,CAAC,CAAC;AAEH,MAAM,UAAU,qCAAqC,CAAC,KAA8B;IAClF,OAAO,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC/D,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BAAmB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;gBACvC,MAAM;YACR,KAAK,UAAU;gBACb,mBAAmB,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;gBACvC,MAAM;YACR,KAAK,iBAAiB;gBACpB,mBAAmB,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC;gBAC9C,MAAM;YACR,KAAK,SAAS;gBACZ,mBAAmB,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;gBACtC,MAAM;YACR;gBACE,4BAA4B;gBAC5B,MAAM;QACV,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC7B,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport * as Protocol from '../../../generated/protocol.js';\nimport type {RenderBlocking, SyntheticNetworkRequest} from '../types/TraceEvents.js';\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<RenderBlocking>([\n 'non_blocking',\n 'dynamically_injected_non_blocking',\n 'potentially_blocking',\n]);\n\nexport function isSyntheticNetworkRequestEventRenderBlocking(event: SyntheticNetworkRequest): boolean {\n return !NON_RENDER_BLOCKING_VALUES.has(event.args.data.renderBlocking);\n}\n\nconst HIGH_NETWORK_PRIORITIES = new Set<Protocol.Network.ResourcePriority>([\n Protocol.Network.ResourcePriority.VeryHigh,\n Protocol.Network.ResourcePriority.High,\n Protocol.Network.ResourcePriority.Medium,\n]);\n\nexport function isSyntheticNetworkRequestHighPriority(event: SyntheticNetworkRequest): boolean {\n return HIGH_NETWORK_PRIORITIES.has(event.args.data.priority);\n}\n\nexport interface CacheControl {\n 'max-age'?: number;\n 'no-cache'?: boolean;\n 'no-store'?: boolean;\n 'must-revalidate'?: boolean;\n // eslint-disable-next-line @stylistic/quote-props\n 'private'?: boolean;\n}\n\nexport const CACHEABLE_STATUS_CODES = new Set([200, 203, 206]);\n\n/** @type {Set<LH.Crdp.Network.ResourceType>} */\nexport const STATIC_RESOURCE_TYPES = new Set([\n Protocol.Network.ResourceType.Font,\n Protocol.Network.ResourceType.Image,\n Protocol.Network.ResourceType.Media,\n Protocol.Network.ResourceType.Script,\n Protocol.Network.ResourceType.Stylesheet,\n]);\n\nexport const NON_NETWORK_SCHEMES = [\n 'blob', // @see https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL\n 'data', // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs\n 'intent', // @see https://developer.chrome.com/docs/multidevice/android/intents/\n 'file', // @see https://en.wikipedia.org/wiki/File_URI_scheme\n 'filesystem', // @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystem\n 'chrome-extension',\n];\n\n/**\n * Parses Cache-Control directives based on https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control\n * eg. 'no-cache, no-store, max-age=0, no-transform, private' will return\n * {no-cache: true, no-store: true, max-age: 0, no-transform: true, private: true}\n */\nexport function parseCacheControl(header: string|null): CacheControl|null {\n if (!header) {\n return null;\n }\n\n const directives = header.split(',').map(directive => directive.trim());\n const cacheControlOptions: CacheControl = {};\n\n for (const directive of directives) {\n const [key, value] = directive.split('=').map(part => part.trim());\n\n switch (key) {\n case 'max-age': {\n const maxAge = parseInt(value, 10);\n if (!isNaN(maxAge)) {\n cacheControlOptions['max-age'] = maxAge;\n }\n break;\n }\n case 'no-cache':\n cacheControlOptions['no-cache'] = true;\n break;\n case 'no-store':\n cacheControlOptions['no-store'] = true;\n break;\n case 'must-revalidate':\n cacheControlOptions['must-revalidate'] = true;\n break;\n case 'private':\n cacheControlOptions['private'] = true;\n break;\n default:\n // Ignore unknown directives\n break;\n }\n }\n\n return cacheControlOptions;\n}\n"]}
1
+ {"version":3,"file":"Network.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/helpers/Network.ts"],"names":[],"mappings":"AAMA,6DAA6D;AAC7D,oCAAoC;AACpC,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAC/E,cAAc;AACd,6EAA6E;AAC7E,8EAA8E;AAC9E,0DAA0D;AAC1D,2EAA2E;AAC3E,4EAA4E;AAC5E,iCAAiC;AACjC,MAAM,0BAA0B,GAAG,IAAI,GAAG,CAAiB;IACzD,cAAc;IACd,mCAAmC;IACnC,sBAAsB;CACvB,CAAC,CAAC;AAEH,MAAM,UAAU,4CAA4C,CAAC,KAA8B;IACzF,OAAO,CAAC,0BAA0B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AACzE,CAAC;AAED,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAoC;;;;CAI1E,CAAC,CAAC;AAEH,MAAM,UAAU,qCAAqC,CAAC,KAA8B;IAClF,OAAO,uBAAuB,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC/D,CAAC;AAWD,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAE/D,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;;;;;;CAM5C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,MAAM,EAAS,4EAA4E;IAC3F,MAAM,EAAS,kFAAkF;IACjG,QAAQ,EAAO,sEAAsE;IACrF,MAAM,EAAS,qDAAqD;IACpE,YAAY,EAAG,mEAAmE;IAClF,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,CAAC;AAED,MAAM,wBAAwB,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAE5D;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,KAA8B;IAC/E,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACvD,sEAAsE;QACtE,6DAA6D;QAC7D,8FAA8F;QAC9F,OAAO,wBAAwB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\nimport * as Protocol from '../../../generated/protocol.js';\nimport type {RenderBlocking, SyntheticNetworkRequest} from '../types/TraceEvents.js';\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<RenderBlocking>([\n 'non_blocking',\n 'dynamically_injected_non_blocking',\n 'potentially_blocking',\n]);\n\nexport function isSyntheticNetworkRequestEventRenderBlocking(event: SyntheticNetworkRequest): boolean {\n return !NON_RENDER_BLOCKING_VALUES.has(event.args.data.renderBlocking);\n}\n\nconst HIGH_NETWORK_PRIORITIES = new Set<Protocol.Network.ResourcePriority>([\n Protocol.Network.ResourcePriority.VeryHigh,\n Protocol.Network.ResourcePriority.High,\n Protocol.Network.ResourcePriority.Medium,\n]);\n\nexport function isSyntheticNetworkRequestHighPriority(event: SyntheticNetworkRequest): boolean {\n return HIGH_NETWORK_PRIORITIES.has(event.args.data.priority);\n}\n\nexport interface CacheControl {\n 'max-age'?: number;\n 'no-cache'?: boolean;\n 'no-store'?: boolean;\n 'must-revalidate'?: boolean;\n // eslint-disable-next-line @stylistic/quote-props\n 'private'?: boolean;\n}\n\nexport const CACHEABLE_STATUS_CODES = new Set([200, 203, 206]);\n\n/** @type {Set<LH.Crdp.Network.ResourceType>} */\nexport const STATIC_RESOURCE_TYPES = new Set([\n Protocol.Network.ResourceType.Font,\n Protocol.Network.ResourceType.Image,\n Protocol.Network.ResourceType.Media,\n Protocol.Network.ResourceType.Script,\n Protocol.Network.ResourceType.Stylesheet,\n]);\n\nexport const NON_NETWORK_SCHEMES = [\n 'blob', // @see https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL\n 'data', // @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs\n 'intent', // @see https://developer.chrome.com/docs/multidevice/android/intents/\n 'file', // @see https://en.wikipedia.org/wiki/File_URI_scheme\n 'filesystem', // @see https://developer.mozilla.org/en-US/docs/Web/API/FileSystem\n 'chrome-extension',\n];\n\n/**\n * Parses Cache-Control directives based on https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control\n * eg. 'no-cache, no-store, max-age=0, no-transform, private' will return\n * {no-cache: true, no-store: true, max-age: 0, no-transform: true, private: true}\n */\nexport function parseCacheControl(header: string|null): CacheControl|null {\n if (!header) {\n return null;\n }\n\n const directives = header.split(',').map(directive => directive.trim());\n const cacheControlOptions: CacheControl = {};\n\n for (const directive of directives) {\n const [key, value] = directive.split('=').map(part => part.trim());\n\n switch (key) {\n case 'max-age': {\n const maxAge = parseInt(value, 10);\n if (!isNaN(maxAge)) {\n cacheControlOptions['max-age'] = maxAge;\n }\n break;\n }\n case 'no-cache':\n cacheControlOptions['no-cache'] = true;\n break;\n case 'no-store':\n cacheControlOptions['no-store'] = true;\n break;\n case 'must-revalidate':\n cacheControlOptions['must-revalidate'] = true;\n break;\n case 'private':\n cacheControlOptions['private'] = true;\n break;\n default:\n // Ignore unknown directives\n break;\n }\n }\n\n return cacheControlOptions;\n}\n\nconst SECURE_LOCALHOST_DOMAINS = ['localhost', '127.0.0.1'];\n\n/**\n * Is the host localhost-enough to satisfy the \"secure context\" definition\n * https://github.com/GoogleChrome/lighthouse/pull/11766#discussion_r582340683\n */\nexport function isSyntheticNetworkRequestLocalhost(event: SyntheticNetworkRequest): boolean {\n try {\n const hostname = new URL(event.args.data.url).hostname;\n // Any hostname terminating in `.localhost` is considered to be local.\n // https://w3c.github.io/webappsec-secure-contexts/#localhost\n // This method doesn't consider IPs that resolve to loopback, IPv6 or other loopback edgecases\n return SECURE_LOCALHOST_DOMAINS.includes(hostname) || hostname.endsWith('.localhost');\n } catch {\n return false;\n }\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  // found in the LICENSE file.
4
4
  import * as Types from '../types/types.js';
5
5
  import { milliToMicro } from './Timing.js';
6
- import { extractSampleTraceId, makeProfileCall, mergeEventsInOrder } from './Trace.js';
6
+ import { extractSampleTraceId, makeProfileCall, mergeEventsInOrder, sortTraceEventsInPlace } from './Trace.js';
7
7
  /**
8
8
  * This is a helper that integrates CPU profiling data coming in the
9
9
  * shape of samples, with trace events. Samples indicate what the JS
@@ -65,12 +65,6 @@ export class SamplesIntegrator {
65
65
  * in the stack before the event came.
66
66
  */
67
67
  #lockedJsStackDepth = [];
68
- /**
69
- * For samples with a trace id, creates a profile call and keeps it
70
- * in a record keyed by that id. The value is typed as an union with
71
- * undefined to avoid nullish accesses when a key is not present.
72
- */
73
- #callsByTraceIds = {};
74
68
  /**
75
69
  * Used to keep track when samples should be integrated even if they
76
70
  * are not children of invocation trace events. This is useful in
@@ -155,6 +149,7 @@ export class SamplesIntegrator {
155
149
  this.#onTraceEventEnd(last);
156
150
  }
157
151
  }
152
+ sortTraceEventsInPlace(this.jsSampleEvents);
158
153
  return this.#constructedProfileCalls;
159
154
  }
160
155
  #onTraceEventStart(event) {
@@ -220,7 +215,6 @@ export class SamplesIntegrator {
220
215
  callsFromProfileSamples() {
221
216
  const samples = this.#profileModel.samples;
222
217
  const timestamps = this.#profileModel.timestamps;
223
- const debugModeEnabled = this.#engineConfig.debugMode;
224
218
  if (!samples) {
225
219
  return [];
226
220
  }
@@ -232,17 +226,9 @@ export class SamplesIntegrator {
232
226
  if (!node) {
233
227
  continue;
234
228
  }
235
- const maybeTraceId = this.#profileModel.traceIds?.[i];
236
229
  const call = makeProfileCall(node, this.#profileId, i, timestamp, this.#processId, this.#threadId);
237
- // Separate samples with trace ids so that they are only used when
238
- // processing the owner event.
239
- if (maybeTraceId === undefined) {
240
- calls.push(call);
241
- }
242
- else {
243
- this.#callsByTraceIds[maybeTraceId] = call;
244
- }
245
- if (debugModeEnabled) {
230
+ calls.push(call);
231
+ if (this.#engineConfig.debugMode) {
246
232
  const traceId = this.#profileModel.traceIds?.[i];
247
233
  this.jsSampleEvents.push(this.#makeJSSampleEvent(call, timestamp, traceId));
248
234
  }
@@ -299,6 +285,18 @@ export class SamplesIntegrator {
299
285
  }
300
286
  return callFrames;
301
287
  }
288
+ #getStackForSampleTraceId(traceId, timestamp) {
289
+ const nodeId = this.#profileModel.traceIds?.[traceId];
290
+ const node = nodeId && this.#profileModel.nodeById(nodeId);
291
+ const maybeCallForTraceId = node && makeProfileCall(node, this.#profileId, -1, timestamp, this.#processId, this.#threadId);
292
+ if (!maybeCallForTraceId) {
293
+ return null;
294
+ }
295
+ if (this.#engineConfig.debugMode) {
296
+ this.jsSampleEvents.push(this.#makeJSSampleEvent(maybeCallForTraceId, timestamp, traceId));
297
+ }
298
+ return this.#makeProfileCallsForStack(maybeCallForTraceId);
299
+ }
302
300
  /**
303
301
  * Update tracked stack using this event's call stack.
304
302
  */
@@ -308,11 +306,9 @@ export class SamplesIntegrator {
308
306
  stackTrace = this.#makeProfileCallsForStack(event);
309
307
  }
310
308
  const traceId = extractSampleTraceId(event);
311
- if (traceId !== null) {
312
- const maybeCallForTraceId = this.#callsByTraceIds[traceId];
313
- if (maybeCallForTraceId) {
314
- stackTrace = this.#makeProfileCallsForStack(maybeCallForTraceId, event.ts);
315
- }
309
+ const maybeCallForTraceId = traceId && this.#getStackForSampleTraceId(traceId, event.ts);
310
+ if (maybeCallForTraceId) {
311
+ stackTrace = maybeCallForTraceId;
316
312
  }
317
313
  SamplesIntegrator.filterStackFrames(stackTrace, this.#engineConfig);
318
314
  const endTime = event.ts + (event.dur || 0);