@paulirish/trace_engine 0.0.52 → 0.0.53

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 (177) hide show
  1. package/.tmp/tsbuildinfo/tsconfig.tsbuildinfo +1 -1
  2. package/core/platform/DOMUtilities.d.ts +8 -0
  3. package/core/platform/DOMUtilities.js +14 -0
  4. package/core/platform/DOMUtilities.js.map +1 -1
  5. package/core/platform/StringUtilities.d.ts +1 -5
  6. package/core/platform/StringUtilities.js.map +1 -1
  7. package/core/platform/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  8. package/core/platform/platform-tsconfig.json +2 -2
  9. package/generated/protocol.d.ts +202 -20
  10. package/locales/af.json +11 -5
  11. package/locales/am.json +7 -1
  12. package/locales/ar.json +7 -1
  13. package/locales/as.json +7 -1
  14. package/locales/az.json +7 -1
  15. package/locales/be.json +7 -1
  16. package/locales/bg.json +7 -1
  17. package/locales/bn.json +7 -1
  18. package/locales/bs.json +7 -1
  19. package/locales/ca.json +7 -1
  20. package/locales/cs.json +7 -1
  21. package/locales/cy.json +7 -1
  22. package/locales/da.json +7 -1
  23. package/locales/de.json +7 -1
  24. package/locales/el.json +7 -1
  25. package/locales/en-GB.json +7 -1
  26. package/locales/en-US.json +49 -7
  27. package/locales/en-XL.json +49 -7
  28. package/locales/es-419.json +7 -1
  29. package/locales/es.json +7 -1
  30. package/locales/et.json +7 -1
  31. package/locales/eu.json +7 -1
  32. package/locales/fa.json +7 -1
  33. package/locales/fi.json +7 -1
  34. package/locales/fil.json +7 -1
  35. package/locales/fr-CA.json +7 -1
  36. package/locales/fr.json +7 -1
  37. package/locales/gl.json +7 -1
  38. package/locales/gu.json +7 -1
  39. package/locales/he.json +7 -1
  40. package/locales/hi.json +7 -1
  41. package/locales/hr.json +7 -1
  42. package/locales/hu.json +7 -1
  43. package/locales/hy.json +7 -1
  44. package/locales/id.json +7 -1
  45. package/locales/is.json +7 -1
  46. package/locales/it.json +7 -1
  47. package/locales/ja.json +7 -1
  48. package/locales/ka.json +7 -1
  49. package/locales/kk.json +7 -1
  50. package/locales/km.json +7 -1
  51. package/locales/kn.json +7 -1
  52. package/locales/ko.json +7 -1
  53. package/locales/ky.json +7 -1
  54. package/locales/lo.json +7 -1
  55. package/locales/lt.json +7 -1
  56. package/locales/lv.json +7 -1
  57. package/locales/mk.json +7 -1
  58. package/locales/ml.json +7 -1
  59. package/locales/mn.json +7 -1
  60. package/locales/mr.json +7 -1
  61. package/locales/ms.json +7 -1
  62. package/locales/my.json +7 -1
  63. package/locales/ne.json +7 -1
  64. package/locales/nl.json +7 -1
  65. package/locales/no.json +7 -1
  66. package/locales/or.json +7 -1
  67. package/locales/pa.json +7 -1
  68. package/locales/pl.json +7 -1
  69. package/locales/pt-PT.json +7 -1
  70. package/locales/pt.json +7 -1
  71. package/locales/ro.json +7 -1
  72. package/locales/ru.json +7 -1
  73. package/locales/si.json +7 -1
  74. package/locales/sk.json +7 -1
  75. package/locales/sl.json +7 -1
  76. package/locales/sq.json +7 -1
  77. package/locales/sr-Latn.json +7 -1
  78. package/locales/sr.json +7 -1
  79. package/locales/sv.json +7 -1
  80. package/locales/sw.json +7 -1
  81. package/locales/ta.json +7 -1
  82. package/locales/te.json +7 -1
  83. package/locales/th.json +7 -1
  84. package/locales/tr.json +7 -1
  85. package/locales/uk.json +7 -1
  86. package/locales/ur.json +7 -1
  87. package/locales/uz.json +7 -1
  88. package/locales/vi.json +7 -1
  89. package/locales/zh-HK.json +7 -1
  90. package/locales/zh-TW.json +7 -1
  91. package/locales/zh.json +7 -1
  92. package/locales/zu.json +7 -1
  93. package/models/cpu_profile/cpu_profile-tsconfig.json +2 -2
  94. package/models/cpu_profile/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  95. package/models/trace/LanternComputationData.js +3 -3
  96. package/models/trace/LanternComputationData.js.map +1 -1
  97. package/models/trace/Processor.d.ts +1 -3
  98. package/models/trace/Processor.js +1 -1
  99. package/models/trace/Processor.js.map +1 -1
  100. package/models/trace/TracingManager.js.map +1 -1
  101. package/models/trace/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  102. package/models/trace/extras/StackTraceForEvent.js +24 -16
  103. package/models/trace/extras/StackTraceForEvent.js.map +1 -1
  104. package/models/trace/extras/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  105. package/models/trace/extras/extras-tsconfig.json +2 -2
  106. package/models/trace/handlers/FramesHandler.js.map +1 -1
  107. package/models/trace/handlers/NetworkRequestsHandler.d.ts +1 -0
  108. package/models/trace/handlers/NetworkRequestsHandler.js +37 -23
  109. package/models/trace/handlers/NetworkRequestsHandler.js.map +1 -1
  110. package/models/trace/handlers/ScreenshotsHandler.js +0 -1
  111. package/models/trace/handlers/ScreenshotsHandler.js.map +1 -1
  112. package/models/trace/handlers/ScriptsHandler.d.ts +5 -1
  113. package/models/trace/handlers/ScriptsHandler.js +51 -20
  114. package/models/trace/handlers/ScriptsHandler.js.map +1 -1
  115. package/models/trace/handlers/WarningsHandler.js +14 -2
  116. package/models/trace/handlers/WarningsHandler.js.map +1 -1
  117. package/models/trace/handlers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  118. package/models/trace/handlers/handlers-tsconfig.json +2 -2
  119. package/models/trace/handlers/helpers.js +3 -0
  120. package/models/trace/handlers/helpers.js.map +1 -1
  121. package/models/trace/handlers/types.d.ts +2 -6
  122. package/models/trace/handlers/types.js.map +1 -1
  123. package/models/trace/helpers/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  124. package/models/trace/helpers/helpers-tsconfig.json +2 -2
  125. package/models/trace/insights/Cache.js +7 -6
  126. package/models/trace/insights/Cache.js.map +1 -1
  127. package/models/trace/insights/Common.js +3 -0
  128. package/models/trace/insights/Common.js.map +1 -1
  129. package/models/trace/insights/DocumentLatency.d.ts +7 -3
  130. package/models/trace/insights/DocumentLatency.js +24 -8
  131. package/models/trace/insights/DocumentLatency.js.map +1 -1
  132. package/models/trace/insights/LCPPhases.d.ts +1 -1
  133. package/models/trace/insights/LCPPhases.js +1 -1
  134. package/models/trace/insights/LCPPhases.js.map +1 -1
  135. package/models/trace/insights/LegacyJavaScript.d.ts +1 -1
  136. package/models/trace/insights/LegacyJavaScript.js +1 -1
  137. package/models/trace/insights/LegacyJavaScript.js.map +1 -1
  138. package/models/trace/insights/NetworkDependencyTree.d.ts +151 -3
  139. package/models/trace/insights/NetworkDependencyTree.js +648 -10
  140. package/models/trace/insights/NetworkDependencyTree.js.map +1 -1
  141. package/models/trace/insights/RenderBlocking.js +1 -1
  142. package/models/trace/insights/RenderBlocking.js.map +1 -1
  143. package/models/trace/insights/ThirdParties.d.ts +1 -1
  144. package/models/trace/insights/ThirdParties.js +1 -1
  145. package/models/trace/insights/ThirdParties.js.map +1 -1
  146. package/models/trace/insights/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  147. package/models/trace/insights/insights-tsconfig.json +2 -2
  148. package/models/trace/insights/types.d.ts +2 -0
  149. package/models/trace/insights/types.js.map +1 -1
  150. package/models/trace/lantern/core/core-tsconfig.json +2 -2
  151. package/models/trace/lantern/core/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  152. package/models/trace/lantern/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  153. package/models/trace/lantern/graph/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  154. package/models/trace/lantern/graph/graph-tsconfig.json +2 -2
  155. package/models/trace/lantern/lantern-tsconfig.json +2 -2
  156. package/models/trace/lantern/metrics/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  157. package/models/trace/lantern/metrics/metrics-tsconfig.json +2 -2
  158. package/models/trace/lantern/simulation/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  159. package/models/trace/lantern/simulation/simulation-tsconfig.json +2 -2
  160. package/models/trace/lantern/types/Lantern.d.ts +4 -7
  161. package/models/trace/lantern/types/Lantern.js +1 -0
  162. package/models/trace/lantern/types/Lantern.js.map +1 -1
  163. package/models/trace/lantern/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  164. package/models/trace/lantern/types/types-tsconfig.json +2 -2
  165. package/models/trace/trace-tsconfig.json +2 -2
  166. package/models/trace/types/Configuration.d.ts +2 -0
  167. package/models/trace/types/Configuration.js.map +1 -1
  168. package/models/trace/types/Extensions.d.ts +1 -3
  169. package/models/trace/types/Extensions.js.map +1 -1
  170. package/models/trace/types/File.d.ts +2 -1
  171. package/models/trace/types/File.js.map +1 -1
  172. package/models/trace/types/TraceEvents.d.ts +49 -22
  173. package/models/trace/types/TraceEvents.js +6 -0
  174. package/models/trace/types/TraceEvents.js.map +1 -1
  175. package/models/trace/types/devtools_entrypoint-bundle-typescript-tsconfig.json +2 -2
  176. package/models/trace/types/types-tsconfig.json +2 -2
  177. package/package.json +1 -1
