chrome-devtools-frontend 1.0.1548980 → 1.0.1550444

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 (323) hide show
  1. package/docs/contributing/settings-experiments-features.md +35 -0
  2. package/docs/styleguide/ux/components.md +53 -12
  3. package/docs/styleguide/ux/images/cards.png +0 -0
  4. package/docs/styleguide/ux/patterns.md +27 -0
  5. package/docs/ui_engineering.md +2 -2
  6. package/eslint.config.mjs +1 -0
  7. package/front_end/Tests.js +2 -0
  8. package/front_end/core/host/InspectorFrontendHost.ts +26 -558
  9. package/front_end/core/host/InspectorFrontendHostAPI.ts +6 -3
  10. package/front_end/core/host/InspectorFrontendHostStub.ts +558 -0
  11. package/front_end/core/host/ResourceLoader.ts +9 -23
  12. package/front_end/core/host/UserMetrics.ts +4 -4
  13. package/front_end/core/root/DevToolsContext.ts +4 -0
  14. package/front_end/core/root/Runtime.ts +10 -0
  15. package/front_end/core/sdk/CSSMatchedStyles.ts +2 -2
  16. package/front_end/core/sdk/CSSModel.ts +24 -24
  17. package/front_end/core/sdk/CSSPropertyParserMatchers.ts +11 -11
  18. package/front_end/core/sdk/CSSQuery.ts +1 -1
  19. package/front_end/core/sdk/CSSRule.ts +2 -2
  20. package/front_end/core/sdk/CSSStyleDeclaration.ts +1 -1
  21. package/front_end/core/sdk/CSSStyleSheetHeader.ts +1 -1
  22. package/front_end/core/sdk/DOMModel.ts +3 -0
  23. package/front_end/core/sdk/NetworkManager.ts +41 -41
  24. package/front_end/core/sdk/NetworkRequest.ts +4 -0
  25. package/front_end/core/sdk/OverlayModel.ts +2 -2
  26. package/front_end/core/sdk/PageResourceLoader.ts +71 -38
  27. package/front_end/core/sdk/SourceMap.ts +6 -0
  28. package/front_end/core/sdk/SourceMapCache.ts +21 -0
  29. package/front_end/core/sdk/SourceMapManager.ts +14 -7
  30. package/front_end/core/sdk/SourceMapScopesInfo.ts +6 -2
  31. package/front_end/core/sdk/TargetManager.ts +14 -2
  32. package/front_end/core/sdk/sdk-meta.ts +13 -0
  33. package/front_end/entrypoints/formatter_worker/FormatterActions.ts +1 -0
  34. package/front_end/entrypoints/formatter_worker/ScopeParser.ts +1 -1
  35. package/front_end/entrypoints/main/MainImpl.ts +5 -4
  36. package/front_end/foundation/Universe.ts +8 -1
  37. package/front_end/generated/Deprecation.ts +18 -4
  38. package/front_end/generated/InspectorBackendCommands.ts +38 -33
  39. package/front_end/generated/SupportedCSSProperties.js +41 -41
  40. package/front_end/generated/protocol-mapping.d.ts +20 -0
  41. package/front_end/generated/protocol-proxy-api.d.ts +17 -0
  42. package/front_end/generated/protocol.ts +146 -35
  43. package/front_end/models/ai_assistance/AiConversation.ts +5 -4
  44. package/front_end/models/ai_assistance/BuiltInAi.ts +79 -5
  45. package/front_end/models/ai_assistance/ChangeManager.ts +4 -4
  46. package/front_end/models/ai_assistance/ConversationHandler.ts +0 -15
  47. package/front_end/models/ai_assistance/agents/AiAgent.ts +9 -6
  48. package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +135 -3
  49. package/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.ts +24 -0
  50. package/front_end/models/bindings/CompilerScriptMapping.ts +43 -0
  51. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +19 -0
  52. package/front_end/models/bindings/ResourceMapping.ts +73 -0
  53. package/front_end/models/bindings/ResourceScriptMapping.ts +50 -0
  54. package/front_end/models/issues_manager/AttributionReportingIssue.ts +6 -8
  55. package/front_end/models/issues_manager/BounceTrackingIssue.ts +4 -14
  56. package/front_end/models/issues_manager/ClientHintIssue.ts +5 -12
  57. package/front_end/models/issues_manager/ContentSecurityPolicyIssue.ts +5 -12
  58. package/front_end/models/issues_manager/CookieDeprecationMetadataIssue.ts +7 -14
  59. package/front_end/models/issues_manager/CookieIssue.ts +27 -30
  60. package/front_end/models/issues_manager/CorsIssue.ts +8 -17
  61. package/front_end/models/issues_manager/CrossOriginEmbedderPolicyIssue.ts +5 -8
  62. package/front_end/models/issues_manager/DeprecationIssue.ts +7 -14
  63. package/front_end/models/issues_manager/ElementAccessibilityIssue.ts +7 -14
  64. package/front_end/models/issues_manager/FederatedAuthRequestIssue.ts +4 -11
  65. package/front_end/models/issues_manager/FederatedAuthUserInfoRequestIssue.ts +4 -11
  66. package/front_end/models/issues_manager/GenericIssue.ts +28 -16
  67. package/front_end/models/issues_manager/HeavyAdIssue.ts +4 -11
  68. package/front_end/models/issues_manager/Issue.ts +12 -4
  69. package/front_end/models/issues_manager/IssueAggregator.ts +8 -2
  70. package/front_end/models/issues_manager/LowTextContrastIssue.ts +3 -10
  71. package/front_end/models/issues_manager/MixedContentIssue.ts +7 -13
  72. package/front_end/models/issues_manager/PartitioningBlobURLIssue.ts +4 -11
  73. package/front_end/models/issues_manager/PropertyRuleIssue.ts +6 -12
  74. package/front_end/models/issues_manager/QuirksModeIssue.ts +3 -10
  75. package/front_end/models/issues_manager/SRIMessageSignatureIssue.ts +7 -13
  76. package/front_end/models/issues_manager/SharedArrayBufferIssue.ts +4 -11
  77. package/front_end/models/issues_manager/SharedDictionaryIssue.ts +6 -13
  78. package/front_end/models/issues_manager/StylesheetLoadingIssue.ts +8 -13
  79. package/front_end/models/issues_manager/UnencodedDigestIssue.ts +2 -9
  80. package/front_end/models/issues_manager/descriptions/genericNavigationEntryMarkedSkippable.md +7 -0
  81. package/front_end/models/javascript_metadata/NativeFunctions.js +7 -16
  82. package/front_end/models/source_map_scopes/FunctionCodeResolver.snapshot.txt +98 -0
  83. package/front_end/models/source_map_scopes/FunctionCodeResolver.ts +270 -0
  84. package/front_end/models/source_map_scopes/source_map_scopes.ts +2 -0
  85. package/front_end/models/workspace/UISourceCode.ts +51 -44
  86. package/front_end/panels/ai_assistance/AiAssistancePanel.ts +76 -34
  87. package/front_end/panels/ai_assistance/aiAssistancePanel.css +1 -0
  88. package/front_end/panels/ai_assistance/components/ChatView.ts +23 -11
  89. package/front_end/panels/application/AppManifestView.ts +7 -6
  90. package/front_end/panels/application/ApplicationPanelSidebar.ts +21 -21
  91. package/front_end/panels/application/BackForwardCacheTreeElement.ts +2 -2
  92. package/front_end/panels/application/BounceTrackingMitigationsTreeElement.ts +2 -2
  93. package/front_end/panels/application/FrameDetailsView.ts +5 -6
  94. package/front_end/panels/application/InterestGroupTreeElement.ts +2 -2
  95. package/front_end/panels/application/OpenedWindowDetailsView.ts +2 -2
  96. package/front_end/panels/application/OriginTrialTreeView.ts +1 -1
  97. package/front_end/panels/application/PreloadingTreeElement.ts +3 -3
  98. package/front_end/panels/application/ReportingApiTreeElement.ts +2 -2
  99. package/front_end/panels/application/ServiceWorkerCacheTreeElement.ts +3 -3
  100. package/front_end/panels/application/ServiceWorkersView.ts +2 -2
  101. package/front_end/panels/application/SharedStorageListTreeElement.ts +2 -2
  102. package/front_end/panels/application/StorageBucketsTreeElement.ts +3 -3
  103. package/front_end/panels/application/StorageView.ts +2 -2
  104. package/front_end/panels/application/TrustTokensTreeElement.ts +4 -8
  105. package/front_end/panels/application/components/PermissionsPolicySection.ts +202 -158
  106. package/front_end/panels/application/components/ProtocolHandlersView.ts +118 -81
  107. package/front_end/panels/application/components/ServiceWorkerRouterView.ts +47 -41
  108. package/front_end/panels/application/components/SharedStorageMetadataView.ts +1 -1
  109. package/front_end/panels/application/components/StorageMetadataView.ts +31 -34
  110. package/front_end/panels/application/components/TrustTokensView.ts +77 -69
  111. package/front_end/panels/application/preloading/components/PreloadingGrid.ts +1 -1
  112. package/front_end/panels/application/preloading/components/RuleSetGrid.ts +1 -1
  113. package/front_end/panels/application/preloading/components/UsedPreloadingView.ts +1 -1
  114. package/front_end/panels/changes/ChangesSidebar.ts +2 -0
  115. package/front_end/panels/changes/CombinedDiffView.ts +2 -0
  116. package/front_end/panels/common/AnnotationManager.ts +71 -0
  117. package/front_end/panels/common/PersistenceUtils.ts +6 -7
  118. package/front_end/panels/common/common.ts +1 -0
  119. package/front_end/panels/console/ConsolePrompt.ts +4 -4
  120. package/front_end/panels/console/ConsoleView.ts +5 -4
  121. package/front_end/panels/console/ConsoleViewMessage.ts +16 -15
  122. package/front_end/panels/console/console-meta.ts +0 -13
  123. package/front_end/panels/console_counters/WarningErrorCounter.ts +2 -0
  124. package/front_end/panels/css_overview/CSSOverviewCompletedView.ts +1 -1
  125. package/front_end/panels/developer_resources/DeveloperResourcesView.ts +3 -1
  126. package/front_end/panels/elements/CSSRuleValidator.ts +7 -7
  127. package/front_end/panels/elements/CSSRuleValidatorHelper.ts +2 -2
  128. package/front_end/panels/elements/ColorSwatchPopoverIcon.ts +3 -3
  129. package/front_end/panels/elements/ElementsPanel.ts +49 -0
  130. package/front_end/panels/elements/ElementsTreeElement.ts +172 -121
  131. package/front_end/panels/elements/ElementsTreeOutline.ts +11 -3
  132. package/front_end/panels/elements/LayoutPane.ts +12 -10
  133. package/front_end/panels/elements/ShortcutTreeElement.ts +2 -2
  134. package/front_end/panels/elements/StyleEditorWidget.ts +2 -2
  135. package/front_end/panels/elements/StylePropertyTreeElement.ts +18 -18
  136. package/front_end/panels/elements/StylesSidebarPane.ts +4 -5
  137. package/front_end/panels/elements/TopLayerContainer.ts +2 -2
  138. package/front_end/panels/elements/components/AdornerManager.ts +3 -3
  139. package/front_end/panels/elements/components/ElementsBreadcrumbs.ts +1 -1
  140. package/front_end/panels/elements/components/ElementsTreeExpandButton.ts +1 -1
  141. package/front_end/panels/elements/components/QueryContainer.ts +1 -1
  142. package/front_end/panels/elements/components/StylePropertyEditor.ts +7 -7
  143. package/front_end/panels/emulation/DeviceModeWrapper.ts +48 -3
  144. package/front_end/panels/explain/components/ConsoleInsight.ts +6 -4
  145. package/front_end/panels/issues/AffectedResourcesView.ts +2 -2
  146. package/front_end/panels/issues/AttributionReportingIssueDetailsView.ts +2 -2
  147. package/front_end/panels/issues/IssueKindView.ts +2 -2
  148. package/front_end/panels/issues/IssueView.ts +4 -4
  149. package/front_end/panels/js_timeline/js_timeline-meta.ts +4 -2
  150. package/front_end/panels/linear_memory_inspector/components/LinearMemoryHighlightChipList.ts +28 -50
  151. package/front_end/panels/linear_memory_inspector/components/LinearMemoryInspector.ts +15 -11
  152. package/front_end/panels/linear_memory_inspector/components/LinearMemoryNavigator.ts +1 -1
  153. package/front_end/panels/linear_memory_inspector/components/LinearMemoryValueInterpreter.ts +1 -1
  154. package/front_end/panels/linear_memory_inspector/components/ValueInterpreterDisplay.ts +1 -1
  155. package/front_end/panels/media/PlayerListView.ts +100 -73
  156. package/front_end/panels/media/playerListView.css +5 -0
  157. package/front_end/panels/mobile_throttling/ThrottlingManager.ts +2 -2
  158. package/front_end/panels/mobile_throttling/ThrottlingSettingsTab.ts +4 -5
  159. package/front_end/panels/network/NetworkDataGridNode.ts +3 -3
  160. package/front_end/panels/network/NetworkFrameGrouper.ts +2 -2
  161. package/front_end/panels/network/NetworkItemView.ts +4 -4
  162. package/front_end/panels/network/NetworkLogViewColumns.ts +3 -3
  163. package/front_end/panels/network/RequestConditionsDrawer.ts +5 -5
  164. package/front_end/panels/network/RequestCookiesView.ts +2 -2
  165. package/front_end/panels/network/SignedExchangeInfoView.ts +2 -2
  166. package/front_end/panels/network/components/DirectSocketConnectionView.ts +17 -0
  167. package/front_end/panels/network/components/RequestTrustTokensView.ts +5 -6
  168. package/front_end/panels/network/resourceChunkView.css +4 -0
  169. package/front_end/panels/profiler/HeapSnapshotGridNodes.ts +3 -3
  170. package/front_end/panels/profiler/ProfileDataGrid.ts +2 -2
  171. package/front_end/panels/profiler/ProfilesPanel.ts +2 -2
  172. package/front_end/panels/protocol_monitor/JSONEditor.ts +1 -1
  173. package/front_end/panels/recorder/components/CreateRecordingView.ts +1 -1
  174. package/front_end/panels/recorder/components/ExtensionView.ts +1 -1
  175. package/front_end/panels/recorder/components/RecordingListView.ts +1 -1
  176. package/front_end/panels/recorder/components/RecordingView.ts +1 -1
  177. package/front_end/panels/recorder/components/StepView.ts +1 -1
  178. package/front_end/panels/screencast/ScreencastView.ts +8 -8
  179. package/front_end/panels/search/SearchView.ts +1 -1
  180. package/front_end/panels/security/CookieControlsTreeElement.ts +2 -2
  181. package/front_end/panels/security/CookieControlsView.ts +1 -1
  182. package/front_end/panels/security/CookieReportTreeElement.ts +2 -2
  183. package/front_end/panels/security/SecurityPanel.ts +5 -5
  184. package/front_end/panels/security/SecurityPanelSidebar.ts +3 -4
  185. package/front_end/panels/sensors/LocationsSettingsTab.ts +1 -1
  186. package/front_end/panels/settings/FrameworkIgnoreListSettingsTab.ts +1 -1
  187. package/front_end/panels/settings/KeybindsSettingsTab.ts +5 -5
  188. package/front_end/panels/settings/SettingsScreen.ts +7 -8
  189. package/front_end/panels/settings/WorkspaceSettingsTab.ts +1 -1
  190. package/front_end/panels/settings/emulation/DevicesSettingsTab.ts +1 -1
  191. package/front_end/panels/snippets/SnippetsQuickOpen.ts +16 -6
  192. package/front_end/panels/sources/BreakpointEditDialog.ts +3 -3
  193. package/front_end/panels/sources/BreakpointsView.ts +1 -1
  194. package/front_end/panels/sources/CSSPlugin.ts +4 -4
  195. package/front_end/panels/sources/CallStackSidebarPane.ts +4 -4
  196. package/front_end/panels/sources/DebuggerPausedMessage.ts +3 -3
  197. package/front_end/panels/sources/FilteredUISourceCodeListProvider.ts +40 -23
  198. package/front_end/panels/sources/GoToLineQuickOpen.ts +11 -5
  199. package/front_end/panels/sources/NavigatorView.ts +4 -4
  200. package/front_end/panels/sources/OpenFileQuickOpen.ts +11 -16
  201. package/front_end/panels/sources/OutlineQuickOpen.ts +23 -23
  202. package/front_end/panels/sources/ProfilePlugin.ts +21 -12
  203. package/front_end/panels/sources/SourcesView.ts +2 -2
  204. package/front_end/panels/sources/TabbedEditorContainer.ts +4 -5
  205. package/front_end/panels/sources/ThreadsSidebarPane.ts +2 -2
  206. package/front_end/panels/sources/UISourceCodeFrame.ts +5 -6
  207. package/front_end/panels/sources/filteredUISourceCodeListProvider.css +41 -0
  208. package/front_end/panels/timeline/TimelineHistoryManager.ts +2 -2
  209. package/front_end/panels/timeline/TimelinePanel.ts +29 -25
  210. package/front_end/panels/timeline/TimelineSelectorStatsView.ts +3 -3
  211. package/front_end/panels/timeline/components/CPUThrottlingSelector.ts +1 -1
  212. package/front_end/panels/timeline/components/LiveMetricsView.ts +1 -1
  213. package/front_end/panels/timeline/components/NetworkRequestTooltip.ts +1 -1
  214. package/front_end/panels/timeline/components/NetworkThrottlingSelector.ts +1 -1
  215. package/front_end/panels/timeline/components/OriginMap.ts +1 -1
  216. package/front_end/panels/timeline/components/insights/Checklist.ts +1 -1
  217. package/front_end/panels/timeline/components/insights/DOMSize.ts +1 -1
  218. package/front_end/panels/timeline/components/insights/ImageDelivery.ts +1 -1
  219. package/front_end/panels/timeline/components/insights/NetworkDependencyTree.ts +1 -1
  220. package/front_end/panels/timeline/components/insights/SlowCSSSelector.ts +2 -2
  221. package/front_end/panels/timeline/docs/flame_chart_migration.md +11 -16
  222. package/front_end/panels/timeline/overlays/components/EntriesLinkOverlay.ts +1 -1
  223. package/front_end/panels/timeline/overlays/components/EntryLabelOverlay.ts +1 -1
  224. package/front_end/panels/timeline/timeline-meta.ts +3 -2
  225. package/front_end/panels/utils/utils.ts +18 -3
  226. package/front_end/panels/whats_new/ReleaseNoteText.ts +10 -20
  227. package/front_end/panels/whats_new/resources/WNDT.md +8 -8
  228. package/front_end/third_party/chromium/README.chromium +1 -1
  229. package/front_end/third_party/puppeteer/third_party/mitt/README.chromium +1 -0
  230. package/front_end/third_party/puppeteer/third_party/parsel/README.chromium +1 -0
  231. package/front_end/third_party/puppeteer/third_party/rxjs/README.chromium +1 -0
  232. package/front_end/ui/components/adorners/Adorner.ts +21 -1
  233. package/front_end/ui/components/annotations/AnnotationRepository.ts +98 -0
  234. package/front_end/ui/components/annotations/AnnotationType.ts +10 -0
  235. package/front_end/ui/components/annotations/annotations.ts +6 -0
  236. package/front_end/ui/components/buttons/Button.ts +2 -2
  237. package/front_end/ui/components/buttons/FloatingButton.ts +2 -2
  238. package/front_end/ui/components/chrome_link/ChromeLink.ts +1 -1
  239. package/front_end/ui/components/dialogs/ButtonDialog.ts +1 -1
  240. package/front_end/ui/components/dialogs/Dialog.ts +1 -1
  241. package/front_end/ui/components/dialogs/ShortcutDialog.ts +1 -0
  242. package/front_end/ui/components/diff_view/DiffView.ts +1 -1
  243. package/front_end/ui/components/expandable_list/ExpandableList.ts +1 -1
  244. package/front_end/ui/components/highlighting/HighlightElement.ts +16 -2
  245. package/front_end/ui/components/highlighting/MarkupHighlight.ts +162 -0
  246. package/front_end/ui/components/highlighting/highlighting.ts +7 -0
  247. package/front_end/ui/components/icon_button/FileSourceIcon.ts +2 -2
  248. package/front_end/ui/components/icon_button/IconButton.ts +2 -2
  249. package/front_end/ui/components/icon_button/icon_button.ts +0 -2
  250. package/front_end/ui/components/issue_counter/IssueCounter.ts +2 -2
  251. package/front_end/ui/components/issue_counter/IssueLinkIcon.ts +2 -2
  252. package/front_end/ui/components/legacy_wrapper/LegacyWrapper.ts +1 -1
  253. package/front_end/ui/components/linkifier/LinkifierImpl.ts +1 -1
  254. package/front_end/ui/components/list/List.ts +184 -0
  255. package/front_end/ui/components/list/list.css +90 -0
  256. package/front_end/ui/components/{cards/cards.ts → list/lists.ts} +3 -3
  257. package/front_end/ui/components/markdown_view/CodeBlock.ts +1 -1
  258. package/front_end/ui/components/markdown_view/MarkdownImage.ts +4 -4
  259. package/front_end/ui/components/markdown_view/MarkdownLink.ts +1 -1
  260. package/front_end/ui/components/markdown_view/MarkdownView.ts +1 -1
  261. package/front_end/ui/components/menus/Menu.ts +1 -1
  262. package/front_end/ui/components/menus/SelectMenu.ts +1 -1
  263. package/front_end/ui/components/node_text/NodeText.ts +1 -1
  264. package/front_end/ui/components/panel_feedback/FeedbackButton.ts +1 -1
  265. package/front_end/ui/components/panel_feedback/PanelFeedback.ts +1 -1
  266. package/front_end/ui/components/panel_feedback/PreviewToggle.ts +1 -1
  267. package/front_end/ui/components/panel_introduction_steps/PanelIntroductionSteps.ts +1 -1
  268. package/front_end/ui/components/report_view/ReportView.ts +1 -1
  269. package/front_end/ui/components/request_link_icon/RequestLinkIcon.ts +2 -2
  270. package/front_end/ui/components/settings/SettingCheckbox.ts +1 -1
  271. package/front_end/ui/components/settings/SettingDeprecationWarning.ts +2 -2
  272. package/front_end/ui/components/snackbars/Snackbar.ts +1 -1
  273. package/front_end/ui/components/spinners/Spinner.ts +1 -1
  274. package/front_end/ui/components/srgb_overlay/SrgbOverlay.ts +1 -1
  275. package/front_end/ui/components/suggestion_input/SuggestionInput.ts +1 -0
  276. package/front_end/ui/components/survey_link/SurveyLink.ts +2 -2
  277. package/front_end/ui/components/switch/SwitchImpl.ts +1 -1
  278. package/front_end/ui/components/text_editor/TextEditor.ts +1 -0
  279. package/front_end/ui/components/text_editor/config.ts +2 -2
  280. package/front_end/ui/components/text_prompt/TextPrompt.ts +1 -1
  281. package/front_end/ui/components/tooltips/Tooltip.ts +1 -1
  282. package/front_end/ui/components/tree_outline/TreeOutline.ts +1 -1
  283. package/front_end/ui/kit/cards/Card.docs.ts +43 -0
  284. package/front_end/ui/{components/icon_button → kit/icons}/Icon.docs.ts +3 -4
  285. package/front_end/ui/{components/icon_button → kit/icons}/Icon.ts +6 -4
  286. package/front_end/ui/kit/kit.ts +6 -0
  287. package/front_end/ui/legacy/Infobar.ts +3 -3
  288. package/front_end/ui/legacy/InspectorView.ts +3 -3
  289. package/front_end/ui/legacy/SearchableView.ts +2 -2
  290. package/front_end/ui/legacy/SoftContextMenu.ts +5 -5
  291. package/front_end/ui/legacy/SoftDropDown.ts +2 -2
  292. package/front_end/ui/legacy/TabbedPane.ts +106 -8
  293. package/front_end/ui/legacy/Toolbar.ts +3 -3
  294. package/front_end/ui/legacy/Treeoutline.ts +2 -2
  295. package/front_end/ui/legacy/UIUtils.ts +4 -188
  296. package/front_end/ui/legacy/ViewManager.ts +27 -12
  297. package/front_end/ui/legacy/ViewRegistration.ts +21 -22
  298. package/front_end/ui/legacy/components/color_picker/ContrastDetails.ts +8 -8
  299. package/front_end/ui/legacy/components/color_picker/Spectrum.ts +4 -4
  300. package/front_end/ui/legacy/components/cookie_table/CookiesTable.ts +4 -4
  301. package/front_end/ui/legacy/components/inline_editor/FontEditor.ts +2 -2
  302. package/front_end/ui/legacy/components/inline_editor/Swatches.ts +5 -5
  303. package/front_end/ui/legacy/components/object_ui/CustomPreviewComponent.ts +3 -3
  304. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +5 -4
  305. package/front_end/ui/legacy/components/perf_ui/LineLevelProfile.ts +73 -35
  306. package/front_end/ui/legacy/components/perf_ui/LiveHeapProfile.ts +11 -2
  307. package/front_end/ui/legacy/components/perf_ui/OverviewGrid.ts +3 -3
  308. package/front_end/ui/legacy/components/quick_open/CommandMenu.ts +23 -31
  309. package/front_end/ui/legacy/components/quick_open/FilteredListWidget.ts +11 -27
  310. package/front_end/ui/legacy/components/quick_open/HelpQuickOpen.ts +11 -15
  311. package/front_end/ui/legacy/components/quick_open/filteredListWidget.css +18 -65
  312. package/front_end/ui/legacy/components/source_frame/JSONView.ts +2 -1
  313. package/front_end/ui/legacy/components/utils/Linkifier.ts +3 -3
  314. package/front_end/ui/legacy/tabbedPane.css +10 -0
  315. package/front_end/ui/visual_logging/KnownContextValues.ts +3 -0
  316. package/inspector_overlay/README.md +3 -3
  317. package/mcp/HostBindings.ts +310 -0
  318. package/mcp/mcp.ts +18 -0
  319. package/mcp/tsconfig.json +6 -1
  320. package/package.json +26 -24
  321. /package/front_end/ui/{components → kit}/cards/Card.ts +0 -0
  322. /package/front_end/ui/{components → kit}/cards/card.css +0 -0
  323. /package/front_end/ui/{components/icon_button → kit/icons}/icon.css +0 -0
@@ -71,9 +71,9 @@ export class AiConversation {
71
71
  ) {
72
72
  this.#changeManager = changeManager;
73
73
  this.#aidaClient = aidaClient;
74
- this.#agent = this.#createAgent(type);
75
-
76
74
  this.type = type;
75
+ this.#agent = this.#createAgent();
76
+
77
77
  this.id = id;
78
78
  this.#isReadOnly = isReadOnly;
79
79
  this.#isExternal = isExternal;
@@ -212,14 +212,14 @@ export class AiConversation {
212
212
  };
213
213
  }
214
214
 
215
- #createAgent(conversationType: ConversationType): AiAgent<unknown> {
215
+ #createAgent(): AiAgent<unknown> {
216
216
  const options = {
217
217
  aidaClient: this.#aidaClient,
218
218
  serverSideLoggingEnabled: isAiAssistanceServerSideLoggingEnabled(),
219
219
  changeManager: this.#changeManager,
220
220
  };
221
221
  let agent: AiAgent<unknown>;
222
- switch (conversationType) {
222
+ switch (this.type) {
223
223
  case ConversationType.STYLING: {
224
224
  agent = new StylingAgent(options);
225
225
  break;
@@ -251,6 +251,7 @@ export class AiConversation {
251
251
  ): AsyncGenerator<ResponseData, void, void> {
252
252
  for await (const data of this.#agent.run(initialQuery, options, multimodalInput)) {
253
253
  // We don't want to save partial responses to the conversation history.
254
+ // TODO(crbug.com/463325400): We should save interleaved answers to the history as well.
254
255
  if (data.type !== ResponseType.ANSWER || data.complete) {
255
256
  void this.addHistoryItem(data);
256
257
  }
@@ -2,6 +2,7 @@
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
 
5
+ import * as Common from '../../core/common/common.js';
5
6
  import * as Host from '../../core/host/host.js';
6
7
  import * as Root from '../../core/root/root.js';
7
8
 
@@ -23,11 +24,13 @@ export const enum LanguageModelAvailability {
23
24
  DISABLED = 'disabled',
24
25
  }
25
26
 
26
- export class BuiltInAi {
27
+ export class BuiltInAi extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
27
28
  #availability: LanguageModelAvailability|null = null;
28
29
  #hasGpu: boolean;
29
30
  #consoleInsightsSession?: LanguageModel;
30
31
  initDoneForTesting: Promise<void>;
32
+ #downloadProgress: number|null = null;
33
+ #currentlyCreatingSession = false;
31
34
 
32
35
  static instance(): BuiltInAi {
33
36
  if (builtInAiInstance === undefined) {
@@ -37,9 +40,10 @@ export class BuiltInAi {
37
40
  }
38
41
 
39
42
  constructor() {
43
+ super();
40
44
  this.#hasGpu = this.#isGpuAvailable();
41
45
  this.initDoneForTesting =
42
- this.getLanguageModelAvailability().then(() => this.initialize()).then(() => this.#sendAvailabilityMetrics());
46
+ this.getLanguageModelAvailability().then(() => this.#sendAvailabilityMetrics()).then(() => this.initialize());
43
47
  }
44
48
 
45
49
  async getLanguageModelAvailability(): Promise<LanguageModelAvailability> {
@@ -49,14 +53,59 @@ export class BuiltInAi {
49
53
  }
50
54
  try {
51
55
  // @ts-expect-error
52
- this.#availability = await window.LanguageModel.availability(
53
- {expectedOutputs: [{type: 'text', languages: ['en']}]}) as LanguageModelAvailability;
56
+ this.#availability = await window.LanguageModel.availability({
57
+ expectedInputs: [{
58
+ type: 'text',
59
+ languages: ['en'],
60
+ }],
61
+ expectedOutputs: [{
62
+ type: 'text',
63
+ languages: ['en'],
64
+ }],
65
+ }) as LanguageModelAvailability;
54
66
  } catch {
55
67
  this.#availability = LanguageModelAvailability.UNAVAILABLE;
56
68
  }
57
69
  return this.#availability;
58
70
  }
59
71
 
72
+ isDownloading(): boolean {
73
+ return this.#availability === LanguageModelAvailability.DOWNLOADING;
74
+ }
75
+
76
+ isEventuallyAvailable(): boolean {
77
+ if (!this.#hasGpu && !Boolean(Root.Runtime.hostConfig.devToolsAiPromptApi?.allowWithoutGpu)) {
78
+ return false;
79
+ }
80
+ return this.#availability === LanguageModelAvailability.AVAILABLE ||
81
+ this.#availability === LanguageModelAvailability.DOWNLOADING ||
82
+ this.#availability === LanguageModelAvailability.DOWNLOADABLE;
83
+ }
84
+
85
+ #setDownloadProgress(newValue: number): void {
86
+ this.#downloadProgress = newValue;
87
+ this.dispatchEventToListeners(Events.DOWNLOAD_PROGRESS_CHANGED, this.#downloadProgress);
88
+ }
89
+
90
+ getDownloadProgress(): number|null {
91
+ return this.#downloadProgress;
92
+ }
93
+
94
+ startDownloadingModel(): void {
95
+ if (!Root.Runtime.hostConfig.devToolsAiPromptApi?.allowWithoutGpu && !this.#hasGpu) {
96
+ return;
97
+ }
98
+ if (this.#availability !== LanguageModelAvailability.DOWNLOADABLE) {
99
+ return;
100
+ }
101
+
102
+ void this.#createSession();
103
+ // Without the timeout, the returned availability would still be `downloadable`
104
+ setTimeout(() => {
105
+ void this.getLanguageModelAvailability();
106
+ }, 1000);
107
+ }
108
+
60
109
  #isGpuAvailable(): boolean {
61
110
  const canvas = document.createElement('canvas');
62
111
  try {
@@ -86,16 +135,29 @@ export class BuiltInAi {
86
135
  if (!Root.Runtime.hostConfig.devToolsAiPromptApi?.allowWithoutGpu && !this.#hasGpu) {
87
136
  return;
88
137
  }
89
- if (this.#availability !== LanguageModelAvailability.AVAILABLE) {
138
+ if (this.#availability !== LanguageModelAvailability.AVAILABLE &&
139
+ this.#availability !== LanguageModelAvailability.DOWNLOADING) {
90
140
  return;
91
141
  }
92
142
  await this.#createSession();
93
143
  }
94
144
 
95
145
  async #createSession(): Promise<void> {
146
+ if (this.#currentlyCreatingSession) {
147
+ return;
148
+ }
149
+ this.#currentlyCreatingSession = true;
150
+
151
+ const monitor = (m: EventTarget): void => {
152
+ m.addEventListener('downloadprogress', ((e: {loaded: number}) => {
153
+ this.#setDownloadProgress(e.loaded);
154
+ }) as unknown as EventListener);
155
+ };
156
+
96
157
  try {
97
158
  // @ts-expect-error
98
159
  this.#consoleInsightsSession = await window.LanguageModel.create({
160
+ monitor,
99
161
  initialPrompts: [{
100
162
  role: 'system',
101
163
  content: `
@@ -125,11 +187,13 @@ Your instructions are as follows:
125
187
  }],
126
188
  });
127
189
  if (this.#availability !== LanguageModelAvailability.AVAILABLE) {
190
+ this.dispatchEventToListeners(Events.DOWNLOADED_AND_SESSION_CREATED);
128
191
  void this.getLanguageModelAvailability();
129
192
  }
130
193
  } catch (e) {
131
194
  console.error('Error when creating LanguageModel session', e.message);
132
195
  }
196
+ this.#currentlyCreatingSession = false;
133
197
  }
134
198
 
135
199
  static removeInstance(): void {
@@ -198,3 +262,13 @@ Your instructions are as follows:
198
262
  }
199
263
  }
200
264
  }
265
+
266
+ export const enum Events {
267
+ DOWNLOAD_PROGRESS_CHANGED = 'downloadProgressChanged',
268
+ DOWNLOADED_AND_SESSION_CREATED = 'downloadedAndSessionCreated',
269
+ }
270
+
271
+ export interface EventTypes {
272
+ [Events.DOWNLOAD_PROGRESS_CHANGED]: number;
273
+ [Events.DOWNLOADED_AND_SESSION_CREATED]: void;
274
+ }
@@ -31,9 +31,9 @@ function formatStyles(styles: Record<string, string>, indent = 2): string {
31
31
  export class ChangeManager {
32
32
  readonly #stylesheetMutex = new Common.Mutex.Mutex();
33
33
  readonly #cssModelToStylesheetId =
34
- new Map<SDK.CSSModel.CSSModel, Map<Protocol.Page.FrameId, Protocol.CSS.StyleSheetId>>();
35
- readonly #stylesheetChanges = new Map<Protocol.CSS.StyleSheetId, Change[]>();
36
- readonly #backupStylesheetChanges = new Map<Protocol.CSS.StyleSheetId, Change[]>();
34
+ new Map<SDK.CSSModel.CSSModel, Map<Protocol.Page.FrameId, Protocol.DOM.StyleSheetId>>();
35
+ readonly #stylesheetChanges = new Map<Protocol.DOM.StyleSheetId, Change[]>();
36
+ readonly #backupStylesheetChanges = new Map<Protocol.DOM.StyleSheetId, Change[]>();
37
37
 
38
38
  constructor() {
39
39
  SDK.TargetManager.TargetManager.instance().addModelListener(
@@ -147,7 +147,7 @@ ${formatStyles(change.styles)}
147
147
  }
148
148
 
149
149
  async #getStylesheet(cssModel: SDK.CSSModel.CSSModel, frameId: Protocol.Page.FrameId):
150
- Promise<Protocol.CSS.StyleSheetId> {
150
+ Promise<Protocol.DOM.StyleSheetId> {
151
151
  return await this.#stylesheetMutex.run(async () => {
152
152
  let frameToStylesheet = this.#cssModelToStylesheetId.get(cssModel);
153
153
  if (!frameToStylesheet) {
@@ -14,7 +14,6 @@ import {
14
14
  type AiAgent,
15
15
  type ExternalRequestResponse,
16
16
  ExternalRequestResponseType,
17
- type ResponseData,
18
17
  ResponseType
19
18
  } from './agents/AiAgent.js';
20
19
  import {NetworkAgent, RequestContext} from './agents/NetworkAgent.js';
@@ -204,20 +203,6 @@ export class ConversationHandler extends Common.ObjectWrapper.ObjectWrapper<Even
204
203
  }
205
204
  }
206
205
 
207
- async *
208
- handleConversationWithHistory(
209
- items: AsyncIterable<ResponseData, void, void>,
210
- conversation: AiConversation|undefined,
211
- ): AsyncGenerator<ResponseData, void, void> {
212
- for await (const data of items) {
213
- // We don't want to save partial responses to the conversation history.
214
- if (data.type !== ResponseType.ANSWER || data.complete) {
215
- void conversation?.addHistoryItem(data);
216
- }
217
- yield data;
218
- }
219
- }
220
-
221
206
  async * #createAndDoExternalConversation(opts: {
222
207
  conversationType: ConversationType,
223
208
  aiAgent: AiAgent<unknown>,
@@ -237,7 +237,8 @@ export interface FunctionDeclaration<Args extends Record<string, unknown>, Retur
237
237
  /**
238
238
  * Function implementation that the LLM will try to execute,
239
239
  */
240
- handler: (args: Args, options?: FunctionHandlerOptions) => Promise<FunctionCallHandlerResult<ReturnType>>;
240
+
241
+ handler(args: Args, options?: FunctionHandlerOptions): Promise<FunctionCallHandlerResult<ReturnType>>;
241
242
  }
242
243
 
243
244
  interface AidaFetchResult {
@@ -618,10 +619,12 @@ export abstract class AiAgent<T> {
618
619
  }
619
620
  }
620
621
 
621
- async * #callFunction(name: string, args: Record<string, unknown>, options?: {
622
- signal?: AbortSignal,
623
- approved?: boolean,
624
- }): AsyncGenerator<FunctionCallResponseData, {result: unknown}> {
622
+ async *
623
+ #callFunction(
624
+ name: string,
625
+ args: Record<string, unknown>,
626
+ options?: FunctionHandlerOptions,
627
+ ): AsyncGenerator<FunctionCallResponseData, {result: unknown}> {
625
628
  const call = this.#functionDeclarations.get(name);
626
629
  if (!call) {
627
630
  throw new Error(`Function ${name} is not found.`);
@@ -655,7 +658,7 @@ export abstract class AiAgent<T> {
655
658
  }
656
659
  }
657
660
 
658
- let result = await call.handler(args, options) as FunctionCallHandlerResult<unknown>;
661
+ let result = await call.handler(args, options);
659
662
 
660
663
  if ('requiresApproval' in result) {
661
664
  if (code) {
@@ -9,6 +9,8 @@ import * as Platform from '../../../core/platform/platform.js';
9
9
  import * as Root from '../../../core/root/root.js';
10
10
  import * as SDK from '../../../core/sdk/sdk.js';
11
11
  import * as Tracing from '../../../services/tracing/tracing.js';
12
+ import * as Annotations from '../../../ui/components/annotations/annotations.js';
13
+ import * as SourceMapScopes from '../../source_map_scopes/source_map_scopes.js';
12
14
  import * as Trace from '../../trace/trace.js';
13
15
  import {
14
16
  PerformanceInsightFormatter,
@@ -23,6 +25,7 @@ import {
23
25
  type ContextResponse,
24
26
  ConversationContext,
25
27
  type ConversationSuggestions,
28
+ type FunctionCallHandlerResult,
26
29
  type ParsedResponse,
27
30
  type RequestOptions,
28
31
  type ResponseData,
@@ -44,6 +47,7 @@ const UIStringsNotTranslated = {
44
47
  mainThreadActivity: 'Investigating main thread activity…',
45
48
  } as const;
46
49
  const lockedString = i18n.i18n.lockedString;
50
+ const annotationsEnabled = Annotations.AnnotationRepository.annotationsEnabled();
47
51
 
48
52
  /**
49
53
  * WARNING: preamble defined in code is only used when userTier is
@@ -51,6 +55,16 @@ const lockedString = i18n.i18n.lockedString;
51
55
  * chrome_preambles.gcl). Sync local changes with the server-side.
52
56
  */
53
57
 
58
+ const greenDevAdditionalFunction = `
59
+ - CRITICAL:You also have access to a function called addElementAnnotation, which should be used to highlight elements.`;
60
+
61
+ const greenDevAdditionalGuidelines = `
62
+ - CRITICAL: Each time an element with a nodeId is mentioned, you MUST ALSO call the function addElementAnnotation for that element.
63
+ - The addElementAnnotation function should be called as soon as you identify an element that needs to be highlighted.
64
+ - The addElementAnnotation function should always be called for the LCP element, if known.
65
+ - The annotationMessage should be descriptive and relevant to why the element is being highlighted.
66
+ `;
67
+
54
68
  /**
55
69
  * Preamble clocks in at ~1341 tokens.
56
70
  * The prose is around 4.5 chars per token.
@@ -68,6 +82,8 @@ Don't mention anything about an insight without first getting more data about it
68
82
 
69
83
  You have many functions available to learn more about the trace. Use these to confirm hypotheses, or to further explore the trace when diagnosing performance issues.
70
84
 
85
+ ${annotationsEnabled ? greenDevAdditionalFunction : ''}
86
+
71
87
  You will be given bounds representing a time range within the trace. Bounds include a min and a max time in microseconds. max is always bigger than min in a bounds.
72
88
 
73
89
  The 3 main performance metrics are:
@@ -108,6 +124,8 @@ Note: if the user asks a specific question about the trace (such as "What is my
108
124
  - Structure your response using markdown headings and bullet points for improved readability.
109
125
  - Be direct and to the point. Avoid unnecessary introductory phrases or filler content. Focus on delivering actionable advice efficiently.
110
126
 
127
+ ${annotationsEnabled ? greenDevAdditionalGuidelines : ''}
128
+
111
129
  ## Strict Constraints
112
130
 
113
131
  Adhere to the following critical requirements:
@@ -135,6 +153,11 @@ When referring to a trace event that has a corresponding \`eventKey\`, annotate
135
153
  When asking the user to make a choice between multiple options, output a list of choices at the end of your text response. The format is \`SUGGESTIONS: ["suggestion1", "suggestion2", "suggestion3"]\`. This MUST start on a newline, and be a single line.
136
154
  `;
137
155
 
156
+ const greenDevAdditionalGuidelineFreshTrace = `
157
+ When referring to an element for which you know the nodeId, always call the function addElementAnnotation, specifying the id and an annotation reason.
158
+ - CRITICAL: Each time you add an annotating link you MUST ALSO call the function addElementAnnotation.
159
+ `;
160
+
138
161
  const extraPreambleWhenFreshTrace = `Additional notes:
139
162
 
140
163
  When referring to an element for which you know the nodeId, annotate your output using markdown link syntax:
@@ -142,7 +165,8 @@ When referring to an element for which you know the nodeId, annotate your output
142
165
  - This link will reveal the element in the Elements panel
143
166
  - Never mention node or nodeId when referring to the element, and especially not in the link text.
144
167
  - When referring to the LCP, it's useful to also mention what the LCP element is via its nodeId. Use the markdown link syntax to do so.
145
- `;
168
+
169
+ ${annotationsEnabled ? greenDevAdditionalGuidelineFreshTrace : ''}`;
146
170
 
147
171
  enum ScorePriority {
148
172
  REQUIRED = 3,
@@ -310,7 +334,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
310
334
  return Host.AidaClient.ClientFeature.CHROME_PERFORMANCE_FULL_AGENT;
311
335
  }
312
336
  get userTier(): string|undefined {
313
- return Root.Runtime.hostConfig.devToolsAiAssistancePerformanceAgent?.userTier;
337
+ return annotationsEnabled ? 'TESTERS' : Root.Runtime.hostConfig.devToolsAiAssistancePerformanceAgent?.userTier;
314
338
  }
315
339
  get options(): RequestOptions {
316
340
  const temperature = Root.Runtime.hostConfig.devToolsAiAssistancePerformanceAgent?.temperature;
@@ -883,12 +907,107 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
883
907
 
884
908
  });
885
909
 
910
+ if (annotationsEnabled) {
911
+ this.declareFunction<{
912
+ elementId: string,
913
+ annotationMessage: string,
914
+ }>('addElementAnnotation', {
915
+ description:
916
+ 'Adds a visual annotation in the Elements panel, attached to a node with the specific UID provided. Use it to highlight nodes in the Elements panel and provide contextual suggestions to the user related to their queries.',
917
+ parameters: {
918
+ type: Host.AidaClient.ParametersTypes.OBJECT,
919
+ description: '',
920
+ nullable: false,
921
+ properties: {
922
+ elementId: {
923
+ type: Host.AidaClient.ParametersTypes.STRING,
924
+ description: 'The UID of the element to annotate.',
925
+ nullable: false,
926
+ },
927
+ annotationMessage: {
928
+ type: Host.AidaClient.ParametersTypes.STRING,
929
+ description: 'The message the annotation should show to the user.',
930
+ nullable: false,
931
+ },
932
+ },
933
+ },
934
+ handler: async params => {
935
+ return await this.addElementAnnotation(params.elementId, params.annotationMessage);
936
+ },
937
+ });
938
+ }
939
+
940
+ this.declareFunction<{scriptUrl: string, line: number, column: number}, {result: string}>('getFunctionCode', {
941
+ description: 'Returns the code for a function defined at the given location.',
942
+ parameters: {
943
+ type: Host.AidaClient.ParametersTypes.OBJECT,
944
+ description: '',
945
+ nullable: false,
946
+ properties: {
947
+ scriptUrl: {
948
+ type: Host.AidaClient.ParametersTypes.STRING,
949
+ description: 'The url of the function.',
950
+ nullable: false,
951
+ },
952
+ line: {
953
+ type: Host.AidaClient.ParametersTypes.INTEGER,
954
+ description: 'The line number where the function is defined.',
955
+ nullable: false,
956
+ },
957
+ column: {
958
+ type: Host.AidaClient.ParametersTypes.INTEGER,
959
+ description: 'The column number where the function is defined.',
960
+ nullable: false,
961
+ },
962
+ },
963
+ },
964
+ displayInfoFromArgs: args => {
965
+ return {
966
+ title: lockedString('Looking up function code…'),
967
+ action: `getFunctionCode('${args.scriptUrl}', ${args.line}, ${args.column})`
968
+ };
969
+ },
970
+ handler: async args => {
971
+ debugLog('Function call: getFunctionCode');
972
+
973
+ if (args.line === undefined) {
974
+ return {error: 'Missing arg: line'};
975
+ }
976
+
977
+ if (args.column === undefined) {
978
+ return {error: 'Missing arg: column'};
979
+ }
980
+
981
+ if (!this.#formatter) {
982
+ throw new Error('missing formatter');
983
+ }
984
+
985
+ const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
986
+ if (!target) {
987
+ throw new Error('missing target');
988
+ }
989
+
990
+ const url = args.scriptUrl as Platform.DevToolsPath.UrlString;
991
+ const code = await SourceMapScopes.FunctionCodeResolver.getFunctionCodeFromLocation(
992
+ target, url, args.line, args.column, {contextLength: 200, contextLineLength: 5, appendProfileData: true});
993
+ if (!code) {
994
+ return {error: 'Could not find code'};
995
+ }
996
+
997
+ const result = this.#formatter.formatFunctionCode(code);
998
+
999
+ const key = `getFunctionCode('${args.scriptUrl}', ${args.line}, ${args.column})`;
1000
+ this.#cacheFunctionResult(focus, key, result);
1001
+ return {result: {result}};
1002
+ },
1003
+ });
1004
+
886
1005
  const isFresh = Tracing.FreshRecording.Tracker.instance().recordingIsFresh(parsedTrace);
887
1006
  const isTraceApp = Root.Runtime.Runtime.isTraceApp();
888
1007
 
889
1008
  this.declareFunction<{url: string}, {content: string}>('getResourceContent', {
890
1009
  description:
891
- 'Returns the content of the resource with the given url. Only use this for text resource types. This function is helpful for getting script contents in order to further analyze main thread activity and suggest code improvements. When analyzing the main thread activity, always call this function to get more detail. Always call this function when asked to provide specifics about what is happening in the code. Never ask permission to call this function, just do it.',
1010
+ 'Returns the content of the resource with the given url. Only use this for text resource types. Prefer getFunctionCode when possible.',
892
1011
  parameters: {
893
1012
  type: Host.AidaClient.ParametersTypes.OBJECT,
894
1013
  description: '',
@@ -972,4 +1091,17 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
972
1091
  });
973
1092
  }
974
1093
  }
1094
+
1095
+ async addElementAnnotation(elementId: string, annotationMessage: string):
1096
+ Promise<FunctionCallHandlerResult<unknown>> {
1097
+ if (!Annotations.AnnotationRepository.annotationsEnabled()) {
1098
+ console.warn('Received agent request to add annotation with annotations disabled');
1099
+ return {error: 'Annotations are not currently enabled'};
1100
+ }
1101
+
1102
+ // eslint-disable-next-line no-console
1103
+ console.log(`AI AGENT EVENT: Performance Agent adding annotation for element ${elementId}: '${annotationMessage}'`);
1104
+ Annotations.AnnotationRepository.instance().addElementsAnnotation(annotationMessage, elementId);
1105
+ return {result: {success: true}};
1106
+ }
975
1107
  }
@@ -3,6 +3,7 @@
3
3
  // found in the LICENSE file.
4
4
 
5
5
  import * as CrUXManager from '../../crux-manager/crux-manager.js';
6
+ import type * as SourceMapScopes from '../../source_map_scopes/source_map_scopes.js';
6
7
  import * as Trace from '../../trace/trace.js';
7
8
  import type {AICallTree} from '../performance/AICallTree.js';
8
9
  import type {AgentFocus} from '../performance/AIContext.js';
@@ -813,4 +814,27 @@ The order of headers corresponds to an internal fixed list. If a header is not p
813
814
  ];
814
815
  return parts.join(';');
815
816
  }
817
+
818
+ formatFunctionCode(code: SourceMapScopes.FunctionCodeResolver.FunctionCode): string {
819
+ const {startLine, startColumn} = code.range;
820
+ const {
821
+ startLine: contextStartLine,
822
+ startColumn: contextStartColumn,
823
+ endLine: contextEndLine,
824
+ endColumn: contextEndColumn
825
+ } = code.rangeWithContext;
826
+ const name = code.functionBounds.name;
827
+ const url = code.functionBounds.uiSourceCode.url();
828
+
829
+ const parts = [];
830
+ parts.push(`${name} @ ${url}:${startLine}:${startColumn}. With added context, chunk is from ${contextStartLine}:${
831
+ contextStartColumn} to ${contextEndLine}:${contextEndColumn}`);
832
+ parts.push(
833
+ '\nThe following is a markdown block of JavaScript. <FUNCTION_START> and <FUNCTION_END> marks the exact function declaration, and everything outside that is provided for additional context. Comments at the end of each line indicate the runtime performance cost of that code. Do not show the user the function markers or the additional context.\n');
834
+ parts.push('```');
835
+ parts.push(code.codeWithContext);
836
+ parts.push('```');
837
+
838
+ return parts.join('\n');
839
+ }
816
840
  }
@@ -270,6 +270,49 @@ export class CompilerScriptMapping implements DebuggerSourceMapping {
270
270
  return ranges;
271
271
  }
272
272
 
273
+ async functionBoundsAtRawLocation(rawLocation: SDK.DebuggerModel.Location):
274
+ Promise<Workspace.UISourceCode.UIFunctionBounds|null> {
275
+ const script = rawLocation.script();
276
+ if (!script) {
277
+ return null;
278
+ }
279
+
280
+ const sourceMap = this.#sourceMapManager.sourceMapForClient(script);
281
+ if (!sourceMap) {
282
+ return null;
283
+ }
284
+
285
+ const {lineNumber, columnNumber} = script.rawLocationToRelativeLocation(rawLocation);
286
+ const {url, scope} = sourceMap.findOriginalFunctionScope({line: lineNumber, column: columnNumber}) ?? {};
287
+ if (!scope || !url) {
288
+ return null;
289
+ }
290
+
291
+ const project = this.#sourceMapToProject.get(sourceMap);
292
+ if (!project) {
293
+ return null;
294
+ }
295
+
296
+ const uiSourceCode = project.uiSourceCodeForURL(url);
297
+ if (!uiSourceCode) {
298
+ return null;
299
+ }
300
+
301
+ // If there's no original source content, callers can't get the source code for
302
+ // the given scope. Presently that's the only reason to get a function's bounds,
303
+ // so in that case return null and allow ResourceScriptMapping to fulfill this
304
+ // request.
305
+ const contentData = await uiSourceCode.requestContentData();
306
+ if ('error' in contentData) {
307
+ return null;
308
+ }
309
+
310
+ const name = scope.name ?? '';
311
+ const range =
312
+ new TextUtils.TextRange.TextRange(scope.start.line, scope.start.column, scope.end.line, scope.end.column);
313
+ return new Workspace.UISourceCode.UIFunctionBounds(uiSourceCode, range, name);
314
+ }
315
+
273
316
  translateRawFramesStep(
274
317
  rawFrames: StackTraceImpl.Trie.RawFrame[],
275
318
  translatedFrames: Awaited<ReturnType<StackTraceImpl.StackTraceModel.TranslateRawFrames>>): boolean {
@@ -338,6 +338,13 @@ export class DebuggerWorkspaceBinding implements SDK.TargetManager.SDKModelObser
338
338
  return [];
339
339
  }
340
340
 
341
+ async functionBoundsAtRawLocation(rawLocation: SDK.DebuggerModel.Location):
342
+ Promise<Workspace.UISourceCode.UIFunctionBounds|null> {
343
+ // TODO(crbug.com/463452667): first try pluginManager.
344
+ const modelData = this.#debuggerModelToData.get(rawLocation.debuggerModel);
345
+ return modelData ? await modelData.functionBoundsAtRawLocation(rawLocation) : null;
346
+ }
347
+
341
348
  async normalizeUILocation(uiLocation: Workspace.UISourceCode.UILocation): Promise<Workspace.UISourceCode.UILocation> {
342
349
  const rawLocations =
343
350
  await this.uiLocationToRawLocations(uiLocation.uiSourceCode, uiLocation.lineNumber, uiLocation.columnNumber);
@@ -582,6 +589,18 @@ class ModelData {
582
589
  return ranges;
583
590
  }
584
591
 
592
+ async functionBoundsAtRawLocation(rawLocation: SDK.DebuggerModel.Location):
593
+ Promise<Workspace.UISourceCode.UIFunctionBounds|null> {
594
+ let scope: Workspace.UISourceCode.UIFunctionBounds|null = null;
595
+ // Check source maps.
596
+ scope = scope || await this.compilerMapping.functionBoundsAtRawLocation(rawLocation);
597
+ // Check debugger scripts.
598
+ scope = scope || await this.#resourceScriptMapping.functionBoundsAtRawLocation(rawLocation);
599
+ // Check inline scripts inside HTML resources.
600
+ scope = scope || await this.#resourceMapping.functionBoundsAtRawLocation(rawLocation);
601
+ return scope;
602
+ }
603
+
585
604
  translateRawFramesStep(
586
605
  rawFrames: StackTraceImpl.Trie.RawFrame[],
587
606
  translatedFrames: Awaited<ReturnType<StackTraceImpl.StackTraceModel.TranslateRawFrames>>): void {