@@ -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;A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UAAU,IAAI;IAClB,OAAO;QACL,0BAA0B,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI;QACrF,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// @ts-expect-error expected to be used.\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,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Aa,CAAC,CAAC;IACnD,mCAAmC;IACnC,8EAA8E;IAC9E,sHAAsH;IACtH,qCAAqC;IACrC,6HAA6H;IAC7H,OAAO,SAAS,IAAI,eAAe,CAAC,EAAE,CAAC;AACzC,CAAC;AAaD,2CAA2C;AAC3C,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,0BAA0B,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI;QACrF,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"]}
@@ -15,8 +15,12 @@ export interface Script {
15
15
  url?: string;
16
16
  sourceUrl?: string;
17
17
  content?: string;
18
- /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url. */
18
+ /** Note: this is the literal text given as the sourceMappingURL value. It has not been resolved relative to the script url.
19
+ * Since M138, data urls are never set here.
20
+ */
19
21
  sourceMapUrl?: string;
22
+ /** If true, the source map url was a data URL, so it got removed from the trace event. */
23
+ sourceMapUrlElided?: boolean;
20
24
  sourceMap?: any;
21
25
  request?: Types.Events.SyntheticNetworkRequest;
22
26
  /** Lazily generated - use getScriptGeneratedSizes to access. */
@@ -36,13 +36,21 @@ 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, sourceMapUrlElided } = event.args.data;
40
40
  const script = getOrMakeScript(isolate, scriptId);
41
41
  script.url = url;
42
42
  if (sourceUrl) {
43
43
  script.sourceUrl = sourceUrl;
44
44
  }
45
- if (sourceMapUrl) {
45
+ // Older traces may have data source map urls. Those can be very large, so a change
46
+ // was made to elide them from the trace.
47
+ // If elided, a fresh trace will fetch the source map from the Script model
48
+ // (see TimelinePanel getExistingSourceMap). If not fresh, the source map is resolved
49
+ // instead in this handler via `findCachedRawSourceMap`.
50
+ if (sourceMapUrlElided) {
51
+ script.sourceMapUrlElided = true;
52
+ }
53
+ else if (sourceMapUrl) {
46
54
  script.sourceMapUrl = sourceMapUrl;
47
55
  }
48
56
  return;
@@ -147,15 +155,31 @@ export function getScriptGeneratedSizes(script) {
147
155
  }
148
156
  return script.sizes ?? null;
149
157
  }
150
- function findCachedRawSourceMap(sourceMapUrl, options) {
151
- if (!sourceMapUrl) {
158
+ function findCachedRawSourceMap(script, options) {
159
+ if (options.isFreshRecording || !options.metadata?.sourceMaps) {
160
+ // Exit if this is not a loaded trace w/ source maps in the metadata.
161
+ return;
162
+ }
163
+ // For elided data url source maps, search the metadata source maps by script url.
164
+ if (script.sourceMapUrlElided) {
165
+ if (!script.url) {
166
+ return;
167
+ }
168
+ const cachedSourceMap = options.metadata.sourceMaps.find(m => m.url === script.url);
169
+ if (cachedSourceMap) {
170
+ return cachedSourceMap.sourceMap;
171
+ }
172
+ return;
173
+ }
174
+ if (!script.sourceMapUrl) {
152
175
  return;
153
176
  }
154
- // If loading from disk, check the metadata for source maps.
155
- // The metadata doesn't store data url source maps.
156
- const isDataUrl = sourceMapUrl.startsWith('data:');
157
- if (!options.isFreshRecording && options.metadata?.sourceMaps && !isDataUrl) {
158
- const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === sourceMapUrl);
177
+ // Otherwise, search by source map url.
178
+ // Note: early enhanced traces may have this field set for data urls. Ignore those,
179
+ // as they were never stored in metadata sourcemap.
180
+ const isDataUrl = script.sourceMapUrl.startsWith('data:');
181
+ if (!isDataUrl) {
182
+ const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === script.sourceMapUrl);
159
183
  if (cachedSourceMap) {
160
184
  return cachedSourceMap.sourceMap;
161
185
  }
@@ -183,7 +207,7 @@ export async function finalize(options) {
183
207
  // No frame or url means the script came from somewhere we don't care about.
184
208
  // Note: scripts from inline <SCRIPT> elements use the url of the HTML document,
185
209
  // so aren't ignored.
186
- if (!script.frame || !script.url || !script.sourceMapUrl) {
210
+ if (!script.frame || !script.url || (!script.sourceMapUrl && !script.sourceMapUrlElided)) {
187
211
  continue;
188
212
  }
189
213
  const frameUrl = findFrame(meta, script.frame)?.url;
@@ -196,26 +220,33 @@ export async function finalize(options) {
196
220
  if (script.sourceUrl) {
197
221
  sourceUrl = completeURL(frameUrl, script.sourceUrl) ?? script.sourceUrl;
198
222
  }
199
- // Resolve the source map url. The value given by v8 may be relative, so resolve it here.
200
- // This process should match the one in `SourceMapManager.attachSourceMap`.
201
- const sourceMapUrl = completeURL(sourceUrl, script.sourceMapUrl);
202
- if (!sourceMapUrl) {
203
- continue;
223
+ let sourceMapUrl;
224
+ if (script.sourceMapUrl) {
225
+ // Resolve the source map url. The value given by v8 may be relative, so resolve it here.
226
+ // This process should match the one in `SourceMapManager.attachSourceMap`.
227
+ sourceMapUrl =
228
+ completeURL(sourceUrl, script.sourceMapUrl);
229
+ if (!sourceMapUrl) {
230
+ continue;
231
+ }
232
+ script.sourceMapUrl = sourceMapUrl;
204
233
  }
205
- script.sourceMapUrl = sourceMapUrl;
206
234
  const params = {
207
235
  scriptId: script.scriptId,
208
- scriptUrl: sourceUrl,
209
- sourceMapUrl: sourceMapUrl,
236
+ scriptUrl: script.url,
237
+ sourceUrl: sourceUrl,
238
+ sourceMapUrl: sourceMapUrl ?? '',
210
239
  frame: script.frame,
211
- cachedRawSourceMap: findCachedRawSourceMap(sourceMapUrl, options),
240
+ cachedRawSourceMap: findCachedRawSourceMap(script, options),
212
241
  };
213
242
  const promise = options.resolveSourceMap(params).then(sourceMap => {
214
243
  if (sourceMap) {
215
244
  script.sourceMap = sourceMap;
216
245
  }
217
246
  });
218
- promises.push(promise);
247
+ promises.push(promise.catch(e => {
248
+ console.error('Uncaught error when resolving source map', params, e);
249
+ }));
219
250
  }
220
251
  await Promise.all(promises);
221
252
  }
@@ -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,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AE,CAAC;YACd,SAAS;QACX,CAAC;QAED,0FAA0F;QAC1F,uHAAuH;QACvH,IAAI,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;QAC3B,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,SAAS,GAAG,WAAW,CAAC,QAAQ,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC;QAC1E,CAAC;QAED,yFAAyF;QACzF,2EAA2E;QAC3E,MAAM,YAAY,GACd,WAAW,CAAC,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;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} = 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\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 meta = metaHandlerData();\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n\n const documentUrls = new Set<string>();\n for (const frames of meta.frameByProcessId.values()) {\n for (const frame of frames.values()) {\n documentUrls.add(frame.url);\n }\n }\n\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n script.inline = !!script.url && documentUrls.has(script.url);\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\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"]}
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,GAAsC,CAAC;IAChD,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAuC,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,OAAO,IAAI,CAAC;AACd,CAAC;AAgCD,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,UAAU,WA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,sBAAsB,CAAC,MAAM,EAAE,OAAO,CAAC;SAC5D,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,KAAK,CAAC,CAAC,CAAC,EAAE;YAC9B,OAAO,CAAC,KAAK,CAAC,0CAA0C,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QACvE,CAAC,CAAC,CAAC,CAAC;IACN,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): Platform.DevToolsPath.UrlString|null {\n if (url.startsWith('data:') || url.startsWith('blob:') || url.startsWith('javascript:') || url.startsWith('mailto:')) {\n return url as Platform.DevToolsPath.UrlString;\n }\n\n try {\n return new URL(url, base).href as Platform.DevToolsPath.UrlString;\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 * Since M138, data urls are never set here.\n */\n sourceMapUrl?: string;\n /** If true, the source map url was a data URL, so it got removed from the trace event. */\n sourceMapUrlElided?: boolean;\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, sourceMapUrlElided} = event.args.data;\n const script = getOrMakeScript(isolate, scriptId);\n script.url = url;\n if (sourceUrl) {\n script.sourceUrl = sourceUrl;\n }\n\n // Older traces may have data source map urls. Those can be very large, so a change\n // was made to elide them from the trace.\n // If elided, a fresh trace will fetch the source map from the Script model\n // (see TimelinePanel getExistingSourceMap). If not fresh, the source map is resolved\n // instead in this handler via `findCachedRawSourceMap`.\n if (sourceMapUrlElided) {\n script.sourceMapUrlElided = true;\n } else 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\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(script: Script, options: Types.Configuration.ParseOptions): SDK.SourceMap.SourceMapV3|\n undefined {\n if (options.isFreshRecording || !options.metadata?.sourceMaps) {\n // Exit if this is not a loaded trace w/ source maps in the metadata.\n return;\n }\n\n // For elided data url source maps, search the metadata source maps by script url.\n if (script.sourceMapUrlElided) {\n if (!script.url) {\n return;\n }\n\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.url === script.url);\n if (cachedSourceMap) {\n return cachedSourceMap.sourceMap;\n }\n\n return;\n }\n\n if (!script.sourceMapUrl) {\n return;\n }\n\n // Otherwise, search by source map url.\n // Note: early enhanced traces may have this field set for data urls. Ignore those,\n // as they were never stored in metadata sourcemap.\n const isDataUrl = script.sourceMapUrl.startsWith('data:');\n if (!isDataUrl) {\n const cachedSourceMap = options.metadata.sourceMaps.find(m => m.sourceMapUrl === script.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 meta = metaHandlerData();\n const networkRequests = [...networkRequestsHandlerData().byId.values()];\n\n const documentUrls = new Set<string>();\n for (const frames of meta.frameByProcessId.values()) {\n for (const frame of frames.values()) {\n documentUrls.add(frame.url);\n }\n }\n\n for (const script of scriptById.values()) {\n script.request = findNetworkRequest(networkRequests, script) ?? undefined;\n script.inline = !!script.url && documentUrls.has(script.url);\n }\n\n if (!options.resolveSourceMap) {\n return;\n }\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 && !script.sourceMapUrlElided)) {\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 let sourceMapUrl;\n if (script.sourceMapUrl) {\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 sourceMapUrl =\n completeURL(sourceUrl as Platform.DevToolsPath.UrlString, script.sourceMapUrl);\n if (!sourceMapUrl) {\n continue;\n }\n\n script.sourceMapUrl = sourceMapUrl;\n }\n\n const params: Types.Configuration.ResolveSourceMapParams = {\n scriptId: script.scriptId,\n scriptUrl: script.url as Platform.DevToolsPath.UrlString,\n sourceUrl: sourceUrl as Platform.DevToolsPath.UrlString,\n sourceMapUrl: sourceMapUrl ?? '' as Platform.DevToolsPath.UrlString,\n frame: script.frame as Protocol.Page.FrameId,\n cachedRawSourceMap: findCachedRawSourceMap(script, options),\n };\n const promise = options.resolveSourceMap(params).then(sourceMap => {\n if (sourceMap) {\n script.sourceMap = sourceMap;\n }\n });\n promises.push(promise.catch(e => {\n console.error('Uncaught error when resolving source map', params, e);\n }));\n }\n await Promise.all(promises);\n}\n\nexport function data(): ScriptsData {\n return {\n scripts: [...scriptById.values()],\n };\n}\n"]}
@@ -5,6 +5,7 @@ import * as Platform from '../../../core/platform/platform.js';
5
5
  import * as Helpers from '../helpers/helpers.js';
6
6
  import * as Types from '../types/types.js';
7
7
  import { data as userInteractionsHandlerData } from './UserInteractionsHandler.js';
8
+ import { data as workersData } from './WorkersHandler.js';
8
9
  const warningsPerEvent = new Map();
9
10
  const eventsPerWarning = new Map();
10
11
  /**
@@ -21,6 +22,10 @@ const jsInvokeStack = [];
21
22
  * Tracks reflow events in a task.
22
23
  */
23
24
  const taskReflowEvents = [];
25
+ /**
26
+ * Tracks events containing long running tasks. These are compared later against the worker thread pool to filter out long tasks from worker threads.
27
+ */
28
+ const longTaskEvents = [];
24
29
  export const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(30));
25
30
  export const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(50));
26
31
  export function reset() {
@@ -29,6 +34,7 @@ export function reset() {
29
34
  allEventsStack.length = 0;
30
35
  jsInvokeStack.length = 0;
31
36
  taskReflowEvents.length = 0;
37
+ longTaskEvents.length = 0;
32
38
  }
33
39
  function storeWarning(event, warning) {
34
40
  const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);
@@ -43,7 +49,7 @@ export function handleEvent(event) {
43
49
  if (event.name === "RunTask" /* Types.Events.Name.RUN_TASK */) {
44
50
  const { duration } = Helpers.Timing.eventTimingsMicroSeconds(event);
45
51
  if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {
46
- storeWarning(event, 'LONG_TASK');
52
+ longTaskEvents.push(event);
47
53
  }
48
54
  return;
49
55
  }
@@ -101,7 +107,7 @@ function accomodateEventInStack(event, stack, pushEventToStack = true) {
101
107
  stack.push(event);
102
108
  }
103
109
  export function deps() {
104
- return ['UserInteractions'];
110
+ return ['UserInteractions', 'Workers'];
105
111
  }
106
112
  export async function finalize() {
107
113
  // These events do exist on the UserInteractionsHandler, but we also put
@@ -113,6 +119,12 @@ export async function finalize() {
113
119
  for (const interaction of longInteractions) {
114
120
  storeWarning(interaction, 'LONG_INTERACTION');
115
121
  }
122
+ for (const event of longTaskEvents) {
123
+ if (!(event.tid, workersData().workerIdByThread.has(event.tid))) {
124
+ storeWarning(event, 'LONG_TASK');
125
+ }
126
+ }
127
+ longTaskEvents.length = 0;
116
128
  }
117
129
  export function data() {
118
130
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"WarningsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WarningsHandler.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;AAG3C,OAAO,EAAC,IAAI,IAAI,2BAA2B,EAAC,MAAM,8BAA8B,CAAC;AAYjF,MAAM,gBAAgB,GAA6B,IAAI,GAAG,EAAE,CAAC;AAC7D,MAAM,gBAAgB,GAA+B,IAAI,GAAG,EAAE,CAAC;AAE/D;;GAEG;AACH,MAAM,cAAc,GAAyB,EAAE,CAAC;AAChD;;;;GAIG;AACH,MAAM,aAAa,GAAyB,EAAE,CAAC;AAC/C;;GA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IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,UAAU,EAAE,gBAAgB;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\nimport {data as userInteractionsHandlerData} from './UserInteractionsHandler.js';\n\nexport interface WarningsData {\n // Tracks warnings keyed by the event.\n perEvent: Map<Types.Events.Event, Warning[]>;\n // The same data in reverse: for each type of warning, track the events.\n // Useful if we need to enumerate events by type of issue\n perWarning: Map<Warning, Types.Events.Event[]>;\n}\n\nexport type Warning = 'LONG_TASK'|'IDLE_CALLBACK_OVER_TIME'|'FORCED_REFLOW'|'LONG_INTERACTION';\n\nconst warningsPerEvent: WarningsData['perEvent'] = new Map();\nconst eventsPerWarning: WarningsData['perWarning'] = new Map();\n\n/**\n * Tracks the stack formed by nested trace events up to a given point\n */\nconst allEventsStack: Types.Events.Event[] = [];\n/**\n * Tracks the stack formed by JS invocation trace events up to a given point.\n * F.e. FunctionCall, EvaluateScript, V8Execute.\n * Not to be confused with ProfileCalls.\n */\nconst jsInvokeStack: Types.Events.Event[] = [];\n/**\n * Tracks reflow events in a task.\n */\nconst taskReflowEvents: Types.Events.Event[] = [];\n\nexport const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(30));\n\nexport const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(50));\n\nexport function reset(): void {\n warningsPerEvent.clear();\n eventsPerWarning.clear();\n allEventsStack.length = 0;\n jsInvokeStack.length = 0;\n taskReflowEvents.length = 0;\n}\n\nfunction storeWarning(event: Types.Events.Event, warning: Warning): void {\n const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);\n existingWarnings.push(warning);\n warningsPerEvent.set(event, existingWarnings);\n\n const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);\n existingEvents.push(event);\n eventsPerWarning.set(warning, existingEvents);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n processForcedReflowWarning(event);\n if (event.name === Types.Events.Name.RUN_TASK) {\n const {duration} = Helpers.Timing.eventTimingsMicroSeconds(event);\n if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {\n storeWarning(event, 'LONG_TASK');\n }\n return;\n }\n\n if (Types.Events.isFireIdleCallback(event)) {\n const {duration} = Helpers.Timing.eventTimingsMilliSeconds(event);\n if (duration > event.args.data.allottedMilliseconds) {\n storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');\n }\n return;\n }\n}\n\n/**\n * Reflows* are added a warning to if:\n * 1. They are forced/sync, meaning they are invoked by JS and finish\n * during the Script execution.\n * 2. Their duration exceeds a threshold.\n * - *Reflow: The style recalculation and layout steps in a render task.\n */\nfunction processForcedReflowWarning(event: Types.Events.Event): void {\n // Update the event and the JS invocation stacks.\n accomodateEventInStack(event, allEventsStack);\n accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.Events.isJSInvocationEvent(event));\n if (jsInvokeStack.length) {\n // Current event falls inside a JS call.\n if (event.name === Types.Events.Name.LAYOUT || event.name === Types.Events.Name.UPDATE_LAYOUT_TREE) {\n // A forced reflow happened. However we need to check if\n // the threshold is surpassed to add a warning. Accumulate the\n // event to check for this after the current Task is over.\n taskReflowEvents.push(event);\n return;\n }\n }\n if (allEventsStack.length === 1) {\n // We hit a new task. Check if the forced reflows in the previous\n // task exceeded the threshold and add a warning if so.\n const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);\n if (totalTime >= FORCED_REFLOW_THRESHOLD) {\n taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));\n }\n taskReflowEvents.length = 0;\n }\n}\n\n/**\n * Updates a given trace event stack given a new event.\n */\nfunction accomodateEventInStack(event: Types.Events.Event, stack: Types.Events.Event[], pushEventToStack = true): void {\n let nextItem = stack.at(-1);\n while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {\n stack.pop();\n nextItem = stack.at(-1);\n }\n if (!pushEventToStack) {\n return;\n }\n stack.push(event);\n}\n\nexport function deps(): HandlerName[] {\n return ['UserInteractions'];\n}\n\nexport async function finalize(): Promise<void> {\n // These events do exist on the UserInteractionsHandler, but we also put\n // them into the WarningsHandler so that the warnings handler can be the\n // source of truth and the way to look up all warnings for a given event.\n // Otherwise, we would have to look up warnings across multiple handlers for\n // a given event, which will start to get messy very quickly.\n const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;\n for (const interaction of longInteractions) {\n storeWarning(interaction, 'LONG_INTERACTION');\n }\n}\n\nexport function data(): WarningsData {\n return {\n perEvent: warningsPerEvent,\n perWarning: eventsPerWarning,\n };\n}\n"]}
1
+ {"version":3,"file":"WarningsHandler.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/WarningsHandler.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;AAG3C,OAAO,EAAC,IAAI,IAAI,2BAA2B,EAAC,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAC,IAAI,IAAI,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAYxD,MAAM,gBAAgB,GAA6B,IAAI,GAAG,EAAE,CAAC;AAC7D,MAAM,gBAAgB,GAA+B,IAAI,GAAG,EAAE,CAAC;AAE/D;;GAEG;AACH,MAAM,cAAc,GAAyB,EAAE,CAAC;AAChD;;;;GAIG;AACH,MAAM,aAAa,GAAyB,EAAE,CAAC;AAC/C;;GAEG;AACH,MAAM,gBA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3C,YAAY,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,cAAc,EAAE,CAAC;QACnC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAChE,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IACD,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,IAAI;IAClB,OAAO;QACL,QAAQ,EAAE,gBAAgB;QAC1B,UAAU,EAAE,gBAAgB;KAC7B,CAAC;AACJ,CAAC","sourcesContent":["// Copyright 2023 The Chromium Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\nimport * as Platform from '../../../core/platform/platform.js';\nimport * as Helpers from '../helpers/helpers.js';\nimport * as Types from '../types/types.js';\n\nimport type {HandlerName} from './types.js';\nimport {data as userInteractionsHandlerData} from './UserInteractionsHandler.js';\nimport {data as workersData} from './WorkersHandler.js';\n\nexport interface WarningsData {\n // Tracks warnings keyed by the event.\n perEvent: Map<Types.Events.Event, Warning[]>;\n // The same data in reverse: for each type of warning, track the events.\n // Useful if we need to enumerate events by type of issue\n perWarning: Map<Warning, Types.Events.Event[]>;\n}\n\nexport type Warning = 'LONG_TASK'|'IDLE_CALLBACK_OVER_TIME'|'FORCED_REFLOW'|'LONG_INTERACTION';\n\nconst warningsPerEvent: WarningsData['perEvent'] = new Map();\nconst eventsPerWarning: WarningsData['perWarning'] = new Map();\n\n/**\n * Tracks the stack formed by nested trace events up to a given point\n */\nconst allEventsStack: Types.Events.Event[] = [];\n/**\n * Tracks the stack formed by JS invocation trace events up to a given point.\n * F.e. FunctionCall, EvaluateScript, V8Execute.\n * Not to be confused with ProfileCalls.\n */\nconst jsInvokeStack: Types.Events.Event[] = [];\n/**\n * Tracks reflow events in a task.\n */\nconst taskReflowEvents: Types.Events.Event[] = [];\n/**\n * Tracks events containing long running tasks. These are compared later against the worker thread pool to filter out long tasks from worker threads.\n */\nconst longTaskEvents: Types.Events.Event[] = [];\n\nexport const FORCED_REFLOW_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(30));\n\nexport const LONG_MAIN_THREAD_TASK_THRESHOLD = Helpers.Timing.milliToMicro(Types.Timing.Milli(50));\n\nexport function reset(): void {\n warningsPerEvent.clear();\n eventsPerWarning.clear();\n allEventsStack.length = 0;\n jsInvokeStack.length = 0;\n taskReflowEvents.length = 0;\n longTaskEvents.length = 0;\n}\n\nfunction storeWarning(event: Types.Events.Event, warning: Warning): void {\n const existingWarnings = Platform.MapUtilities.getWithDefault(warningsPerEvent, event, () => []);\n existingWarnings.push(warning);\n warningsPerEvent.set(event, existingWarnings);\n\n const existingEvents = Platform.MapUtilities.getWithDefault(eventsPerWarning, warning, () => []);\n existingEvents.push(event);\n eventsPerWarning.set(warning, existingEvents);\n}\n\nexport function handleEvent(event: Types.Events.Event): void {\n processForcedReflowWarning(event);\n if (event.name === Types.Events.Name.RUN_TASK) {\n const {duration} = Helpers.Timing.eventTimingsMicroSeconds(event);\n if (duration > LONG_MAIN_THREAD_TASK_THRESHOLD) {\n longTaskEvents.push(event);\n }\n return;\n }\n\n if (Types.Events.isFireIdleCallback(event)) {\n const {duration} = Helpers.Timing.eventTimingsMilliSeconds(event);\n if (duration > event.args.data.allottedMilliseconds) {\n storeWarning(event, 'IDLE_CALLBACK_OVER_TIME');\n }\n return;\n }\n}\n\n/**\n * Reflows* are added a warning to if:\n * 1. They are forced/sync, meaning they are invoked by JS and finish\n * during the Script execution.\n * 2. Their duration exceeds a threshold.\n * - *Reflow: The style recalculation and layout steps in a render task.\n */\nfunction processForcedReflowWarning(event: Types.Events.Event): void {\n // Update the event and the JS invocation stacks.\n accomodateEventInStack(event, allEventsStack);\n accomodateEventInStack(event, jsInvokeStack, /* pushEventToStack */ Types.Events.isJSInvocationEvent(event));\n if (jsInvokeStack.length) {\n // Current event falls inside a JS call.\n if (event.name === Types.Events.Name.LAYOUT || event.name === Types.Events.Name.UPDATE_LAYOUT_TREE) {\n // A forced reflow happened. However we need to check if\n // the threshold is surpassed to add a warning. Accumulate the\n // event to check for this after the current Task is over.\n taskReflowEvents.push(event);\n return;\n }\n }\n if (allEventsStack.length === 1) {\n // We hit a new task. Check if the forced reflows in the previous\n // task exceeded the threshold and add a warning if so.\n const totalTime = taskReflowEvents.reduce((time, event) => time + (event.dur || 0), 0);\n if (totalTime >= FORCED_REFLOW_THRESHOLD) {\n taskReflowEvents.forEach(reflowEvent => storeWarning(reflowEvent, 'FORCED_REFLOW'));\n }\n taskReflowEvents.length = 0;\n }\n}\n\n/**\n * Updates a given trace event stack given a new event.\n */\nfunction accomodateEventInStack(event: Types.Events.Event, stack: Types.Events.Event[], pushEventToStack = true): void {\n let nextItem = stack.at(-1);\n while (nextItem && event.ts > nextItem.ts + (nextItem.dur || 0)) {\n stack.pop();\n nextItem = stack.at(-1);\n }\n if (!pushEventToStack) {\n return;\n }\n stack.push(event);\n}\n\nexport function deps(): HandlerName[] {\n return ['UserInteractions', 'Workers'];\n}\n\nexport async function finalize(): Promise<void> {\n // These events do exist on the UserInteractionsHandler, but we also put\n // them into the WarningsHandler so that the warnings handler can be the\n // source of truth and the way to look up all warnings for a given event.\n // Otherwise, we would have to look up warnings across multiple handlers for\n // a given event, which will start to get messy very quickly.\n const longInteractions = userInteractionsHandlerData().interactionsOverThreshold;\n for (const interaction of longInteractions) {\n storeWarning(interaction, 'LONG_INTERACTION');\n }\n\n for (const event of longTaskEvents) {\n if (!(event.tid, workersData().workerIdByThread.has(event.tid))) {\n storeWarning(event, 'LONG_TASK');\n }\n }\n longTaskEvents.length = 0;\n}\n\nexport function data(): WarningsData {\n return {\n perEvent: warningsPerEvent,\n perWarning: eventsPerWarning,\n };\n}\n"]}
@@ -17,8 +17,8 @@
17
17
  "noFallthroughCasesInSwitch": true,
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
22
  "outDir": ".",
23
23
  "rootDir": "../../../../../../../front_end/models/trace/handlers",
24
24
  "skipLibCheck": true,
@@ -17,8 +17,8 @@
17
17
  "noFallthroughCasesInSwitch": true,
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
22
  "outDir": ".",
23
23
  "rootDir": "../../../../../../../front_end/models/trace/handlers",
24
24
  "skipLibCheck": true,
@@ -20,6 +20,9 @@ export function getNonResolvedURL(entry, parsedTrace) {
20
20
  if (Types.Events.isSyntheticNetworkRequest(entry)) {
21
21
  return entry.args.data.url;
22
22
  }
23
+ if (Types.Events.isParseAuthorStyleSheetEvent(entry) && entry.args) {
24
+ return entry.args.data.stylesheetUrl;
25
+ }
23
26
  if (entry.args?.data?.stackTrace && entry.args.data.stackTrace.length > 0) {
24
27
  return entry.args.data.stackTrace[0].url;
25
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/helpers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,aAAa,MAAM,yDAAyD,CAAC;AACzF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAmB3C,MAAM,UAAU,iBAAiB,CAAC,KAAyB,EAAE,WAAgC;IAC3F,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;IACT,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC3C,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Z,OAAO;IACT,CAAC;IACD,iKAAiK;IACjK,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAClF,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,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.\n\nimport type * as Platform from '../../../core/platform/platform.js';\nimport * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';\nimport * as Types from '../types/types.js';\n\nimport type {TraceEventsForNetworkRequest} from './NetworkRequestsHandler.js';\nimport type {ParsedTrace} from './types.js';\n\nexport type Entity = typeof ThirdPartyWeb.ThirdPartyWeb.entities[number]&{\n isUnrecognized?: boolean,\n};\n\nexport interface EntityMappings {\n createdEntityCache: Map<string, Entity>;\n entityByEvent: Map<Types.Events.Event, Entity>;\n /**\n * This holds the entities that had to be created, because they were not found using the\n * ThirdPartyWeb database.\n */\n eventsByEntity: Map<Entity, Types.Events.Event[]>;\n}\n\nexport function getEntityForEvent(event: Types.Events.Event, entityCache: Map<string, Entity>): Entity|undefined {\n const url = getNonResolvedURL(event);\n if (!url) {\n return;\n }\n return getEntityForUrl(url, entityCache);\n}\n\nexport function getEntityForUrl(url: string, entityCache: Map<string, Entity>): Entity|undefined {\n return ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityCache, url);\n}\n\nexport function getNonResolvedURL(\n entry: Types.Events.Event, parsedTrace?: ParsedTrace): Platform.DevToolsPath.UrlString|null {\n if (Types.Events.isProfileCall(entry)) {\n return entry.callFrame.url as Platform.DevToolsPath.UrlString;\n }\n\n if (Types.Events.isSyntheticNetworkRequest(entry)) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n if (entry.args?.data?.stackTrace && entry.args.data.stackTrace.length > 0) {\n return entry.args.data.stackTrace[0].url as Platform.DevToolsPath.UrlString;\n }\n\n // ParseHTML events store the URL under beginData, not data.\n if (Types.Events.isParseHTML(entry)) {\n return entry.args.beginData.url as Platform.DevToolsPath.UrlString;\n }\n\n if (parsedTrace) {\n // DecodeImage events use the URL from the relevant PaintImage event.\n if (Types.Events.isDecodeImage(entry)) {\n const paintEvent = parsedTrace.ImagePainting.paintImageForEvent.get(entry);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n\n // DrawLazyPixelRef events use the URL from the relevant PaintImage event.\n if (Types.Events.isDrawLazyPixelRef(entry) && entry.args?.LazyPixelRef) {\n const paintEvent = parsedTrace.ImagePainting.paintImageByDrawLazyPixelRef.get(entry.args.LazyPixelRef);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n }\n\n // For all other events, try to see if the URL is provided, else return null.\n if (entry.args?.data?.url) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n // Many events don't have a url, but are associated with a request. Use the\n // request's url.\n const requestId = (entry.args?.data as {requestId?: string})?.requestId;\n if (parsedTrace && requestId) {\n const url = parsedTrace.NetworkRequests.byId.get(requestId)?.args.data.url;\n if (url) {\n return url as Platform.DevToolsPath.UrlString;\n }\n }\n\n return null;\n}\n\nexport function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity|undefined {\n if (url.startsWith('chrome-extension:')) {\n return makeUpChromeExtensionEntity(entityCache, url);\n }\n\n // Make up an entity only for valid http/https URLs.\n if (!url.startsWith('http')) {\n return;\n }\n\n // NOTE: Lighthouse uses a tld database to determine the root domain, but here\n // we are using third party web's database. Doesn't really work for the case of classifying\n // domains 3pweb doesn't know about, so it will just give us a guess.\n const rootDomain = ThirdPartyWeb.ThirdPartyWeb.getRootDomain(url);\n if (!rootDomain) {\n return;\n }\n\n if (entityCache.has(rootDomain)) {\n return entityCache.get(rootDomain);\n }\n\n const unrecognizedEntity = {\n name: rootDomain,\n company: rootDomain,\n category: '',\n categories: [],\n domains: [rootDomain],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n isUnrecognized: true,\n };\n entityCache.set(rootDomain, unrecognizedEntity);\n return unrecognizedEntity;\n}\n\nfunction getChromeExtensionOrigin(url: URL): string {\n return url.protocol + '//' + url.host;\n}\n\nfunction makeUpChromeExtensionEntity(entityCache: Map<string, Entity>, url: string, extensionName?: string): Entity {\n const parsedUrl = new URL(url);\n const origin = getChromeExtensionOrigin(parsedUrl);\n const host = new URL(origin).host;\n const name = extensionName || host;\n\n const cachedEntity = entityCache.get(origin);\n if (cachedEntity) {\n return cachedEntity;\n }\n\n const chromeExtensionEntity = {\n name,\n company: name,\n category: 'Chrome Extension',\n homepage: 'https://chromewebstore.google.com/detail/' + host,\n categories: [],\n domains: [origin],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n };\n\n entityCache.set(origin, chromeExtensionEntity);\n return chromeExtensionEntity;\n}\n\nexport function addEventToEntityMapping(event: Types.Events.Event, entityMappings: EntityMappings): void {\n const entity = getEntityForEvent(event, entityMappings.createdEntityCache);\n if (!entity) {\n return;\n }\n\n // As we share the entityMappings between Network and Renderer... We can have ResourceSendRequest events passed in here\n // that were already mapped in Network. So, to avoid mapping twice, we always check that we didn't yet.\n if (entityMappings.entityByEvent.has(event)) {\n return;\n }\n\n const mappedEvents = entityMappings.eventsByEntity.get(entity);\n if (mappedEvents) {\n mappedEvents.push(event);\n } else {\n entityMappings.eventsByEntity.set(entity, [event]);\n }\n entityMappings.entityByEvent.set(event, entity);\n}\n\n// A slight upgrade of addEventToEntityMapping to handle the sub-events of a network request.\nexport function addNetworkRequestToEntityMapping(\n networkRequest: Types.Events.SyntheticNetworkRequest, entityMappings: EntityMappings,\n requestTraceEvents: TraceEventsForNetworkRequest): void {\n const entity = getEntityForEvent(networkRequest, entityMappings.createdEntityCache);\n if (!entity) {\n return;\n }\n // In addition to mapping the network request, we'll also assign this entity to its \"child\" instant events like receiveData, willSendRequest, finishLoading, etc,\n const eventsToMap = [networkRequest, ...Object.values(requestTraceEvents).flat()];\n const mappedEvents = entityMappings.eventsByEntity.get(entity);\n if (mappedEvents) {\n mappedEvents.push(...eventsToMap);\n } else {\n entityMappings.eventsByEntity.set(entity, eventsToMap);\n }\n for (const evt of eventsToMap) {\n entityMappings.entityByEvent.set(evt, entity);\n }\n}\n"]}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/helpers.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,yEAAyE;AACzE,6BAA6B;AAG7B,OAAO,KAAK,aAAa,MAAM,yDAAyD,CAAC;AACzF,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAmB3C,MAAM,UAAU,iBAAiB,CAAC,KAAyB,EAAE,WAAgC;IAC3F,MAAM,GAAG,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO;IACT,CAAC;IACD,OAAO,eAAe,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,WAAgC;IAC3E,OAAO,aAAa,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACtF,CAAC;AAED,MAAM,UAAU,iB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D,iKAAiK;IACjK,MAAM,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAClF,MAAM,YAAY,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;IACpC,CAAC;SAAM,CAAC;QACN,cAAc,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzD,CAAC;IACD,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,cAAc,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAChD,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.\n\nimport type * as Platform from '../../../core/platform/platform.js';\nimport * as ThirdPartyWeb from '../../../third_party/third-party-web/third-party-web.js';\nimport * as Types from '../types/types.js';\n\nimport type {TraceEventsForNetworkRequest} from './NetworkRequestsHandler.js';\nimport type {ParsedTrace} from './types.js';\n\nexport type Entity = typeof ThirdPartyWeb.ThirdPartyWeb.entities[number]&{\n isUnrecognized?: boolean,\n};\n\nexport interface EntityMappings {\n createdEntityCache: Map<string, Entity>;\n entityByEvent: Map<Types.Events.Event, Entity>;\n /**\n * This holds the entities that had to be created, because they were not found using the\n * ThirdPartyWeb database.\n */\n eventsByEntity: Map<Entity, Types.Events.Event[]>;\n}\n\nexport function getEntityForEvent(event: Types.Events.Event, entityCache: Map<string, Entity>): Entity|undefined {\n const url = getNonResolvedURL(event);\n if (!url) {\n return;\n }\n return getEntityForUrl(url, entityCache);\n}\n\nexport function getEntityForUrl(url: string, entityCache: Map<string, Entity>): Entity|undefined {\n return ThirdPartyWeb.ThirdPartyWeb.getEntity(url) ?? makeUpEntity(entityCache, url);\n}\n\nexport function getNonResolvedURL(\n entry: Types.Events.Event, parsedTrace?: ParsedTrace): Platform.DevToolsPath.UrlString|null {\n if (Types.Events.isProfileCall(entry)) {\n return entry.callFrame.url as Platform.DevToolsPath.UrlString;\n }\n\n if (Types.Events.isSyntheticNetworkRequest(entry)) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n if (Types.Events.isParseAuthorStyleSheetEvent(entry) && entry.args) {\n return entry.args.data.stylesheetUrl as Platform.DevToolsPath.UrlString;\n }\n\n if (entry.args?.data?.stackTrace && entry.args.data.stackTrace.length > 0) {\n return entry.args.data.stackTrace[0].url as Platform.DevToolsPath.UrlString;\n }\n\n // ParseHTML events store the URL under beginData, not data.\n if (Types.Events.isParseHTML(entry)) {\n return entry.args.beginData.url as Platform.DevToolsPath.UrlString;\n }\n\n if (parsedTrace) {\n // DecodeImage events use the URL from the relevant PaintImage event.\n if (Types.Events.isDecodeImage(entry)) {\n const paintEvent = parsedTrace.ImagePainting.paintImageForEvent.get(entry);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n\n // DrawLazyPixelRef events use the URL from the relevant PaintImage event.\n if (Types.Events.isDrawLazyPixelRef(entry) && entry.args?.LazyPixelRef) {\n const paintEvent = parsedTrace.ImagePainting.paintImageByDrawLazyPixelRef.get(entry.args.LazyPixelRef);\n return paintEvent ? getNonResolvedURL(paintEvent, parsedTrace) : null;\n }\n }\n\n // For all other events, try to see if the URL is provided, else return null.\n if (entry.args?.data?.url) {\n return entry.args.data.url as Platform.DevToolsPath.UrlString;\n }\n\n // Many events don't have a url, but are associated with a request. Use the\n // request's url.\n const requestId = (entry.args?.data as {requestId?: string})?.requestId;\n if (parsedTrace && requestId) {\n const url = parsedTrace.NetworkRequests.byId.get(requestId)?.args.data.url;\n if (url) {\n return url as Platform.DevToolsPath.UrlString;\n }\n }\n\n return null;\n}\n\nexport function makeUpEntity(entityCache: Map<string, Entity>, url: string): Entity|undefined {\n if (url.startsWith('chrome-extension:')) {\n return makeUpChromeExtensionEntity(entityCache, url);\n }\n\n // Make up an entity only for valid http/https URLs.\n if (!url.startsWith('http')) {\n return;\n }\n\n // NOTE: Lighthouse uses a tld database to determine the root domain, but here\n // we are using third party web's database. Doesn't really work for the case of classifying\n // domains 3pweb doesn't know about, so it will just give us a guess.\n const rootDomain = ThirdPartyWeb.ThirdPartyWeb.getRootDomain(url);\n if (!rootDomain) {\n return;\n }\n\n if (entityCache.has(rootDomain)) {\n return entityCache.get(rootDomain);\n }\n\n const unrecognizedEntity = {\n name: rootDomain,\n company: rootDomain,\n category: '',\n categories: [],\n domains: [rootDomain],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n isUnrecognized: true,\n };\n entityCache.set(rootDomain, unrecognizedEntity);\n return unrecognizedEntity;\n}\n\nfunction getChromeExtensionOrigin(url: URL): string {\n return url.protocol + '//' + url.host;\n}\n\nfunction makeUpChromeExtensionEntity(entityCache: Map<string, Entity>, url: string, extensionName?: string): Entity {\n const parsedUrl = new URL(url);\n const origin = getChromeExtensionOrigin(parsedUrl);\n const host = new URL(origin).host;\n const name = extensionName || host;\n\n const cachedEntity = entityCache.get(origin);\n if (cachedEntity) {\n return cachedEntity;\n }\n\n const chromeExtensionEntity = {\n name,\n company: name,\n category: 'Chrome Extension',\n homepage: 'https://chromewebstore.google.com/detail/' + host,\n categories: [],\n domains: [origin],\n averageExecutionTime: 0,\n totalExecutionTime: 0,\n totalOccurrences: 0,\n };\n\n entityCache.set(origin, chromeExtensionEntity);\n return chromeExtensionEntity;\n}\n\nexport function addEventToEntityMapping(event: Types.Events.Event, entityMappings: EntityMappings): void {\n const entity = getEntityForEvent(event, entityMappings.createdEntityCache);\n if (!entity) {\n return;\n }\n\n // As we share the entityMappings between Network and Renderer... We can have ResourceSendRequest events passed in here\n // that were already mapped in Network. So, to avoid mapping twice, we always check that we didn't yet.\n if (entityMappings.entityByEvent.has(event)) {\n return;\n }\n\n const mappedEvents = entityMappings.eventsByEntity.get(entity);\n if (mappedEvents) {\n mappedEvents.push(event);\n } else {\n entityMappings.eventsByEntity.set(entity, [event]);\n }\n entityMappings.entityByEvent.set(event, entity);\n}\n\n// A slight upgrade of addEventToEntityMapping to handle the sub-events of a network request.\nexport function addNetworkRequestToEntityMapping(\n networkRequest: Types.Events.SyntheticNetworkRequest, entityMappings: EntityMappings,\n requestTraceEvents: TraceEventsForNetworkRequest): void {\n const entity = getEntityForEvent(networkRequest, entityMappings.createdEntityCache);\n if (!entity) {\n return;\n }\n // In addition to mapping the network request, we'll also assign this entity to its \"child\" instant events like receiveData, willSendRequest, finishLoading, etc,\n const eventsToMap = [networkRequest, ...Object.values(requestTraceEvents).flat()];\n const mappedEvents = entityMappings.eventsByEntity.get(entity);\n if (mappedEvents) {\n mappedEvents.push(...eventsToMap);\n } else {\n entityMappings.eventsByEntity.set(entity, eventsToMap);\n }\n for (const evt of eventsToMap) {\n entityMappings.entityByEvent.set(evt, entity);\n }\n}\n"]}
@@ -9,16 +9,12 @@ export interface Handler {
9
9
  handleUserConfig?(config: Types.Configuration.Configuration): void;
10
10
  }
11
11
  export type HandlerName = keyof typeof ModelHandlers;
12
- export type EnabledHandlerDataWithMeta<T extends {
13
- [key: string]: Handler;
14
- }> = {
12
+ export type EnabledHandlerDataWithMeta<T extends Record<string, Handler>> = {
15
13
  Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>;
16
14
  } & {
17
15
  [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;
18
16
  };
19
- export type HandlersWithMeta<T extends {
20
- [key: string]: Handler;
21
- }> = {
17
+ export type HandlersWithMeta<T extends Record<string, Handler>> = {
22
18
  Meta: typeof ModelHandlers.Meta;
23
19
  } & {
24
20
  [K in keyof T]: T[K];
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// 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.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport interface Handler {\n reset(): void;\n handleEvent(data: object): void;\n finalize(options?: Types.Configuration.ParseOptions): Promise<void>;\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\n\nexport type HandlerName = keyof typeof ModelHandlers;\n\n// This type maps Handler names to the return type of their data\n// function. So, for example, if we are given an object with a key of 'foo'\n// and a value which is a TraceHandler containing a data() function that\n// returns a string, this type will be { foo: string }.\n//\n// This allows us to model the behavior of the TraceProcessor in the model,\n// which takes an object with Handlers as part of its config, and\n// which ultimately returns an object keyed off the names of the\n// Handlers, and with values that are derived from each\n// Handler's data function.\n//\n// So, concretely, we provide a Handler for calculating the #time\n// bounds of a trace called TraceBounds, whose data() function returns a\n// TraceWindow. The HandlerData, therefore, would determine that the\n// TraceProcessor would contain a key called 'TraceBounds' whose value is\n// a TraceWindow.\nexport type EnabledHandlerDataWithMeta<T extends {[key: string]: Handler}> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends {[key: string]: Handler}> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n// Represents the final parsed data from all of the handlers. If you instantiate a\n// TraceProcessor with a subset of handlers, you should instead use\n// `EnabledHandlerDataWithMeta<>`.\nexport type ParsedTrace = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type ParsedTraceMutable = DeepWriteable<ParsedTrace>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../front_end/models/trace/handlers/types.ts"],"names":[],"mappings":"","sourcesContent":["\n// 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.\nimport type * as Types from './../types/types.js';\nimport type * as ModelHandlers from './ModelHandlers.js';\n\nexport interface Handler {\n reset(): void;\n handleEvent(data: object): void;\n finalize(options?: Types.Configuration.ParseOptions): Promise<void>;\n data(): unknown;\n deps?(): HandlerName[];\n handleUserConfig?(config: Types.Configuration.Configuration): void;\n}\n\nexport type HandlerName = keyof typeof ModelHandlers;\n\n// This type maps Handler names to the return type of their data\n// function. So, for example, if we are given an object with a key of 'foo'\n// and a value which is a TraceHandler containing a data() function that\n// returns a string, this type will be { foo: string }.\n//\n// This allows us to model the behavior of the TraceProcessor in the model,\n// which takes an object with Handlers as part of its config, and\n// which ultimately returns an object keyed off the names of the\n// Handlers, and with values that are derived from each\n// Handler's data function.\n//\n// So, concretely, we provide a Handler for calculating the #time\n// bounds of a trace called TraceBounds, whose data() function returns a\n// TraceWindow. The HandlerData, therefore, would determine that the\n// TraceProcessor would contain a key called 'TraceBounds' whose value is\n// a TraceWindow.\nexport type EnabledHandlerDataWithMeta<T extends Record<string, Handler>> = {\n // We allow the user to configure which handlers are created by passing them\n // in when constructing a model instance. However, we then ensure that the\n // Meta handler is added to that, as the Model relies on some of the data\n // from the Meta handler when creating the file. Therefore, this type\n // explicitly defines that the Meta data is present, before then extending it\n // with the index type to represent all the other handlers.\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: Readonly<ReturnType<typeof ModelHandlers['Meta']['data']>>,\n}&{\n // For every key in the object, look up the Handler's data function\n // and use its return type as the value for the object.\n [K in keyof T]: Readonly<ReturnType<T[K]['data']>>;\n};\n\nexport type HandlersWithMeta<T extends Record<string, Handler>> = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n Meta: typeof ModelHandlers.Meta,\n}&{\n [K in keyof T]: T[K];\n};\n\n// Represents the final parsed data from all of the handlers. If you instantiate a\n// TraceProcessor with a subset of handlers, you should instead use\n// `EnabledHandlerDataWithMeta<>`.\nexport type ParsedTrace = Readonly<EnabledHandlerDataWithMeta<typeof ModelHandlers>>;\n\ntype DeepWriteable<T> = {\n -readonly[P in keyof T]: DeepWriteable<T[P]>\n};\nexport type ParsedTraceMutable = DeepWriteable<ParsedTrace>;\n\nexport type Handlers = typeof ModelHandlers;\n"]}
@@ -17,8 +17,8 @@
17
17
  "noFallthroughCasesInSwitch": true,
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
22
  "outDir": ".",
23
23
  "rootDir": "../../../../../../../front_end/models/trace/helpers",
24
24
  "skipLibCheck": true,
@@ -17,8 +17,8 @@
17
17
  "noFallthroughCasesInSwitch": true,
18
18
  "noImplicitOverride": true,
19
19
  "noImplicitReturns": true,
20
- "noUnusedLocals": true,
21
- "noUnusedParameters": true,
20
+ "noUnusedLocals": false,
21
+ "noUnusedParameters": false,
22
22
  "outDir": ".",
23
23
  "rootDir": "../../../../../../../front_end/models/trace/helpers",
24
24
  "skipLibCheck": true,
@@ -82,16 +82,17 @@ export function computeCacheLifetimeInSeconds(headers, cacheControl) {
82
82
  }
83
83
  /**
84
84
  * Computes the percent likelihood that a return visit will be within the cache lifetime, based on
85
- * Chrome UMA stats see the note below.
86
- * See https://github.com/GoogleChrome/lighthouse/blob/aba818f733552189de35121907cb5625a74af640/core/audits/byte-efficiency/uses-long-cache-ttl.js
87
- * TODO: This Chrome UMA stat is outdated. Using this is fine for now, but update in follow-up.
85
+ * historical Chrome UMA stats (see RESOURCE_AGE_IN_HOURS_DECILES comment).
86
+ *
87
+ * This function returns values on this curve: https://www.desmos.com/calculator/eaqiszhugy (but using seconds, rather than hours)
88
+ * See http://github.com/GoogleChrome/lighthouse/pull/3531 for history.
88
89
  */
89
90
  function getCacheHitProbability(maxAgeInSeconds) {
90
91
  // This array contains the hand wavy distribution of the age of a resource in hours at the time of
91
92
  // cache hit at 0th, 10th, 20th, 30th, etc percentiles. This is used to compute `wastedMs` since there
92
93
  // are clearly diminishing returns to cache duration i.e. 6 months is not 2x better than 3 months.
93
- // Based on UMA stats for HttpCache.StaleEntry.Validated.Age, see https://www.desmos.com/calculator/7v0qh1nzvh
94
- // Example: a max-age of 12 hours already covers ~50% of cases, doubling to 24 hours covers ~10% more.
94
+ // Based on UMA stats for HttpCache.StaleEntry.Validated.Age. see https://www.desmos.com/calculator/jjwc5mzuwd
95
+ // This UMA data is from 2017 but the metric isn't tracked any longer in 2025.
95
96
  const RESOURCE_AGE_IN_HOURS_DECILES = [0, 0.2, 1, 3, 8, 12, 24, 48, 72, 168, 8760, Infinity];
96
97
  const maxAgeInHours = maxAgeInSeconds / 3600;
97
98
  const upperDecileIndex = RESOURCE_AGE_IN_HOURS_DECILES.findIndex(decile => decile >= maxAgeInHours);
@@ -149,7 +150,7 @@ export function generateInsight(parsedTrace, context) {
149
150
  let totalWastedBytes = 0;
150
151
  const wastedBytesByRequestId = new Map();
151
152
  for (const req of contextRequests) {
152
- if (!isCacheable(req)) {
153
+ if (!req.args.data.responseHeaders || !isCacheable(req)) {
153
154
  continue;
154
155
  }
155
156
  const headers = getCombinedHeaders(req.args.data.responseHeaders);