chrome-devtools-frontend 1.0.1726686 → 1.0.1730971

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 (490) hide show
  1. package/.agents/rules/tests/test-strict-assertions-and-literal-expectations.md +1 -1
  2. package/.agents/rules/tests/test-view-and-presenter-isolation.md +1 -1
  3. package/.agents/rules/ui-and-widgets/ui-accessibility-and-semantic-html.md +1 -1
  4. package/.agents/rules/ui-and-widgets/ui-css-scoping-and-flex-layout.md +2 -2
  5. package/.agents/rules/ui-and-widgets/ui-declarative-child-widget-composition.md +5 -5
  6. package/.agents/rules/ui-and-widgets/ui-lit-declarative-templates-and-directives.md +2 -2
  7. package/.agents/rules/ui-and-widgets/ui-localization-and-uistrings-hygiene.md +2 -2
  8. package/.agents/rules/ui-and-widgets/ui-modern-component-and-encapsulation-standards.md +3 -3
  9. package/.agents/rules/ui-and-widgets/ui-pure-view-and-presenter-separation.md +2 -2
  10. package/.agents/rules/ui-and-widgets/ui-reactive-widget-update-lifecycle.md +2 -2
  11. package/.agents/rules/ui-and-widgets/ui-view-output-and-callback-contracts.md +2 -2
  12. package/.agents/rules/ui-and-widgets/ui-widget-dom-and-listener-lifecycle.md +2 -2
  13. package/.agents/skills/code-review/SKILL.md +63 -12
  14. package/.agents/skills/ui-eng-vision-local-lit-renderer/SKILL.md +38 -10
  15. package/.agents/skills/ui-eng-vision-widget-promoter/SKILL.md +1 -0
  16. package/.agents/skills/ui-widgets/SKILL.md +8 -2
  17. package/.agents/skills/write-ai-eval-test/SKILL.md +106 -0
  18. package/AUTHORS +2 -0
  19. package/DIR_METADATA +1 -2
  20. package/README.md +48 -26
  21. package/config/typescript/tsconfig.base.json +1 -0
  22. package/config/typescript/tsconfig.eslint.json +1 -0
  23. package/docs/contributing/changes.md +25 -0
  24. package/docs/ui_engineering.md +13 -4
  25. package/eslint.config.mjs +323 -41
  26. package/front_end/core/common/Color.ts +7 -7
  27. package/front_end/core/common/ParsedURL.ts +3 -3
  28. package/front_end/core/common/ResolverBase.ts +3 -3
  29. package/front_end/core/common/SegmentedRange.ts +3 -3
  30. package/front_end/core/common/SimpleHistoryManager.ts +14 -14
  31. package/front_end/core/common/Trie.ts +3 -3
  32. package/front_end/core/common/VersionController.ts +7 -7
  33. package/front_end/core/host/InspectorFrontendHost.ts +2 -2
  34. package/front_end/core/host/InspectorFrontendHostAPI.ts +9 -1
  35. package/front_end/core/host/InspectorFrontendHostStub.ts +1 -1
  36. package/front_end/core/host/UserMetrics.ts +4 -0
  37. package/front_end/core/host/UserMetricsEnums.ts +2 -1
  38. package/front_end/core/platform/StringUtilities.ts +54 -13
  39. package/front_end/core/platform/node/HostRuntime.ts +13 -7
  40. package/front_end/core/protocol_client/DevToolsCDPConnection.ts +4 -5
  41. package/front_end/core/root/Runtime.ts +5 -0
  42. package/front_end/core/sdk/AccessibilityModel.ts +5 -5
  43. package/front_end/core/sdk/AnimationModel.ts +17 -19
  44. package/front_end/core/sdk/CPUProfilerModel.ts +3 -3
  45. package/front_end/core/sdk/CPUThrottlingManager.ts +7 -0
  46. package/front_end/core/sdk/CSSMatchedStyles.ts +73 -13
  47. package/front_end/core/sdk/CSSMetadata.ts +7 -7
  48. package/front_end/core/sdk/CSSModel.ts +33 -33
  49. package/front_end/core/sdk/CSSProperty.ts +5 -5
  50. package/front_end/core/sdk/CSSRule.ts +6 -6
  51. package/front_end/core/sdk/CSSStyleSheetHeader.ts +4 -4
  52. package/front_end/core/sdk/Connections.ts +16 -16
  53. package/front_end/core/sdk/ConsoleModel.ts +44 -47
  54. package/front_end/core/sdk/CookieParser.ts +11 -11
  55. package/front_end/core/sdk/EmulationModel.ts +35 -36
  56. package/front_end/core/sdk/EventBreakpointsModel.ts +11 -11
  57. package/front_end/core/sdk/FrameManager.ts +16 -16
  58. package/front_end/core/sdk/IsolateManager.ts +2 -2
  59. package/front_end/core/sdk/IssuesModel.ts +2 -2
  60. package/front_end/core/sdk/OverlayModel.ts +19 -19
  61. package/front_end/core/sdk/PageResourceLoader.ts +14 -16
  62. package/front_end/core/sdk/RemoteObject.ts +9 -9
  63. package/front_end/core/sdk/Resource.ts +2 -2
  64. package/front_end/core/sdk/RuntimeModel.ts +7 -7
  65. package/front_end/core/sdk/Script.ts +6 -6
  66. package/front_end/core/sdk/ServiceWorkerManager.ts +36 -10
  67. package/front_end/core/sdk/SourceMap.ts +18 -20
  68. package/front_end/core/sdk/SourceMapManager.ts +2 -2
  69. package/front_end/core/sdk/TargetManager.ts +2 -2
  70. package/front_end/devtools_compatibility.js +7 -3
  71. package/front_end/entrypoints/inspector_main/InspectorMain.ts +2 -2
  72. package/front_end/entrypoints/node_app/app/NodeConnectionsPanel.ts +203 -115
  73. package/front_end/generated/InspectorBackendCommands.ts +1 -1
  74. package/front_end/generated/SupportedCSSProperties.ts +1 -3
  75. package/front_end/generated/protocol.ts +1 -0
  76. package/front_end/models/ai_assistance/AiAgent2.ts +36 -12
  77. package/front_end/models/ai_assistance/AiConversation.ts +8 -2
  78. package/front_end/models/ai_assistance/agents/AiAgent.ts +137 -62
  79. package/front_end/models/ai_assistance/agents/ExecuteJavascript.ts +2 -2
  80. package/front_end/models/ai_assistance/agents/StylingAgent.snapshot.txt +2 -2
  81. package/front_end/models/ai_assistance/data_formatters/LighthouseFormatter.snapshot.txt +149 -2
  82. package/front_end/models/ai_assistance/data_formatters/LighthouseFormatter.ts +269 -42
  83. package/front_end/models/ai_assistance/tools/ExecuteJavaScript.ts +3 -0
  84. package/front_end/models/ai_assistance/tools/GetLighthouseAudits.ts +9 -0
  85. package/front_end/models/ai_assistance/tools/ResolveDevtoolsNodePath.ts +13 -2
  86. package/front_end/models/ai_assistance/tools/RunLighthouse.ts +23 -7
  87. package/front_end/models/ai_assistance/tools/Tool.ts +7 -5
  88. package/front_end/models/bindings/CSSWorkspaceBinding.ts +22 -24
  89. package/front_end/models/bindings/DebuggerLanguagePlugins.ts +60 -60
  90. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +24 -24
  91. package/front_end/models/bindings/DefaultScriptMapping.ts +8 -8
  92. package/front_end/models/bindings/FileUtils.ts +13 -13
  93. package/front_end/models/bindings/PresentationConsoleMessageHelper.ts +3 -3
  94. package/front_end/models/bindings/ResourceScriptMapping.ts +23 -23
  95. package/front_end/models/comment_manager/CommentManager.ts +3 -3
  96. package/front_end/models/comment_manager/CommentThread.ts +50 -5
  97. package/front_end/models/cpu_profile/CPUProfileDataModel.ts +14 -14
  98. package/front_end/models/cpu_profile/ProfileTreeModel.ts +4 -4
  99. package/front_end/models/elements/StyleChanges.ts +38 -0
  100. package/front_end/models/emulation/EmulatedDevices.ts +12 -12
  101. package/front_end/models/har/HARFormat.ts +4 -4
  102. package/front_end/models/javascript_metadata/NativeFunctions.ts +5 -1
  103. package/front_end/models/lighthouse/LighthouseReporterTypes.ts +57 -3
  104. package/front_end/models/lighthouse/RunTypes.ts +9 -1
  105. package/front_end/models/logs/LogManager.ts +2 -2
  106. package/front_end/models/persistence/AutomaticFileSystemManager.ts +3 -0
  107. package/front_end/models/persistence/FileSystemWorkspaceBinding.ts +24 -24
  108. package/front_end/models/persistence/IsolatedFileSystemManager.ts +6 -0
  109. package/front_end/models/persistence/NetworkPersistenceManager.ts +8 -3
  110. package/front_end/models/trace/LanternComputationData.ts +37 -11
  111. package/front_end/models/trace/Processor.ts +2 -1
  112. package/front_end/models/trace/extras/TraceTree.ts +36 -10
  113. package/front_end/models/trace/handlers/InitiatorsHandler.ts +27 -34
  114. package/front_end/models/trace/handlers/LayoutShiftsHandler.ts +2 -6
  115. package/front_end/models/trace/handlers/SamplesHandler.ts +9 -6
  116. package/front_end/models/workspace/FileManager.ts +6 -0
  117. package/front_end/panels/accessibility/ARIAAttributesView.ts +4 -4
  118. package/front_end/panels/accessibility/AccessibilityAnnouncementRecordingView.ts +8 -1
  119. package/front_end/panels/accessibility/AccessibilityNodeView.ts +15 -17
  120. package/front_end/panels/accessibility/AccessibilitySubPane.ts +1 -1
  121. package/front_end/panels/ai_assistance/AiAssistancePanel.ts +5 -5
  122. package/front_end/panels/ai_assistance/ExternalHandler.ts +10 -1
  123. package/front_end/panels/ai_assistance/components/ChatMessage.ts +27 -22
  124. package/front_end/panels/ai_assistance/components/DisabledWidget.ts +19 -23
  125. package/front_end/panels/ai_assistance/components/ExploreWidget.ts +2 -2
  126. package/front_end/panels/ai_assistance/components/PermissionPrompt.ts +23 -9
  127. package/front_end/panels/ai_assistance/components/chatInput.css +1 -1
  128. package/front_end/panels/animation/AnimationTimeline.ts +37 -17
  129. package/front_end/panels/animation/animationTimeline.css +19 -3
  130. package/front_end/panels/application/AppManifestView.ts +1 -2
  131. package/front_end/panels/application/ApplicationPanelSidebar.ts +143 -128
  132. package/front_end/panels/application/DOMStorageItemsView.ts +14 -14
  133. package/front_end/panels/application/DeviceBoundSessionsView.ts +10 -13
  134. package/front_end/panels/application/ExtensionStorageItemsView.ts +3 -4
  135. package/front_end/panels/application/IndexedDBViews.ts +8 -4
  136. package/front_end/panels/application/KeyValueStorageItemsView.ts +4 -5
  137. package/front_end/panels/application/PrivateVerificationTokensView.ts +53 -0
  138. package/front_end/panels/application/ServiceWorkerCacheViews.ts +12 -8
  139. package/front_end/panels/application/ServiceWorkersView.ts +1 -2
  140. package/front_end/panels/application/StorageItemsToolbar.ts +3 -3
  141. package/front_end/panels/application/StorageView.ts +2 -2
  142. package/front_end/panels/application/WebMCPView.ts +91 -109
  143. package/front_end/panels/application/application.ts +2 -0
  144. package/front_end/panels/application/components/StorageMetadataView.ts +6 -6
  145. package/front_end/panels/application/preloading/PreloadingView.ts +70 -37
  146. package/front_end/panels/application/preloading/components/MismatchedPreloadingGrid.ts +2 -2
  147. package/front_end/panels/application/preloading/components/PreloadingDisabledInfobar.ts +3 -3
  148. package/front_end/panels/application/preloading/components/PreloadingGrid.ts +12 -0
  149. package/front_end/panels/application/preloading/components/RuleSetDetailsView.ts +10 -11
  150. package/front_end/panels/application/privateVerificationTokensView.css +20 -0
  151. package/front_end/panels/application/serviceWorkersView.css +2 -2
  152. package/front_end/panels/browser_debugger/DOMBreakpointsSidebarPane.ts +24 -24
  153. package/front_end/panels/changes/ChangesSidebar.ts +5 -5
  154. package/front_end/panels/changes/ChangesView.ts +10 -11
  155. package/front_end/panels/comments/CommentsPane.ts +292 -102
  156. package/front_end/panels/comments/commentsPane.css +93 -12
  157. package/front_end/panels/common/CommentThreadWidget.ts +69 -0
  158. package/front_end/panels/common/CommentsOverlayWidget.ts +108 -29
  159. package/front_end/panels/common/CommentsStatusBarPill.ts +17 -6
  160. package/front_end/panels/common/DOMLinkifier.ts +37 -12
  161. package/front_end/panels/common/ExtensionPanel.ts +13 -4
  162. package/front_end/panels/common/ExtensionServer.ts +27 -3
  163. package/front_end/panels/common/PersistenceUtils.ts +3 -3
  164. package/front_end/panels/common/commentThreadWidget.css +25 -1
  165. package/front_end/panels/common/common-meta.ts +10 -0
  166. package/front_end/panels/console/ConsolePinPane.ts +13 -15
  167. package/front_end/panels/console/ConsolePrompt.ts +173 -95
  168. package/front_end/panels/console/ConsoleSidebar.ts +2 -2
  169. package/front_end/panels/console/ConsoleView.ts +75 -79
  170. package/front_end/panels/console/ConsoleViewMessage.ts +52 -4
  171. package/front_end/panels/console/SymbolizedErrorWidget.ts +8 -4
  172. package/front_end/panels/console/consolePrompt.css +1 -1
  173. package/front_end/panels/console/consoleView.css +1 -1
  174. package/front_end/panels/console_counters/WarningErrorCounter.ts +3 -4
  175. package/front_end/panels/coverage/CoverageListView.ts +2 -2
  176. package/front_end/panels/coverage/CoverageView.ts +20 -5
  177. package/front_end/panels/css_overview/CSSOverviewCompletedView.ts +4 -3
  178. package/front_end/panels/css_overview/CSSOverviewPanel.ts +2 -2
  179. package/front_end/panels/css_overview/CSSOverviewProcessingView.ts +2 -2
  180. package/front_end/panels/css_overview/CSSOverviewSidebarPanel.ts +2 -2
  181. package/front_end/panels/css_overview/CSSOverviewStartView.ts +2 -2
  182. package/front_end/panels/css_overview/CSSOverviewUnusedDeclarations.ts +8 -8
  183. package/front_end/panels/developer_resources/DeveloperResourcesListView.ts +2 -3
  184. package/front_end/panels/developer_resources/DeveloperResourcesView.ts +4 -5
  185. package/front_end/panels/elements/AccessibilityTreeUtils.ts +6 -7
  186. package/front_end/panels/elements/CSSValueTraceView.ts +3 -3
  187. package/front_end/panels/elements/ClassesPaneWidget.ts +1 -2
  188. package/front_end/panels/elements/ComputedStyleWidget.ts +15 -14
  189. package/front_end/panels/elements/DOMTreeElementWidget.ts +5 -4
  190. package/front_end/panels/elements/DOMTreeWidget.ts +2 -1
  191. package/front_end/panels/elements/ElementStatePaneWidget.ts +2 -2
  192. package/front_end/panels/elements/ElementsPanel.ts +1 -0
  193. package/front_end/panels/elements/EventListenersWidget.ts +2 -2
  194. package/front_end/panels/elements/LayoutPane.ts +2 -2
  195. package/front_end/panels/elements/PlatformFontsWidget.ts +3 -3
  196. package/front_end/panels/elements/PropertiesWidget.ts +9 -10
  197. package/front_end/panels/elements/PropertyRenderer.ts +72 -11
  198. package/front_end/panels/elements/StandaloneStylesContainer.ts +5 -10
  199. package/front_end/panels/elements/StyleEditorWidget.ts +30 -16
  200. package/front_end/panels/elements/StylePropertiesSection.ts +93 -44
  201. package/front_end/panels/elements/StylePropertyTreeElement.ts +230 -302
  202. package/front_end/panels/elements/StylesContainer.ts +2 -3
  203. package/front_end/panels/elements/StylesSidebarPane.ts +4 -13
  204. package/front_end/panels/elements/components/AccessibilityTreeNode.ts +66 -37
  205. package/front_end/panels/elements/components/CSSHintDetailsView.ts +51 -41
  206. package/front_end/panels/elements/components/CSSPropertyDocsView.ts +75 -65
  207. package/front_end/panels/elements/components/CSSQuery.ts +112 -74
  208. package/front_end/panels/elements/components/CSSVariableValueView.ts +109 -68
  209. package/front_end/panels/elements/components/ComputedStyleProperty.ts +64 -45
  210. package/front_end/panels/elements/components/ElementsTreeExpandButton.ts +35 -28
  211. package/front_end/panels/elements/components/QueryContainer.ts +104 -74
  212. package/front_end/panels/elements/components/accessibilityTreeNode.css +22 -20
  213. package/front_end/panels/elements/components/computedStyleProperty.css +2 -0
  214. package/front_end/panels/elements/components/cssHintDetailsView.css +23 -21
  215. package/front_end/panels/elements/components/cssPropertyDocsView.css +38 -36
  216. package/front_end/panels/elements/components/cssVariableValueView.css +42 -40
  217. package/front_end/panels/elements/components/elementsTreeExpandButton.css +5 -2
  218. package/front_end/panels/elements/components/queryContainer.css +23 -21
  219. package/front_end/panels/elements/stylesSidebarPane.css +3 -3
  220. package/front_end/panels/emulation/DeviceModeToolbar.ts +2 -2
  221. package/front_end/panels/emulation/InspectedPagePlaceholder.ts +2 -2
  222. package/front_end/panels/emulation/MediaQueryInspector.ts +9 -10
  223. package/front_end/panels/emulation/mediaQueryInspector.css +1 -1
  224. package/front_end/panels/event_listeners/EventListenersView.ts +2 -2
  225. package/front_end/panels/issues/AffectedCookiesView.ts +144 -101
  226. package/front_end/panels/issues/AffectedDescendantsWithinSelectElementView.ts +83 -31
  227. package/front_end/panels/issues/AffectedDirectivesView.ts +218 -135
  228. package/front_end/panels/issues/AffectedDocumentsInQuirksModeView.ts +84 -34
  229. package/front_end/panels/issues/AffectedElementsView.ts +86 -23
  230. package/front_end/panels/issues/AffectedLazyLoadImagesView.ts +2 -2
  231. package/front_end/panels/issues/AffectedMetadataAllowedSitesView.ts +2 -2
  232. package/front_end/panels/issues/AffectedPartitioningBlobURLView.ts +36 -11
  233. package/front_end/panels/issues/AffectedSharedArrayBufferIssueDetailsView.ts +135 -58
  234. package/front_end/panels/issues/AffectedSourcesView.ts +49 -28
  235. package/front_end/panels/issues/AffectedTrackingSitesView.ts +3 -4
  236. package/front_end/panels/issues/CorsIssueDetailsView.ts +490 -269
  237. package/front_end/panels/issues/GenericIssueDetailsView.ts +2 -2
  238. package/front_end/panels/issues/IssueKindView.ts +63 -48
  239. package/front_end/panels/issues/IssueView.ts +14 -18
  240. package/front_end/panels/issues/components/ElementsPanelLink.ts +70 -34
  241. package/front_end/panels/issues/components/HideIssuesMenu.ts +56 -32
  242. package/front_end/panels/issues/components/elementsPanelLink.css +10 -6
  243. package/front_end/panels/issues/components/hideIssuesMenu.css +16 -14
  244. package/front_end/panels/issues/issues.ts +2 -0
  245. package/front_end/panels/issues/issuesTree.css +4 -4
  246. package/front_end/panels/lighthouse/LighthouseController.ts +6 -6
  247. package/front_end/panels/lighthouse/LighthouseStatusView.ts +12 -13
  248. package/front_end/panels/lighthouse/lighthouseStartView.css +1 -1
  249. package/front_end/panels/linear_memory_inspector/LinearMemoryInspectorPane.ts +159 -161
  250. package/front_end/panels/linear_memory_inspector/LinearMemoryInspectorView.ts +228 -0
  251. package/front_end/panels/linear_memory_inspector/components/LinearMemoryInspector.ts +32 -41
  252. package/front_end/panels/linear_memory_inspector/components/linearMemoryHighlightChipList.css +2 -2
  253. package/front_end/panels/linear_memory_inspector/linear_memory_inspector.ts +2 -0
  254. package/front_end/panels/media/EventDisplayTable.ts +2 -2
  255. package/front_end/panels/media/MainView.ts +132 -66
  256. package/front_end/panels/media/PlayerDetailView.ts +32 -14
  257. package/front_end/panels/media/PlayerListView.ts +83 -23
  258. package/front_end/panels/media/PlayerPropertiesView.ts +2 -2
  259. package/front_end/panels/media/TickingFlameChart.ts +153 -63
  260. package/front_end/panels/mobile_throttling/NetworkThrottlingSelector.ts +2 -2
  261. package/front_end/panels/mobile_throttling/ThrottlingSettingsTab.ts +615 -464
  262. package/front_end/panels/mobile_throttling/throttlingSettingsTab.css +43 -0
  263. package/front_end/panels/network/EventSourceMessagesView.ts +3 -3
  264. package/front_end/panels/network/NetworkConfigView.ts +6 -2
  265. package/front_end/panels/network/NetworkDataGridNode.ts +2 -1
  266. package/front_end/panels/network/NetworkItemView.ts +27 -26
  267. package/front_end/panels/network/NetworkManageCustomHeadersView.ts +236 -97
  268. package/front_end/panels/network/NetworkOverview.ts +8 -10
  269. package/front_end/panels/network/RequestConditionsDrawer.ts +8 -4
  270. package/front_end/panels/network/RequestDeviceBoundSessionsView.ts +2 -4
  271. package/front_end/panels/network/RequestHTMLView.ts +26 -7
  272. package/front_end/panels/network/RequestHeadersView.ts +2 -2
  273. package/front_end/panels/network/RequestInitiatorView.ts +21 -22
  274. package/front_end/panels/network/RequestPayloadView.ts +2 -16
  275. package/front_end/panels/network/RequestPreviewView.ts +5 -5
  276. package/front_end/panels/network/RequestTimingView.ts +6 -6
  277. package/front_end/panels/network/ResourceDirectSocketChunkView.ts +5 -6
  278. package/front_end/panels/network/ResourceWebSocketFrameView.ts +4 -3
  279. package/front_end/panels/network/ShowMoreDetailsWidget.ts +11 -12
  280. package/front_end/panels/network/SignedExchangeInfoView.ts +2 -2
  281. package/front_end/panels/network/networkLogView.css +2 -2
  282. package/front_end/panels/network/networkManageCustomHeadersView.css +27 -6
  283. package/front_end/panels/network/requestConditionsDrawer.css +1 -1
  284. package/front_end/panels/network/requestInitiatorView.css +5 -3
  285. package/front_end/panels/performance_monitor/PerformanceMonitor.ts +2 -2
  286. package/front_end/panels/profiler/HeapDetachedElementsView.ts +1 -2
  287. package/front_end/panels/profiler/HeapTimelineOverview.ts +77 -15
  288. package/front_end/panels/profiler/IsolateSelector.ts +258 -187
  289. package/front_end/panels/profiler/ProfileLauncherView.ts +7 -29
  290. package/front_end/panels/profiler/profileLauncherView.css +6 -1
  291. package/front_end/panels/protocol_monitor/JSONEditor.ts +4 -5
  292. package/front_end/panels/recorder/ControlButton.ts +1 -1
  293. package/front_end/panels/recorder/RecordingListView.ts +2 -4
  294. package/front_end/panels/recorder/RecordingView.ts +1 -2
  295. package/front_end/panels/recorder/SelectorPicker.ts +2 -4
  296. package/front_end/panels/recorder/StepView.ts +24 -10
  297. package/front_end/panels/recorder/TimelineSection.ts +1 -1
  298. package/front_end/panels/recorder/recordingView.css +1 -1
  299. package/front_end/panels/screencast/ScreencastApp.ts +1 -1
  300. package/front_end/panels/search/SearchResultsPane.ts +11 -12
  301. package/front_end/panels/search/SearchView.ts +8 -10
  302. package/front_end/panels/security/SecurityPanel.ts +1 -8
  303. package/front_end/panels/security/SecurityPanelSidebar.ts +2 -2
  304. package/front_end/panels/security/mainView.css +1 -1
  305. package/front_end/panels/sensors/LocationsSettingsTab.ts +1 -2
  306. package/front_end/panels/settings/AISettingsTab.ts +1 -1
  307. package/front_end/panels/settings/BackendLinkingSettingsTab.ts +34 -20
  308. package/front_end/panels/settings/EditFileSystemView.ts +2 -2
  309. package/front_end/panels/settings/FrameworkIgnoreListSettingsTab.ts +375 -197
  310. package/front_end/panels/settings/KeybindsSettingsTab.ts +570 -414
  311. package/front_end/panels/settings/SettingsScreen.ts +312 -114
  312. package/front_end/panels/settings/WorkspaceSettingsTab.ts +2 -2
  313. package/front_end/panels/settings/aiSettingsTab.css +1 -4
  314. package/front_end/panels/settings/emulation/DevicesSettingsTab.ts +924 -578
  315. package/front_end/panels/settings/emulation/components/UserAgentClientHintsForm.ts +9 -2
  316. package/front_end/panels/settings/emulation/devicesSettingsTab.css +39 -0
  317. package/front_end/panels/settings/frameworkIgnoreListSettingsTab.css +37 -8
  318. package/front_end/panels/settings/settingsScreen.css +0 -24
  319. package/front_end/panels/sources/BreakpointEditDialog.ts +9 -6
  320. package/front_end/panels/sources/BreakpointsView.ts +25 -4
  321. package/front_end/panels/sources/CallStackSidebarPane.ts +7 -1
  322. package/front_end/panels/sources/DebuggerPlugin.ts +1 -0
  323. package/front_end/panels/sources/GoToLineQuickOpen.ts +8 -8
  324. package/front_end/panels/sources/NavigatorView.ts +521 -439
  325. package/front_end/panels/sources/PersistenceActions.ts +11 -12
  326. package/front_end/panels/sources/ProfilePlugin.ts +28 -17
  327. package/front_end/panels/sources/ScopeChainSidebarPane.ts +3 -4
  328. package/front_end/panels/sources/SourcesNavigator.ts +9 -9
  329. package/front_end/panels/sources/SourcesPanel.ts +2 -2
  330. package/front_end/panels/sources/SourcesView.ts +3 -3
  331. package/front_end/panels/sources/ThreadsSidebarPane.ts +2 -2
  332. package/front_end/panels/sources/WatchExpressionsSidebarPane.ts +2 -2
  333. package/front_end/panels/sources/components/HeadersView.ts +1 -2
  334. package/front_end/panels/timeline/CompatibilityTracksAppender.ts +5 -6
  335. package/front_end/panels/timeline/EventsTimelineTreeView.ts +73 -34
  336. package/front_end/panels/timeline/IsolateSelector.ts +25 -37
  337. package/front_end/panels/timeline/StatusDialog.ts +5 -7
  338. package/front_end/panels/timeline/ThirdPartyTreeView.ts +10 -13
  339. package/front_end/panels/timeline/TimelineDetailsView.ts +40 -21
  340. package/front_end/panels/timeline/TimelineEventOverview.ts +130 -34
  341. package/front_end/panels/timeline/TimelineFlameChartNetworkDataProvider.ts +1 -1
  342. package/front_end/panels/timeline/TimelineMiniMap.ts +255 -103
  343. package/front_end/panels/timeline/TimelinePaintProfilerView.ts +19 -11
  344. package/front_end/panels/timeline/TimelinePanel.ts +1 -0
  345. package/front_end/panels/timeline/TimelineSelectorStatsView.ts +11 -12
  346. package/front_end/panels/timeline/TimelineTreeView.ts +240 -122
  347. package/front_end/panels/timeline/TimelineUIUtils.ts +12 -0
  348. package/front_end/panels/timeline/components/BreadcrumbsUI.ts +5 -4
  349. package/front_end/panels/timeline/components/DetailsView.ts +97 -65
  350. package/front_end/panels/timeline/components/LayoutShiftDetails.ts +2 -2
  351. package/front_end/panels/timeline/components/MetricCard.ts +2 -2
  352. package/front_end/panels/timeline/components/NetworkRequestDetails.ts +11 -12
  353. package/front_end/panels/timeline/components/NetworkTrackWidget.ts +57 -50
  354. package/front_end/panels/timeline/components/RelatedInsightChips.ts +2 -2
  355. package/front_end/panels/timeline/components/Sidebar.ts +161 -109
  356. package/front_end/panels/timeline/components/SidebarAnnotationsTab.ts +33 -12
  357. package/front_end/panels/timeline/components/SidebarInsightsTab.ts +3 -0
  358. package/front_end/panels/timeline/components/insights/LCPDiscovery.ts +11 -11
  359. package/front_end/panels/timeline/components/insights/SlowCSSSelector.ts +6 -7
  360. package/front_end/panels/timeline/components/networkTrackWidget.css +24 -22
  361. package/front_end/panels/timeline/components/sidebarInsightsTab.css +1 -1
  362. package/front_end/panels/timeline/overlays/components/TimespanBreakdownOverlay.ts +15 -10
  363. package/front_end/panels/timeline/overlays/components/entryLabelOverlay.css +1 -1
  364. package/front_end/panels/timeline/timelinePanel.css +5 -0
  365. package/front_end/panels/timeline/timelineStatusDialog.css +1 -1
  366. package/front_end/panels/web_audio/WebAudioView.ts +2 -2
  367. package/front_end/third_party/chromium/README.chromium +1 -1
  368. package/front_end/third_party/legacy-javascript/README.chromium +2 -2
  369. package/front_end/third_party/legacy-javascript/lib/legacy-javascript.js +2 -2
  370. package/front_end/third_party/legacy-javascript/package.json +1 -1
  371. package/front_end/third_party/lighthouse/README.chromium +2 -2
  372. package/front_end/third_party/lighthouse/lighthouse-dt-bundle.js +1983 -2022
  373. package/front_end/third_party/lighthouse/locales/ar-XB.json +157 -142
  374. package/front_end/third_party/lighthouse/locales/ar.json +157 -142
  375. package/front_end/third_party/lighthouse/locales/bg.json +154 -139
  376. package/front_end/third_party/lighthouse/locales/ca.json +157 -142
  377. package/front_end/third_party/lighthouse/locales/cs.json +148 -133
  378. package/front_end/third_party/lighthouse/locales/da.json +153 -138
  379. package/front_end/third_party/lighthouse/locales/de.json +152 -137
  380. package/front_end/third_party/lighthouse/locales/el.json +153 -138
  381. package/front_end/third_party/lighthouse/locales/en-GB.json +160 -145
  382. package/front_end/third_party/lighthouse/locales/en-US.json +239 -218
  383. package/front_end/third_party/lighthouse/locales/en-XL.json +239 -218
  384. package/front_end/third_party/lighthouse/locales/es-419.json +150 -135
  385. package/front_end/third_party/lighthouse/locales/es.json +149 -134
  386. package/front_end/third_party/lighthouse/locales/fi.json +151 -136
  387. package/front_end/third_party/lighthouse/locales/fil.json +154 -139
  388. package/front_end/third_party/lighthouse/locales/fr.json +150 -135
  389. package/front_end/third_party/lighthouse/locales/he.json +160 -145
  390. package/front_end/third_party/lighthouse/locales/hi.json +156 -141
  391. package/front_end/third_party/lighthouse/locales/hr.json +154 -139
  392. package/front_end/third_party/lighthouse/locales/hu.json +111 -96
  393. package/front_end/third_party/lighthouse/locales/id.json +153 -138
  394. package/front_end/third_party/lighthouse/locales/it.json +153 -138
  395. package/front_end/third_party/lighthouse/locales/ja.json +150 -135
  396. package/front_end/third_party/lighthouse/locales/ko.json +42 -27
  397. package/front_end/third_party/lighthouse/locales/lt.json +152 -137
  398. package/front_end/third_party/lighthouse/locales/lv.json +93 -78
  399. package/front_end/third_party/lighthouse/locales/nl.json +149 -134
  400. package/front_end/third_party/lighthouse/locales/no.json +152 -137
  401. package/front_end/third_party/lighthouse/locales/pl.json +153 -138
  402. package/front_end/third_party/lighthouse/locales/pt-PT.json +152 -137
  403. package/front_end/third_party/lighthouse/locales/pt.json +157 -142
  404. package/front_end/third_party/lighthouse/locales/ro.json +149 -134
  405. package/front_end/third_party/lighthouse/locales/ru.json +76 -61
  406. package/front_end/third_party/lighthouse/locales/sk.json +153 -138
  407. package/front_end/third_party/lighthouse/locales/sl.json +149 -134
  408. package/front_end/third_party/lighthouse/locales/sr-Latn.json +151 -136
  409. package/front_end/third_party/lighthouse/locales/sr.json +151 -136
  410. package/front_end/third_party/lighthouse/locales/sv.json +152 -137
  411. package/front_end/third_party/lighthouse/locales/ta.json +156 -141
  412. package/front_end/third_party/lighthouse/locales/te.json +157 -142
  413. package/front_end/third_party/lighthouse/locales/th.json +111 -96
  414. package/front_end/third_party/lighthouse/locales/tr.json +153 -138
  415. package/front_end/third_party/lighthouse/locales/uk.json +149 -134
  416. package/front_end/third_party/lighthouse/locales/vi.json +162 -147
  417. package/front_end/third_party/lighthouse/locales/zh-HK.json +150 -135
  418. package/front_end/third_party/lighthouse/locales/zh-TW.json +154 -139
  419. package/front_end/third_party/lighthouse/locales/zh.json +152 -137
  420. package/front_end/third_party/lighthouse/report/bundle.d.ts +9 -8
  421. package/front_end/third_party/lighthouse/report/bundle.js +10 -10
  422. package/front_end/third_party/lighthouse/report-assets/report-generator.mjs +2 -7
  423. package/front_end/tsconfig.compatibility.json +1 -0
  424. package/front_end/tsconfig.json +3 -2
  425. package/front_end/ui/components/dialogs/TypeToAllowDialog.ts +0 -2
  426. package/front_end/ui/components/dialogs/typeToAllowDialog.css +0 -4
  427. package/front_end/ui/components/icon_button/fileSourceIcon.css +1 -1
  428. package/front_end/ui/components/input/textInput.css +1 -1
  429. package/front_end/ui/components/lists/List.ts +26 -14
  430. package/front_end/ui/components/menus/menus.ts +0 -2
  431. package/front_end/ui/components/suggestion_input/SuggestionInput.ts +351 -138
  432. package/front_end/ui/components/survey_link/surveyLink.css +3 -3
  433. package/front_end/ui/components/switch/switch.css +6 -6
  434. package/front_end/ui/components/text_editor/AiCodeCompletionTeaser.ts +2 -3
  435. package/front_end/ui/components/text_editor/TextEditor.ts +1 -1
  436. package/front_end/ui/components/tooltips/Tooltip.ts +53 -4
  437. package/front_end/ui/components/tree_outline/treeOutline.css +7 -7
  438. package/front_end/ui/helpers/OpenInNewTab.ts +8 -3
  439. package/front_end/ui/legacy/EmptyWidget.ts +4 -4
  440. package/front_end/ui/legacy/ForwardedInputEventHandler.ts +2 -2
  441. package/front_end/ui/legacy/GlassPane.ts +1 -1
  442. package/front_end/ui/legacy/KeyboardShortcut.ts +7 -7
  443. package/front_end/ui/legacy/RemoteDebuggingTerminatedScreen.ts +2 -2
  444. package/front_end/ui/legacy/TabbedPane.ts +198 -66
  445. package/front_end/ui/legacy/TargetCrashedScreen.ts +2 -2
  446. package/front_end/ui/legacy/UIUtils.ts +71 -68
  447. package/front_end/ui/legacy/View.ts +7 -4
  448. package/front_end/ui/legacy/ViewManager.ts +49 -37
  449. package/front_end/ui/legacy/Widget.ts +32 -12
  450. package/front_end/ui/legacy/components/cookie_table/CookiesTable.ts +2 -3
  451. package/front_end/ui/legacy/components/inline_editor/AnimationTimingUI.ts +8 -8
  452. package/front_end/ui/legacy/components/inline_editor/BezierUI.ts +8 -9
  453. package/front_end/ui/legacy/components/inline_editor/LinkSwatch.ts +2 -2
  454. package/front_end/ui/legacy/components/inline_editor/cssAngleEditor.css +1 -1
  455. package/front_end/ui/legacy/components/inline_editor/cssAngleSwatch.css +1 -1
  456. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +45 -11
  457. package/front_end/ui/legacy/components/object_ui/RemoteObjectPreviewFormatter.ts +10 -12
  458. package/front_end/ui/legacy/components/perf_ui/ChartViewport.ts +102 -29
  459. package/front_end/ui/legacy/components/perf_ui/FlameChart.ts +148 -122
  460. package/front_end/ui/legacy/components/perf_ui/TimelineOverviewPane.ts +20 -14
  461. package/front_end/ui/legacy/components/quick_open/filteredListWidget.css +1 -1
  462. package/front_end/ui/legacy/components/source_frame/FontView.ts +29 -5
  463. package/front_end/ui/legacy/components/source_frame/ImageView.ts +79 -12
  464. package/front_end/ui/legacy/components/source_frame/JSONView.ts +20 -2
  465. package/front_end/ui/legacy/components/source_frame/PreviewFactory.ts +2 -2
  466. package/front_end/ui/legacy/components/source_frame/StreamingContentHexView.ts +6 -10
  467. package/front_end/ui/legacy/components/source_frame/XMLView.ts +11 -11
  468. package/front_end/ui/legacy/components/source_frame/fontView.css +7 -0
  469. package/front_end/ui/legacy/components/source_frame/imageView.css +7 -0
  470. package/front_end/ui/legacy/components/utils/JSPresentationUtils.ts +14 -3
  471. package/front_end/ui/legacy/components/utils/Linkifier.ts +126 -2
  472. package/front_end/ui/legacy/emptyWidget.css +2 -1
  473. package/front_end/ui/legacy/inspectorCommon.css +3 -3
  474. package/front_end/ui/legacy/smallBubble.css +1 -1
  475. package/front_end/ui/legacy/tabbedPane.css +6 -0
  476. package/front_end/ui/lit/Directives.ts +35 -18
  477. package/front_end/ui/lit/lit.ts +0 -2
  478. package/front_end/ui/lit/render.ts +0 -7
  479. package/front_end/ui/visual_logging/KnownContextValues.ts +5 -0
  480. package/package.json +1 -1
  481. package/vpython.toml +8 -0
  482. package/vpython.toml.uv.lock +3 -0
  483. package/.agents/skills/review-models-core/SKILL.md +0 -73
  484. package/.agents/skills/review-tests/SKILL.md +0 -67
  485. package/.agents/skills/review-ui-widgets/SKILL.md +0 -115
  486. package/front_end/generated/ARIAProperties.ts +0 -2686
  487. package/front_end/ui/components/menus/README.md +0 -119
  488. package/front_end/ui/components/menus/SelectMenu.ts +0 -473
  489. package/front_end/ui/components/menus/selectMenu.css +0 -54
  490. package/front_end/ui/components/menus/selectMenuButton.css +0 -108
@@ -1,16 +1,18 @@
1
1
  // Copyright 2017 The Chromium Authors
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
- /* eslint-disable @devtools/no-imperative-dom-api */
5
4
 
5
+ import '../../ui/components/lists/lists.js';
6
6
  import '../../ui/kit/kit.js';
7
7
 
8
8
  import * as Common from '../../core/common/common.js';
9
9
  import * as i18n from '../../core/i18n/i18n.js';
10
+ import * as Platform from '../../core/platform/platform.js';
10
11
  import * as SDK from '../../core/sdk/sdk.js';
11
12
  import * as Buttons from '../../ui/components/buttons/buttons.js';
12
- import {type Card, createIcon} from '../../ui/kit/kit.js';
13
+ import type * as Lists from '../../ui/components/lists/lists.js';
13
14
  import * as UI from '../../ui/legacy/legacy.js';
15
+ import {Directives, html, type LitTemplate, nothing, render} from '../../ui/lit/lit.js';
14
16
  import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
15
17
  import * as PanelsCommon from '../common/common.js';
16
18
 
@@ -18,6 +20,8 @@ import {CalibrationController} from './CalibrationController.js';
18
20
  import {ThrottlingPresets} from './ThrottlingPresets.js';
19
21
  import throttlingSettingsTabStyles from './throttlingSettingsTab.css.js';
20
22
 
23
+ const {widget} = UI.Widget;
24
+
21
25
  const UIStrings = {
22
26
  /**
23
27
  * @description Title for default network throttling profiles card.
@@ -151,6 +155,14 @@ const UIStrings = {
151
155
  * @description Button text to allow the user to cancel the CPU calibration process.
152
156
  */
153
157
  cancel: 'Cancel',
158
+ /**
159
+ * @description Button text to save changes when editing a custom profile in the throttling settings tab.
160
+ */
161
+ save: 'Save',
162
+ /**
163
+ * @description Button text to add a new custom profile in the throttling settings tab.
164
+ */
165
+ add: 'Add',
154
166
  /**
155
167
  * @description Text to use to indicate that a CPU calibration has not been run yet.
156
168
  */
@@ -220,125 +232,146 @@ function createComputePressurePromise(): Promise<{state: string}> {
220
232
  });
221
233
  }
222
234
 
223
- export class CPUThrottlingCard {
224
- element: Card;
235
+ export interface CPUThrottlingCardViewInput {
236
+ state: 'cta'|'prompting'|'calibrating';
237
+ hasCalibrated: boolean;
238
+ lowResultText: string;
239
+ lowNotCalibrated: boolean;
240
+ midResultText: string;
241
+ midNotCalibrated: boolean;
242
+ warnings: string[];
243
+ progressWorked: number;
244
+ onCalibrateClick: () => void;
245
+ onCancelClick: () => void;
246
+ }
225
247
 
226
- private readonly setting: Common.Settings.Setting<PanelsCommon.CPUThrottlingOption.CalibratedCPUThrottling>;
248
+ export type CPUThrottlingCardView = (input: CPUThrottlingCardViewInput, output: undefined, target: HTMLElement) => void;
249
+
250
+ export const CPU_THROTTLING_CARD_DEFAULT_VIEW: CPUThrottlingCardView = (input, _output, target) => {
251
+ const renderTextWithIcon = (text: string, icon: string): LitTemplate => html`
252
+ <div class="text-with-icon">
253
+ <devtools-icon name=${icon}></devtools-icon>
254
+ ${text}
255
+ </div>
256
+ `;
257
+
258
+ const showCalibrateButton = input.state === 'cta' || input.state === 'prompting';
259
+ const calibrateButtonText = input.state === 'prompting' ?
260
+ i18nString(UIStrings.continue) :
261
+ (input.hasCalibrated ? i18nString(UIStrings.recalibrate) : i18nString(UIStrings.calibrate));
262
+ const showCancelButton = input.state === 'prompting' || input.state === 'calibrating';
263
+ const showTextContainer = (input.state === 'cta' && !input.hasCalibrated) || input.state === 'prompting';
264
+ const showProgress = input.state === 'calibrating';
265
+
266
+ // clang-format off
267
+ render(
268
+ html`
269
+ <devtools-card heading=${i18nString(UIStrings.cpuThrottlingPresets)}>
270
+ <span>${i18nString(UIStrings.cpuCalibrationDescription)}</span>
271
+ <div class="cpu-preset-section">
272
+ ${i18nString(UIStrings.calibratedLowTierMobile)}
273
+ <div class=${Directives.classMap({
274
+ 'cpu-preset-result': true,
275
+ 'not-calibrated': input.lowNotCalibrated,
276
+ })}>
277
+ ${input.lowResultText}
278
+ </div>
279
+ </div>
280
+ <div class="cpu-preset-section">
281
+ ${i18nString(UIStrings.calibratedMidTierMobile)}
282
+ <div class=${Directives.classMap({
283
+ 'cpu-preset-result': true,
284
+ 'not-calibrated': input.midNotCalibrated,
285
+ })}>
286
+ ${input.midResultText}
287
+ </div>
288
+ </div>
289
+ <div class="cpu-preset-section cpu-preset-calibrate">
290
+ <div class="button-container">
291
+ <devtools-button
292
+ class="calibrate-button"
293
+ style=${showCalibrateButton ? '' : 'display: none'}
294
+ .variant=${Buttons.Button.Variant.PRIMARY}
295
+ .jslogContext=${'throttling.calibrate'}
296
+ @click=${input.onCalibrateClick}>
297
+ ${calibrateButtonText}
298
+ </devtools-button>
299
+ <devtools-button
300
+ class="cancel-button"
301
+ style=${showCancelButton ? '' : 'display: none'}
302
+ .variant=${Buttons.Button.Variant.OUTLINED}
303
+ .jslogContext=${'throttling.calibrate-cancel'}
304
+ @click=${input.onCancelClick}>
305
+ ${i18nString(UIStrings.cancel)}
306
+ </devtools-button>
307
+ </div>
308
+ <div
309
+ class="text-container"
310
+ style=${showTextContainer ? '' : 'display: none'}>
311
+ ${input.state === 'cta' && !input.hasCalibrated
312
+ ? renderTextWithIcon(i18nString(UIStrings.calibrationCTA), 'info')
313
+ : nothing}
314
+ ${input.state === 'prompting' ? html`
315
+ ${input.warnings.map(warning => renderTextWithIcon(warning, 'warning'))}
316
+ ${renderTextWithIcon(i18nString(UIStrings.calibrationConfirmationPrompt), 'info')}
317
+ ` : nothing}
318
+ </div>
319
+ <devtools-progress
320
+ no-stop-button
321
+ style=${showProgress ? '' : 'display: none'}
322
+ .worked=${input.progressWorked}
323
+ .totalWork=${1}>
324
+ </devtools-progress>
325
+ </div>
326
+ </devtools-card>
327
+ `,
328
+ target);
329
+ // clang-format on
330
+ };
331
+
332
+ export class CPUThrottlingCard extends UI.Widget.Widget {
333
+ #setting?: Common.Settings.Setting<PanelsCommon.CPUThrottlingOption.CalibratedCPUThrottling>;
227
334
  private computePressurePromise?: ReturnType<typeof createComputePressurePromise>;
228
335
  private controller?: CalibrationController;
229
-
230
- // UI stuff.
231
- private lowTierMobileDeviceEl: HTMLElement;
232
- private midTierMobileDeviceEl: HTMLElement;
233
- private calibrateEl: HTMLElement;
234
- private textEl: HTMLElement;
235
- private calibrateButton: Buttons.Button.Button;
236
- private cancelButton: Buttons.Button.Button;
237
- private progress: UI.ProgressIndicator.ProgressIndicator;
238
336
  private state: 'cta'|'prompting'|'calibrating' = 'cta';
239
337
  private warnings: string[] = [];
338
+ readonly #view: CPUThrottlingCardView;
339
+ #progressWorked = 0;
240
340
 
241
- constructor(settings: Common.Settings.Settings) {
242
- this.setting = settings.createSetting<PanelsCommon.CPUThrottlingOption.CalibratedCPUThrottling>(
243
- 'calibrated-cpu-throttling', {}, Common.Settings.SettingStorageType.GLOBAL);
244
-
245
- this.element = document.createElement('devtools-card');
246
- this.element.heading = i18nString(UIStrings.cpuThrottlingPresets);
247
-
248
- const descriptionEl = this.element.createChild('span');
249
- descriptionEl.textContent = i18nString(UIStrings.cpuCalibrationDescription);
250
-
251
- this.lowTierMobileDeviceEl = this.element.createChild('div', 'cpu-preset-section');
252
- this.lowTierMobileDeviceEl.append(i18nString(UIStrings.calibratedLowTierMobile));
253
- this.lowTierMobileDeviceEl.createChild('div', 'cpu-preset-result');
254
-
255
- this.midTierMobileDeviceEl = this.element.createChild('div', 'cpu-preset-section');
256
- this.midTierMobileDeviceEl.append(i18nString(UIStrings.calibratedMidTierMobile));
257
- this.midTierMobileDeviceEl.createChild('div', 'cpu-preset-result');
258
-
259
- this.calibrateEl = this.element.createChild('div', 'cpu-preset-section cpu-preset-calibrate');
260
-
261
- const buttonContainerEl = this.calibrateEl.createChild('div', 'button-container');
262
-
263
- this.calibrateButton = new Buttons.Button.Button();
264
- this.calibrateButton.classList.add('calibrate-button');
265
- this.calibrateButton.data = {
266
- variant: Buttons.Button.Variant.PRIMARY,
267
- jslogContext: 'throttling.calibrate',
268
- };
269
- this.calibrateButton.addEventListener('click', () => this.calibrateButtonClicked());
270
- buttonContainerEl.append(this.calibrateButton);
271
-
272
- this.cancelButton = new Buttons.Button.Button();
273
- this.cancelButton.classList.add('cancel-button');
274
- this.cancelButton.data = {
275
- variant: Buttons.Button.Variant.OUTLINED,
276
- jslogContext: 'throttling.calibrate-cancel',
277
- };
278
- this.cancelButton.textContent = i18nString(UIStrings.cancel);
279
- this.cancelButton.addEventListener('click', () => this.cancelButtonClicked());
280
- buttonContainerEl.append(this.cancelButton);
281
-
282
- this.textEl = this.calibrateEl.createChild('div', 'text-container');
283
-
284
- this.progress = this.calibrateEl.createChild('devtools-progress');
285
- this.progress.setAttribute('no-stop-button', '');
286
-
287
- this.updateState();
341
+ constructor(element?: HTMLElement, view: CPUThrottlingCardView = CPU_THROTTLING_CARD_DEFAULT_VIEW) {
342
+ super(element);
343
+ this.#view = view;
344
+ this.performUpdate();
288
345
  }
289
346
 
290
- wasShown(): void {
347
+ override wasShown(): void {
348
+ super.wasShown();
291
349
  this.computePressurePromise = createComputePressurePromise();
292
350
  this.state = 'cta';
293
- this.updateState();
351
+ this.performUpdate();
294
352
  }
295
353
 
296
- willHide(): void {
354
+ override willHide(): void {
355
+ super.willHide();
297
356
  this.computePressurePromise = undefined;
298
357
  if (this.controller) {
299
358
  this.controller.abort();
300
359
  }
301
360
  }
302
361
 
303
- private updateState(): void {
362
+ override performUpdate(): void {
363
+ if (!this.#setting && Common.Settings.Settings.hasInstance()) {
364
+ this.#setting =
365
+ Common.Settings.Settings.instance().createSetting<PanelsCommon.CPUThrottlingOption.CalibratedCPUThrottling>(
366
+ 'calibrated-cpu-throttling', {}, Common.Settings.SettingStorageType.GLOBAL);
367
+ }
368
+
304
369
  if (this.state !== 'calibrating') {
305
370
  this.controller = undefined;
306
371
  }
307
372
 
308
- const result = this.setting.get();
309
- const hasCalibrated = result.low || result.mid;
310
-
311
- this.calibrateButton.style.display = 'none';
312
- this.textEl.style.display = 'none';
313
- this.cancelButton.style.display = 'none';
314
- this.progress.style.display = 'none';
315
-
316
- if (this.state === 'cta') {
317
- this.calibrateButton.style.display = '';
318
- this.calibrateButton.textContent =
319
- hasCalibrated ? i18nString(UIStrings.recalibrate) : i18nString(UIStrings.calibrate);
320
-
321
- if (!hasCalibrated) {
322
- this.textEl.style.display = '';
323
- this.textEl.textContent = '';
324
- this.textEl.append(this.createTextWithIcon(i18nString(UIStrings.calibrationCTA), 'info'));
325
- }
326
- } else if (this.state === 'prompting') {
327
- this.calibrateButton.style.display = '';
328
- this.calibrateButton.textContent = i18nString(UIStrings.continue);
329
-
330
- this.cancelButton.style.display = '';
331
-
332
- this.textEl.style.display = '';
333
- this.textEl.textContent = '';
334
- for (const warning of this.warnings) {
335
- this.textEl.append(this.createTextWithIcon(warning, 'warning'));
336
- }
337
- this.textEl.append(this.createTextWithIcon(i18nString(UIStrings.calibrationConfirmationPrompt), 'info'));
338
- } else if (this.state === 'calibrating') {
339
- this.cancelButton.style.display = '';
340
- this.progress.style.display = '';
341
- }
373
+ const result = this.#setting?.get() ?? {};
374
+ const hasCalibrated = Boolean(result.low || result.mid);
342
375
 
343
376
  const resultToString = (result: number|PanelsCommon.CPUThrottlingOption.CalibrationError|undefined): string => {
344
377
  if (result === undefined) {
@@ -358,26 +391,24 @@ export class CPUThrottlingCard {
358
391
  return i18nString(UIStrings.dSlowdown, {PH1: result.toFixed(1)});
359
392
  };
360
393
 
361
- const setPresetResult = (element: HTMLElement|null,
362
- result: number|PanelsCommon.CPUThrottlingOption.CalibrationError|undefined): void => {
363
- if (!element) {
364
- throw new Error('expected HTMLElement');
365
- }
366
-
367
- element.textContent = resultToString(result);
368
- element.classList.toggle('not-calibrated', result === undefined);
369
- };
370
-
371
- setPresetResult(this.lowTierMobileDeviceEl.querySelector('.cpu-preset-result'), result.low);
372
- setPresetResult(this.midTierMobileDeviceEl.querySelector('.cpu-preset-result'), result.mid);
373
- }
374
-
375
- private createTextWithIcon(text: string, icon: string): HTMLElement {
376
- const el = document.createElement('div');
377
- el.classList.add('text-with-icon');
378
- el.append(createIcon(icon));
379
- el.append(text);
380
- return el;
394
+ this.#view(
395
+ {
396
+ state: this.state,
397
+ hasCalibrated,
398
+ lowResultText: resultToString(result.low),
399
+ lowNotCalibrated: result.low === undefined,
400
+ midResultText: resultToString(result.mid),
401
+ midNotCalibrated: result.mid === undefined,
402
+ warnings: this.warnings,
403
+ progressWorked: this.#progressWorked,
404
+ onCalibrateClick: () => {
405
+ void this.calibrateButtonClicked();
406
+ },
407
+ onCancelClick: () => this.cancelButtonClicked(),
408
+ },
409
+ undefined,
410
+ this.element,
411
+ );
381
412
  }
382
413
 
383
414
  private async getCalibrationWarnings(): Promise<string[]> {
@@ -405,10 +436,10 @@ export class CPUThrottlingCard {
405
436
  if (this.state === 'cta') {
406
437
  this.warnings = await this.getCalibrationWarnings();
407
438
  this.state = 'prompting';
408
- this.updateState();
439
+ this.requestUpdate();
409
440
  } else if (this.state === 'prompting') {
410
441
  this.state = 'calibrating';
411
- this.updateState();
442
+ this.requestUpdate();
412
443
  void this.runCalibration();
413
444
  }
414
445
  }
@@ -418,13 +449,13 @@ export class CPUThrottlingCard {
418
449
  this.controller.abort();
419
450
  } else {
420
451
  this.state = 'cta';
421
- this.updateState();
452
+ this.requestUpdate();
422
453
  }
423
454
  }
424
455
 
425
456
  private async runCalibration(): Promise<void> {
426
- this.progress.worked = 0;
427
- this.progress.totalWork = 1;
457
+ this.#progressWorked = 0;
458
+ this.requestUpdate();
428
459
 
429
460
  this.controller = new CalibrationController();
430
461
 
@@ -435,7 +466,8 @@ export class CPUThrottlingCard {
435
466
  }
436
467
 
437
468
  for await (const result of this.controller.iterator()) {
438
- this.progress.worked = result.progress;
469
+ this.#progressWorked = result.progress;
470
+ this.requestUpdate();
439
471
  }
440
472
  } catch (e) {
441
473
  console.error(e);
@@ -444,15 +476,16 @@ export class CPUThrottlingCard {
444
476
  }
445
477
 
446
478
  const result = this.controller.result();
447
- if (result && (result.low || result.mid)) {
448
- this.setting.set(result);
479
+ if (result && (result.low || result.mid) && this.#setting) {
480
+ this.#setting.set(result);
449
481
  // Let the user bask in the glory of a 100% progress bar, for a bit.
450
- this.progress.worked = 1;
482
+ this.#progressWorked = 1;
483
+ this.requestUpdate();
451
484
  await new Promise(resolve => setTimeout(resolve, 200));
452
485
  }
453
486
 
454
487
  this.state = 'cta';
455
- this.updateState();
488
+ this.requestUpdate();
456
489
  }
457
490
  }
458
491
 
@@ -464,15 +497,312 @@ function extractCustomSettingIndex(key: SDK.NetworkManager.UserDefinedThrottling
464
497
  return 0;
465
498
  }
466
499
 
467
- export class ThrottlingSettingsTab extends UI.Widget.VBox implements
468
- UI.ListWidget.Delegate<SDK.NetworkManager.Conditions> {
469
- /** List of default network throttling presets (read-only in UI) */
470
- private readonly presetsList: UI.ListWidget.ListWidget<SDK.NetworkManager.Conditions>;
471
- /** List of custom user-defined network throttling profiles */
472
- private readonly customList: UI.ListWidget.ListWidget<SDK.NetworkManager.Conditions>;
500
+ function retrieveOptionsTitle(conditions: SDK.NetworkManager.Conditions): string {
501
+ // The title is usually an i18nLazyString except for custom values that are stored in the local storage in the form of a string.
502
+ return typeof conditions.title === 'function' ? conditions.title() : conditions.title;
503
+ }
504
+
505
+ export interface EditorValues {
506
+ title: string;
507
+ download: string;
508
+ upload: string;
509
+ latency: string;
510
+ packetLoss: string;
511
+ packetQueueLength: string;
512
+ packetReordering: boolean;
513
+ }
514
+
515
+ export type EditorFieldName = keyof EditorValues;
516
+
517
+ export interface ViewInput {
518
+ presets: SDK.NetworkManager.Conditions[];
519
+ customConditions: SDK.NetworkManager.Conditions[];
520
+ editingIndex: number|null;
521
+ editingValues: EditorValues;
522
+ validationErrors: Partial<Record<EditorFieldName, Common.UIString.LocalizedString>>;
523
+ showValidationErrors: boolean;
524
+ onAddCustomProfile: () => void;
525
+ onBeginEdit: (index: number) => void;
526
+ onRemoveCustomProfile: (index: number) => void;
527
+ onEditorInput: <K extends EditorFieldName>(field: K, value: EditorValues[K]) => void;
528
+ onCommitEdit: () => void;
529
+ onCancelEdit: () => void;
530
+ }
531
+
532
+ export type View = (input: ViewInput, output: undefined, target: HTMLElement) => void;
533
+
534
+ function renderHeaderRow(): LitTemplate {
535
+ const profileName = i18nString(UIStrings.profileName);
536
+ const columns = [
537
+ i18nString(UIStrings.download),
538
+ i18nString(UIStrings.upload),
539
+ i18nString(UIStrings.latency),
540
+ i18nString(UIStrings.packetLoss),
541
+ i18nString(UIStrings.packetQueueLength),
542
+ i18nString(UIStrings.packetReordering),
543
+ ];
544
+ // clang-format off
545
+ return html`
546
+ <div class="conditions-list-item conditions-list-header">
547
+ <div class="conditions-list-text conditions-list-title" title=${profileName}>
548
+ <div class="conditions-list-title-text">${profileName}</div>
549
+ </div>
550
+ ${columns.map(column => html`
551
+ <div class="conditions-list-separator"></div>
552
+ <div class="conditions-list-text" title=${column}>${column}</div>
553
+ `)}
554
+ </div>
555
+ `;
556
+ // clang-format on
557
+ }
558
+
559
+ function renderConditionsItem(conditions: SDK.NetworkManager.Conditions): LitTemplate {
560
+ const title = retrieveOptionsTitle(conditions);
561
+ const downloadText = throughputText(conditions.download);
562
+ const uploadText = throughputText(conditions.upload);
563
+ const latencyText = i18nString(UIStrings.dms, {PH1: conditions.latency});
564
+ const packetLossText = percentText(conditions.packetLoss ?? 0);
565
+ const packetQueueLengthText = String(conditions.packetQueueLength ?? 0);
566
+ const packetReorderingText = conditions.packetReordering ? i18nString(UIStrings.on) : i18nString(UIStrings.off);
567
+ // clang-format off
568
+ return html`
569
+ <div class="conditions-list-item">
570
+ <div class="conditions-list-text conditions-list-title" title=${title}>
571
+ <div class="conditions-list-title-text">${title}</div>
572
+ </div>
573
+ <div class="conditions-list-separator"></div>
574
+ <div class="conditions-list-text">${downloadText}</div>
575
+ <div class="conditions-list-separator"></div>
576
+ <div class="conditions-list-text">${uploadText}</div>
577
+ <div class="conditions-list-separator"></div>
578
+ <div class="conditions-list-text">${latencyText}</div>
579
+ <div class="conditions-list-separator"></div>
580
+ <div class="conditions-list-text">${packetLossText}</div>
581
+ <div class="conditions-list-separator"></div>
582
+ <div class="conditions-list-text">${packetQueueLengthText}</div>
583
+ <div class="conditions-list-separator"></div>
584
+ <div class="conditions-list-text">${packetReorderingText}</div>
585
+ </div>
586
+ `;
587
+ // clang-format on
588
+ }
589
+
590
+ interface TextFieldDefinition {
591
+ name: Exclude<EditorFieldName, 'packetReordering'>;
592
+ labelText: Common.UIString.LocalizedString;
593
+ placeholder: string;
594
+ isOptional: boolean;
595
+ }
596
+
597
+ function renderEditor(input: ViewInput): LitTemplate {
598
+ const isNew = input.editingIndex === input.customConditions.length;
599
+ const optionalStr = i18nString(UIStrings.optional);
600
+ const textFields: TextFieldDefinition[] = [
601
+ {
602
+ name: 'title',
603
+ labelText: i18nString(UIStrings.profileName),
604
+ placeholder: '',
605
+ isOptional: false,
606
+ },
607
+ {
608
+ name: 'download',
609
+ labelText: i18nString(UIStrings.download),
610
+ placeholder: i18n.i18n.lockedString('kbit/s'),
611
+ isOptional: true,
612
+ },
613
+ {
614
+ name: 'upload',
615
+ labelText: i18nString(UIStrings.upload),
616
+ placeholder: i18n.i18n.lockedString('kbit/s'),
617
+ isOptional: true,
618
+ },
619
+ {
620
+ name: 'latency',
621
+ labelText: i18nString(UIStrings.latency),
622
+ placeholder: i18n.i18n.lockedString('ms'),
623
+ isOptional: true,
624
+ },
625
+ {
626
+ name: 'packetLoss',
627
+ labelText: i18nString(UIStrings.packetLoss),
628
+ placeholder: i18n.i18n.lockedString('percent'),
629
+ isOptional: true,
630
+ },
631
+ {
632
+ name: 'packetQueueLength',
633
+ labelText: i18nString(UIStrings.packetQueueLength),
634
+ placeholder: i18nString(UIStrings.packet),
635
+ isOptional: true,
636
+ },
637
+ ];
638
+ const errorMessages = Object.values(input.validationErrors).filter(Boolean);
639
+ const hasErrors = errorMessages.length > 0;
640
+
641
+ // clang-format off
642
+ return html`
643
+ <div
644
+ class="editor-container"
645
+ jslog=${VisualLogging.pane('editor').track({resize: true})}
646
+ @keydown=${(e: KeyboardEvent) => {
647
+ if (Platform.KeyboardUtilities.isEscKey(e)) {
648
+ e.consume(true);
649
+ input.onCancelEdit();
650
+ }
651
+ }}>
652
+ <div
653
+ class="editor-content"
654
+ @keydown=${(e: KeyboardEvent) => {
655
+ if (e.key === 'Enter') {
656
+ e.consume(true);
657
+ input.onCommitEdit();
658
+ }
659
+ }}>
660
+ <div class="settings-container">
661
+ ${textFields.map((field, index) => {
662
+ const isInvalid = input.showValidationErrors && Boolean(input.validationErrors[field.name]);
663
+ return html`
664
+ <div class="setting">
665
+ <div>${field.labelText}</div>
666
+ <div>
667
+ <input
668
+ class=${Directives.classMap({
669
+ 'harmony-input': true,
670
+ input: true,
671
+ 'error-input': isInvalid,
672
+ })}
673
+ type="text"
674
+ ?autofocus=${index === 0}
675
+ placeholder=${field.placeholder}
676
+ aria-label=${field.labelText}
677
+ aria-description=${optionalStr}
678
+ aria-invalid=${isInvalid ? 'true' : 'false'}
679
+ .value=${Directives.live(input.editingValues[field.name])}
680
+ jslog=${VisualLogging.textField().track({change: true, keydown: 'Enter'}).context(field.name)}
681
+ @input=${(e: Event) => input.onEditorInput(field.name, (e.target as HTMLInputElement).value)}>
682
+ <div style=${field.isOptional ? '' : 'visibility: hidden'}>
683
+ ${optionalStr}
684
+ </div>
685
+ </div>
686
+ </div>
687
+ `;
688
+ })}
689
+ <div class="setting">
690
+ <div>${i18nString(UIStrings.packetReordering)}</div>
691
+ <div>
692
+ <devtools-checkbox
693
+ class="input"
694
+ aria-label=${i18nString(UIStrings.packetReordering)}
695
+ aria-description=${optionalStr}
696
+ .checked=${input.editingValues.packetReordering}
697
+ .jslogContext=${'packetReordering'}
698
+ @change=${(e: Event) => input.onEditorInput('packetReordering', (e.target as UI.UIUtils.CheckboxLabel).checked)}>
699
+ </devtools-checkbox>
700
+ <div style="visibility: hidden">
701
+ ${optionalStr}
702
+ </div>
703
+ </div>
704
+ </div>
705
+ </div>
706
+ </div>
707
+ <div class="editor-buttons">
708
+ <devtools-button
709
+ .variant=${Buttons.Button.Variant.OUTLINED}
710
+ .jslogContext=${'cancel'}
711
+ jslog=${VisualLogging.action('cancel').track({click: true})}
712
+ @click=${input.onCancelEdit}>
713
+ ${i18nString(UIStrings.cancel)}
714
+ </devtools-button>
715
+ <devtools-button
716
+ .variant=${Buttons.Button.Variant.PRIMARY}
717
+ .jslogContext=${'commit'}
718
+ .disabled=${hasErrors}
719
+ @click=${input.onCommitEdit}>
720
+ ${isNew ? i18nString(UIStrings.add) : i18nString(UIStrings.save)}
721
+ </devtools-button>
722
+ </div>
723
+ <div class="list-widget-input-validation-error" role="alert" aria-live="polite">
724
+ ${input.showValidationErrors && hasErrors
725
+ ? errorMessages.map((msg, i) => html`${i > 0 ? html`<br>` : nothing}${msg}`)
726
+ : nothing}
727
+ </div>
728
+ </div>
729
+ `;
730
+ // clang-format on
731
+ }
732
+
733
+ export const DEFAULT_VIEW: View = (input, _output, target) => {
734
+ const editingIndex = input.editingIndex;
735
+ const customBefore = editingIndex !== null ? input.customConditions.slice(0, editingIndex) : input.customConditions;
736
+ const customAfter = editingIndex !== null ? input.customConditions.slice(editingIndex + 1) : [];
737
+
738
+ // clang-format off
739
+ render(
740
+ html`
741
+ <div class="settings-card-container-wrapper">
742
+ <div class="settings-card-container throttling-conditions-settings">
743
+ ${widget(CPUThrottlingCard)}
744
+ <devtools-card heading=${i18nString(UIStrings.defaultProfiles)}>
745
+ <div>
746
+ ${renderHeaderRow()}
747
+ <devtools-list class="conditions-list">
748
+ ${input.presets.map(preset => renderConditionsItem(preset))}
749
+ </devtools-list>
750
+ </div>
751
+ </devtools-card>
752
+ <devtools-card heading=${i18nString(UIStrings.customProfiles)}>
753
+ <div>
754
+ ${renderHeaderRow()}
755
+ ${customBefore.length > 0 ? html`
756
+ <devtools-list
757
+ class="conditions-list"
758
+ editable
759
+ deletable
760
+ @edit=${(e: Lists.List.ItemEditEvent) => input.onBeginEdit(e.detail.index)}
761
+ @delete=${(e: Lists.List.ItemRemoveEvent) => input.onRemoveCustomProfile(e.detail.index)}>
762
+ ${customBefore.map(item => renderConditionsItem(item))}
763
+ </devtools-list>
764
+ ` : nothing}
765
+ ${editingIndex !== null ? renderEditor(input) : nothing}
766
+ ${editingIndex !== null && customAfter.length > 0 ? html`
767
+ <devtools-list
768
+ class="conditions-list"
769
+ editable
770
+ deletable
771
+ @edit=${(e: Lists.List.ItemEditEvent) => input.onBeginEdit(editingIndex + 1 + e.detail.index)}
772
+ @delete=${(e: Lists.List.ItemRemoveEvent) => input.onRemoveCustomProfile(editingIndex + 1 + e.detail.index)}>
773
+ ${customAfter.map(item => renderConditionsItem(item))}
774
+ </devtools-list>
775
+ ` : nothing}
776
+ <devtools-button
777
+ class="add-conditions-button"
778
+ .variant=${Buttons.Button.Variant.OUTLINED}
779
+ .iconName=${'plus'}
780
+ .jslogContext=${'network.add-conditions'}
781
+ @click=${input.onAddCustomProfile}>
782
+ ${i18nString(UIStrings.addCustomProfile)}
783
+ </devtools-button>
784
+ </div>
785
+ </devtools-card>
786
+ </div>
787
+ </div>
788
+ `,
789
+ target, {container: {attributes: {jslog: `${VisualLogging.pane('throttling-conditions')}`}}});
790
+ // clang-format on
791
+ };
792
+
793
+ const EMPTY_EDITOR_VALUES: EditorValues = {
794
+ title: '',
795
+ download: '',
796
+ upload: '',
797
+ latency: '',
798
+ packetLoss: '',
799
+ packetQueueLength: '',
800
+ packetReordering: false,
801
+ };
802
+
803
+ export class ThrottlingSettingsTab extends UI.Widget.VBox {
473
804
  private readonly customUserConditions: Common.Settings.Setting<SDK.NetworkManager.Conditions[]>;
474
- private editor?: UI.ListWidget.Editor<SDK.NetworkManager.Conditions>;
475
- private cpuThrottlingCard: CPUThrottlingCard;
805
+ readonly #view: View;
476
806
  /**
477
807
  * We store how many custom conditions the user has defined when we load up
478
808
  * DevTools. This is because when the user creates a new one, we need to
@@ -481,46 +811,20 @@ export class ThrottlingSettingsTab extends UI.Widget.VBox implements
481
811
  * profile; we always use this counter which is only ever incremented.
482
812
  */
483
813
  #customUserConditionsCount: number;
814
+ #editingIndex: number|null = null;
815
+ #editingConditions: SDK.NetworkManager.Conditions|null = null;
816
+ #editingValues: EditorValues = {...EMPTY_EDITOR_VALUES};
817
+ #showValidationErrors = false;
484
818
 
485
- constructor(settings: Common.Settings.Settings) {
819
+ constructor(settings: Common.Settings.Settings, view: View = DEFAULT_VIEW) {
486
820
  super({
487
- jslog: `${VisualLogging.pane('throttling-conditions')}`,
488
821
  useShadowDom: true,
489
822
  });
823
+ this.#view = view;
490
824
  this.registerRequiredCSS(throttlingSettingsTabStyles);
491
825
 
492
- const settingsContent =
493
- this.contentElement.createChild('div', 'settings-card-container-wrapper').createChild('div');
494
- settingsContent.classList.add('settings-card-container', 'throttling-conditions-settings');
495
-
496
- this.cpuThrottlingCard = new CPUThrottlingCard(settings);
497
- settingsContent.append(this.cpuThrottlingCard.element);
498
-
499
- const addButton = new Buttons.Button.Button();
500
- addButton.classList.add('add-conditions-button');
501
- addButton.data = {
502
- variant: Buttons.Button.Variant.OUTLINED,
503
- iconName: 'plus',
504
- jslogContext: 'network.add-conditions',
505
- };
506
- addButton.textContent = i18nString(UIStrings.addCustomProfile);
507
- addButton.addEventListener('click', () => this.addButtonClicked());
508
-
509
- this.presetsList = new UI.ListWidget.ListWidget(this);
510
- this.presetsList.setHeader(createHeaderRow());
511
- createProfilesCard(i18nString(UIStrings.defaultProfiles), this.presetsList, settingsContent);
512
- const presets = ThrottlingPresets.networkPresets;
513
- for (let i = 0; i < presets.length; ++i) {
514
- this.presetsList.appendItem(presets[i], false);
515
- }
516
-
517
- this.customList = new UI.ListWidget.ListWidget(this);
518
- this.customList.setHeader(createHeaderRow());
519
- const customContainer = createProfilesCard(i18nString(UIStrings.customProfiles), this.customList, settingsContent);
520
- customContainer.appendChild(addButton);
521
-
522
826
  this.customUserConditions = SDK.NetworkManager.customUserNetworkConditionsSetting(settings);
523
- this.customUserConditions.addChangeListener(this.conditionsUpdated, this);
827
+ this.customUserConditions.addChangeListener(this.#conditionsUpdated, this);
524
828
 
525
829
  const customConditions = this.customUserConditions.get();
526
830
  // We need to parse out the current max condition key index. If the last
@@ -539,31 +843,53 @@ export class ThrottlingSettingsTab extends UI.Widget.VBox implements
539
843
  } else {
540
844
  this.#customUserConditionsCount = 0;
541
845
  }
542
- }
543
846
 
544
- override wasShown(): void {
545
- super.wasShown();
546
- this.cpuThrottlingCard.wasShown();
547
- this.conditionsUpdated();
847
+ this.performUpdate();
548
848
  }
549
849
 
550
- override willHide(): void {
551
- super.willHide();
552
- this.cpuThrottlingCard.willHide();
850
+ override performUpdate(): void {
851
+ const customConditions = this.customUserConditions.get();
852
+ const validationErrors = this.#editingIndex !== null ? this.#validateEditorValues(this.#editingValues) : {};
853
+
854
+ this.#view(
855
+ {
856
+ presets: ThrottlingPresets.networkPresets,
857
+ customConditions,
858
+ editingIndex: this.#editingIndex,
859
+ editingValues: this.#editingValues,
860
+ validationErrors,
861
+ showValidationErrors: this.#showValidationErrors,
862
+ onAddCustomProfile: () => this.#addButtonClicked(),
863
+ onBeginEdit: this.#beginEdit.bind(this),
864
+ onRemoveCustomProfile: this.#removeCustomProfile.bind(this),
865
+ onEditorInput: this.#onEditorInput.bind(this),
866
+ onCommitEdit: this.#commitEdit.bind(this),
867
+ onCancelEdit: this.#cancelEdit.bind(this),
868
+ },
869
+ undefined,
870
+ this.contentElement,
871
+ );
553
872
  }
554
873
 
555
- private conditionsUpdated(): void {
556
- this.customList.clear();
874
+ override wasShown(): void {
875
+ super.wasShown();
876
+ this.#conditionsUpdated();
877
+ this.performUpdate();
878
+ }
557
879
 
558
- const conditions = this.customUserConditions.get();
559
- for (let i = 0; i < conditions.length; ++i) {
560
- this.customList.appendItem(conditions[i], true);
561
- }
880
+ #conditionsUpdated(): void {
881
+ this.#editingIndex = null;
882
+ this.#editingConditions = null;
883
+ this.#editingValues = {...EMPTY_EDITOR_VALUES};
884
+ this.#showValidationErrors = false;
885
+ this.requestUpdate();
562
886
  }
563
887
 
564
- private addButtonClicked(): void {
888
+ #addButtonClicked(): void {
565
889
  this.#customUserConditionsCount++;
566
- this.customList.addNewItem(this.customList.items.length, {
890
+ const customConditions = this.customUserConditions.get();
891
+ this.#editingIndex = customConditions.length;
892
+ this.#editingConditions = {
567
893
  key: `USER_CUSTOM_SETTING_${this.#customUserConditionsCount}`,
568
894
  title: () => '',
569
895
  download: -1,
@@ -571,280 +897,143 @@ export class ThrottlingSettingsTab extends UI.Widget.VBox implements
571
897
  latency: 0,
572
898
  packetLoss: 0,
573
899
  packetReordering: false,
574
- });
900
+ };
901
+ this.#editingValues = {...EMPTY_EDITOR_VALUES};
902
+ this.#showValidationErrors = false;
903
+ this.requestUpdate();
575
904
  }
576
905
 
577
- renderItem(conditions: SDK.NetworkManager.Conditions, _editable: boolean): Element {
578
- const element = document.createElement('div');
579
- element.classList.add('conditions-list-item');
580
- const title = element.createChild('div', 'conditions-list-text conditions-list-title');
581
- const titleText = title.createChild('div', 'conditions-list-title-text');
582
- const castedTitle = this.retrieveOptionsTitle(conditions);
583
- titleText.textContent = castedTitle;
584
- UI.Tooltip.Tooltip.install(title, castedTitle);
585
- element.createChild('div', 'conditions-list-separator');
586
- element.createChild('div', 'conditions-list-text').textContent = throughputText(conditions.download);
587
- element.createChild('div', 'conditions-list-separator');
588
- element.createChild('div', 'conditions-list-text').textContent = throughputText(conditions.upload);
589
- element.createChild('div', 'conditions-list-separator');
590
- element.createChild('div', 'conditions-list-text').textContent =
591
- i18nString(UIStrings.dms, {PH1: conditions.latency});
592
- element.createChild('div', 'conditions-list-separator');
593
- element.createChild('div', 'conditions-list-text').textContent = percentText(conditions.packetLoss ?? 0);
594
- element.createChild('div', 'conditions-list-separator');
595
- element.createChild('div', 'conditions-list-text').textContent = String(conditions.packetQueueLength ?? 0);
596
- element.createChild('div', 'conditions-list-separator');
597
- element.createChild('div', 'conditions-list-text').textContent =
598
- conditions.packetReordering ? i18nString(UIStrings.on) : i18nString(UIStrings.off);
599
-
600
- return element;
906
+ #beginEdit(index: number): void {
907
+ const customConditions = this.customUserConditions.get();
908
+ const conditions = customConditions[index];
909
+ if (!conditions) {
910
+ return;
911
+ }
912
+ this.#editingIndex = index;
913
+ this.#editingConditions = conditions;
914
+ this.#editingValues = {
915
+ title: retrieveOptionsTitle(conditions),
916
+ download: conditions.download <= 0 ? '' : String(conditions.download / (1000 / 8)),
917
+ upload: conditions.upload <= 0 ? '' : String(conditions.upload / (1000 / 8)),
918
+ latency: conditions.latency ? String(conditions.latency) : '',
919
+ packetLoss: conditions.packetLoss ? String(conditions.packetLoss) : '',
920
+ packetQueueLength: conditions.packetQueueLength ? String(conditions.packetQueueLength) : '',
921
+ packetReordering: conditions.packetReordering ?? false,
922
+ };
923
+ this.#showValidationErrors = false;
924
+ this.requestUpdate();
601
925
  }
602
926
 
603
- removeItemRequested(_item: SDK.NetworkManager.Conditions, index: number): void {
604
- const list = this.customUserConditions.get();
605
- list.splice(index, 1);
606
- this.customUserConditions.set(list);
927
+ #onEditorInput<K extends EditorFieldName>(field: K, value: EditorValues[K]): void {
928
+ this.#editingValues = {
929
+ ...this.#editingValues,
930
+ [field]: value,
931
+ };
932
+ this.#showValidationErrors = true;
933
+ this.requestUpdate();
607
934
  }
608
935
 
609
- retrieveOptionsTitle(conditions: SDK.NetworkManager.Conditions): string {
610
- // The title is usually an i18nLazyString except for custom values that are stored in the local storage in the form of a string.
611
- const castedTitle = typeof conditions.title === 'function' ? conditions.title() : conditions.title;
612
- return castedTitle;
936
+ #cancelEdit(): void {
937
+ this.#editingIndex = null;
938
+ this.#editingConditions = null;
939
+ this.#editingValues = {...EMPTY_EDITOR_VALUES};
940
+ this.#showValidationErrors = false;
941
+ this.requestUpdate();
613
942
  }
614
943
 
615
- commitEdit(
616
- conditions: SDK.NetworkManager.Conditions, editor: UI.ListWidget.Editor<SDK.NetworkManager.Conditions>,
617
- isNew: boolean): void {
618
- conditions.title = editor.control('title').value.trim();
619
- const download = editor.control('download').value.trim();
944
+ #commitEdit(): void {
945
+ if (this.#editingIndex === null || !this.#editingConditions) {
946
+ return;
947
+ }
948
+ const validationErrors = this.#validateEditorValues(this.#editingValues);
949
+ if (Object.keys(validationErrors).length > 0) {
950
+ this.#showValidationErrors = true;
951
+ this.requestUpdate();
952
+ return;
953
+ }
954
+
955
+ const conditions = this.#editingConditions;
956
+ conditions.title = this.#editingValues.title.trim();
957
+ const download = this.#editingValues.download.trim();
620
958
  conditions.download = download ? parseInt(download, 10) * (1000 / 8) : -1;
621
- const upload = editor.control('upload').value.trim();
959
+ const upload = this.#editingValues.upload.trim();
622
960
  conditions.upload = upload ? parseInt(upload, 10) * (1000 / 8) : -1;
623
- const latency = editor.control('latency').value.trim();
961
+ const latency = this.#editingValues.latency.trim();
624
962
  conditions.latency = latency ? parseInt(latency, 10) : 0;
625
- const packetLoss = editor.control('packetLoss').value.trim();
963
+ const packetLoss = this.#editingValues.packetLoss.trim();
626
964
  conditions.packetLoss = packetLoss ? parseFloat(packetLoss) : 0;
627
- const packetQueueLength = editor.control('packetQueueLength').value.trim();
965
+ const packetQueueLength = this.#editingValues.packetQueueLength.trim();
628
966
  conditions.packetQueueLength = packetQueueLength ? parseFloat(packetQueueLength) : 0;
629
- const packetReordering = (editor.control('packetReordering') as HTMLInputElement).checked;
630
- conditions.packetReordering = packetReordering;
967
+ conditions.packetReordering = this.#editingValues.packetReordering;
631
968
 
632
- const list = this.customUserConditions.get();
633
- if (isNew) {
969
+ const list = [...this.customUserConditions.get()];
970
+ if (this.#editingIndex === list.length) {
634
971
  list.push(conditions);
635
972
  }
636
973
 
974
+ this.#editingIndex = null;
975
+ this.#editingConditions = null;
976
+ this.#editingValues = {...EMPTY_EDITOR_VALUES};
977
+ this.#showValidationErrors = false;
637
978
  this.customUserConditions.set(list);
638
979
  }
639
980
 
640
- beginEdit(conditions: SDK.NetworkManager.Conditions): UI.ListWidget.Editor<SDK.NetworkManager.Conditions> {
641
- const editor = this.createEditor();
642
- editor.control('title').value = this.retrieveOptionsTitle(conditions);
643
- editor.control('download').value = conditions.download <= 0 ? '' : String(conditions.download / (1000 / 8));
644
- editor.control('upload').value = conditions.upload <= 0 ? '' : String(conditions.upload / (1000 / 8));
645
- editor.control('latency').value = conditions.latency ? String(conditions.latency) : '';
646
- editor.control('packetLoss').value = conditions.packetLoss ? String(conditions.packetLoss) : '';
647
- editor.control('packetQueueLength').value =
648
- conditions.packetQueueLength ? String(conditions.packetQueueLength) : '';
649
- (editor.control('packetReordering') as HTMLInputElement).checked = conditions.packetReordering ?? false;
650
- return editor;
981
+ #removeCustomProfile(index: number): void {
982
+ const list = [...this.customUserConditions.get()];
983
+ list.splice(index, 1);
984
+ this.customUserConditions.set(list);
651
985
  }
652
986
 
653
- private createEditor(): UI.ListWidget.Editor<SDK.NetworkManager.Conditions> {
654
- if (this.editor) {
655
- return this.editor;
656
- }
657
-
658
- // Define the settings configuration
659
- const settings = [
660
- {
661
- name: 'title',
662
- labelText: i18nString(UIStrings.profileName),
663
- inputType: 'text',
664
- placeholder: '',
665
- validator: titleValidator,
666
- isOptional: false,
667
- },
668
- {
669
- name: 'download',
670
- labelText: i18nString(UIStrings.download),
671
- inputType: 'text',
672
- placeholder: i18n.i18n.lockedString('kbit/s'),
673
- validator: throughputValidator,
674
- },
675
- {
676
- name: 'upload',
677
- labelText: i18nString(UIStrings.upload),
678
- inputType: 'text',
679
- placeholder: i18n.i18n.lockedString('kbit/s'),
680
- validator: throughputValidator,
681
- },
682
- {
683
- name: 'latency',
684
- labelText: i18nString(UIStrings.latency),
685
- inputType: 'text',
686
- placeholder: i18n.i18n.lockedString('ms'),
687
- validator: latencyValidator,
688
- },
689
- {
690
- name: 'packetLoss',
691
- labelText: i18nString(UIStrings.packetLoss),
692
- inputType: 'text',
693
- placeholder: i18n.i18n.lockedString('percent'),
694
- validator: packetLossValidator,
695
- },
696
- {
697
- name: 'packetQueueLength',
698
- labelText: i18nString(UIStrings.packetQueueLength),
699
- inputType: 'text',
700
- placeholder: i18nString(UIStrings.packet),
701
- validator: packetQueueLengthValidator,
702
- },
703
- {
704
- name: 'packetReordering',
705
- labelText: i18nString(UIStrings.packetReordering),
706
- inputType: 'checkbox',
707
- placeholder: '',
708
- validator: packetReorderingValidator,
709
- isOptional: false,
710
- },
711
- ];
712
-
713
- const editor = new UI.ListWidget.Editor<SDK.NetworkManager.Conditions>();
714
- this.editor = editor;
715
- const content = editor.contentElement();
716
-
717
- const settingsContainer = content.createChild('div', 'settings-container');
718
-
719
- const createSettingField = (
720
- name: string,
721
- labelText: Common.UIString.LocalizedString,
722
- inputType: string,
723
- placeholder: Common.UIString.LocalizedString|string,
724
- validator: (item: SDK.NetworkManager.Conditions, index: number, input: UI.ListWidget.EditorControl) =>
725
- UI.ListWidget.ValidatorResult,
726
- isOptional = true,
727
- ): void => {
728
- const settingElement = settingsContainer.createChild('div', 'setting');
729
- // Create title element
730
- const titleContainer = settingElement.createChild('div');
731
- titleContainer.textContent = labelText;
732
- // Create input element
733
- const inputElement = settingElement.createChild('div');
734
- const input = editor.createInput(name, inputType, placeholder, validator);
735
- input.classList.add('input');
736
- UI.ARIAUtils.setLabel(input, labelText);
737
- inputElement.appendChild(input);
738
-
739
- const optionalTextElement = inputElement.createChild('div');
740
- const optionalStr = i18nString(UIStrings.optional);
741
- optionalTextElement.textContent = optionalStr;
742
- UI.ARIAUtils.setDescription(input, optionalStr);
743
- if (!isOptional) {
744
- optionalTextElement.style.visibility = 'hidden';
745
- }
746
- };
747
-
748
- // Iterate over settings and create components
749
- settings.forEach(setting => {
750
- createSettingField(
751
- setting.name, setting.labelText, setting.inputType, setting.placeholder, setting.validator,
752
- setting.isOptional);
753
- });
754
-
755
- return editor;
987
+ #validateEditorValues(values: EditorValues): Partial<Record<EditorFieldName, Common.UIString.LocalizedString>> {
988
+ const errors: Partial<Record<EditorFieldName, Common.UIString.LocalizedString>> = {};
756
989
 
757
- function titleValidator(_item: SDK.NetworkManager.Conditions, _index: number, input: UI.ListWidget.EditorControl):
758
- UI.ListWidget.ValidatorResult {
759
- const maxLength = 49;
760
- const value = input.value.trim();
761
- const valid = value.length > 0 && value.length <= maxLength;
762
- if (!valid) {
763
- const errorMessage = i18nString(UIStrings.profileNameCharactersLengthMust, {PH1: maxLength});
764
- return {valid, errorMessage};
765
- }
766
- return {
767
- valid,
768
- };
990
+ const maxLength = 49;
991
+ const title = values.title.trim();
992
+ if (title.length === 0 || title.length > maxLength) {
993
+ errors.title = i18nString(UIStrings.profileNameCharactersLengthMust, {PH1: maxLength});
769
994
  }
770
995
 
771
- function throughputValidator(
772
- _item: SDK.NetworkManager.Conditions, _index: number,
773
- input: UI.ListWidget.EditorControl): UI.ListWidget.ValidatorResult {
774
- const minThroughput = 0;
775
- const maxThroughput = 10000000;
776
- const value = input.value.trim();
777
- const parsedValue = Number(value);
778
- const throughput = input.getAttribute('aria-label');
779
- const valid = !Number.isNaN(parsedValue) && parsedValue >= minThroughput && parsedValue <= maxThroughput;
780
- if (!valid) {
781
- const errorMessage = i18nString(
782
- UIStrings.sMustBeANumberBetweenSkbsToSkbs,
783
- {PH1: String(throughput), PH2: minThroughput, PH3: maxThroughput});
784
- return {valid, errorMessage};
785
- }
786
- return {
787
- valid,
788
- };
996
+ const minThroughput = 0;
997
+ const maxThroughput = 10000000;
998
+ const download = values.download.trim();
999
+ const parsedDownload = Number(download);
1000
+ if (Number.isNaN(parsedDownload) || parsedDownload < minThroughput || parsedDownload > maxThroughput) {
1001
+ errors.download = i18nString(UIStrings.sMustBeANumberBetweenSkbsToSkbs,
1002
+ {PH1: i18nString(UIStrings.download), PH2: minThroughput, PH3: maxThroughput});
789
1003
  }
790
1004
 
791
- function latencyValidator(_item: SDK.NetworkManager.Conditions, _index: number, input: UI.ListWidget.EditorControl):
792
- UI.ListWidget.ValidatorResult {
793
- const minLatency = 0;
794
- const maxLatency = 1000000;
795
- const value = input.value.trim();
796
- const parsedValue = Number(value);
797
- const valid = Number.isInteger(parsedValue) && parsedValue >= minLatency && parsedValue <= maxLatency;
798
- if (!valid) {
799
- const errorMessage = i18nString(UIStrings.latencyMustBeAnIntegerBetweenSms, {PH1: minLatency, PH2: maxLatency});
800
- return {valid, errorMessage};
801
- }
802
- return {
803
- valid,
804
- };
1005
+ const upload = values.upload.trim();
1006
+ const parsedUpload = Number(upload);
1007
+ if (Number.isNaN(parsedUpload) || parsedUpload < minThroughput || parsedUpload > maxThroughput) {
1008
+ errors.upload = i18nString(UIStrings.sMustBeANumberBetweenSkbsToSkbs,
1009
+ {PH1: i18nString(UIStrings.upload), PH2: minThroughput, PH3: maxThroughput});
805
1010
  }
806
1011
 
807
- function packetLossValidator(
808
- _item: SDK.NetworkManager.Conditions, _index: number,
809
- input: UI.ListWidget.EditorControl): UI.ListWidget.ValidatorResult {
810
- const minPacketLoss = 0;
811
- const maxPacketLoss = 100;
812
- const value = input.value.trim();
813
- const parsedValue = Number(value);
814
- const valid = parsedValue >= minPacketLoss && parsedValue <= maxPacketLoss;
815
- if (!valid) {
816
- const errorMessage =
817
- i18nString(UIStrings.packetLossMustBeAnIntegerBetweenSpct, {PH1: minPacketLoss, PH2: maxPacketLoss});
818
- return {valid, errorMessage};
819
- }
820
- return {
821
- valid,
822
- };
1012
+ const minLatency = 0;
1013
+ const maxLatency = 1000000;
1014
+ const latency = values.latency.trim();
1015
+ const parsedLatency = Number(latency);
1016
+ if (!Number.isInteger(parsedLatency) || parsedLatency < minLatency || parsedLatency > maxLatency) {
1017
+ errors.latency = i18nString(UIStrings.latencyMustBeAnIntegerBetweenSms, {PH1: minLatency, PH2: maxLatency});
823
1018
  }
824
1019
 
825
- function packetQueueLengthValidator(
826
- _item: SDK.NetworkManager.Conditions, _index: number,
827
- input: UI.ListWidget.EditorControl): UI.ListWidget.ValidatorResult {
828
- const minPacketQueueLength = 0;
829
- const value = input.value.trim();
830
- const parsedValue = Number(value);
831
- const valid = parsedValue >= minPacketQueueLength;
832
- if (!valid) {
833
- const errorMessage = i18nString(UIStrings.packetQueueLengthMustBeAnIntegerGreaterOrEqualToZero);
834
- return {valid, errorMessage};
835
- }
836
- return {
837
- valid,
838
- };
1020
+ const minPacketLoss = 0;
1021
+ const maxPacketLoss = 100;
1022
+ const packetLoss = values.packetLoss.trim();
1023
+ const parsedPacketLoss = Number(packetLoss);
1024
+ if (Number.isNaN(parsedPacketLoss) || parsedPacketLoss < minPacketLoss || parsedPacketLoss > maxPacketLoss) {
1025
+ errors.packetLoss =
1026
+ i18nString(UIStrings.packetLossMustBeAnIntegerBetweenSpct, {PH1: minPacketLoss, PH2: maxPacketLoss});
839
1027
  }
840
1028
 
841
- function packetReorderingValidator(
842
- _item: SDK.NetworkManager.Conditions, _index: number,
843
- _input: UI.ListWidget.EditorControl): UI.ListWidget.ValidatorResult {
844
- return {
845
- valid: true,
846
- };
1029
+ const minPacketQueueLength = 0;
1030
+ const packetQueueLength = values.packetQueueLength.trim();
1031
+ const parsedPacketQueueLength = Number(packetQueueLength);
1032
+ if (Number.isNaN(parsedPacketQueueLength) || parsedPacketQueueLength < minPacketQueueLength) {
1033
+ errors.packetQueueLength = i18nString(UIStrings.packetQueueLengthMustBeAnIntegerGreaterOrEqualToZero);
847
1034
  }
1035
+
1036
+ return errors;
848
1037
  }
849
1038
  }
850
1039
 
@@ -871,41 +1060,3 @@ function percentText(percent: number): string {
871
1060
  }
872
1061
  return String(percent) + '%';
873
1062
  }
874
-
875
- function createProfilesCard(heading: string, list: UI.ListWidget.ListWidget<SDK.NetworkManager.Conditions>,
876
- parent: Element): HTMLElement {
877
- const card = parent.createChild('devtools-card');
878
- card.heading = heading;
879
- const container = card.createChild('div');
880
- list.element.classList.add('conditions-list');
881
- list.registerRequiredCSS(throttlingSettingsTabStyles);
882
- list.show(container);
883
- return container;
884
- }
885
-
886
- function appendHeaderColumn(element: Element, text: string): void {
887
- element.createChild('div', 'conditions-list-separator');
888
- const column = element.createChild('div', 'conditions-list-text');
889
- column.textContent = text;
890
- UI.Tooltip.Tooltip.install(column, text);
891
- }
892
-
893
- function createHeaderRow(): Element {
894
- const element = document.createElement('div');
895
- element.classList.add('conditions-list-item', 'conditions-list-header');
896
-
897
- const title = element.createChild('div', 'conditions-list-text conditions-list-title');
898
- const titleText = title.createChild('div', 'conditions-list-title-text');
899
- const profileName = i18nString(UIStrings.profileName);
900
- titleText.textContent = profileName;
901
- UI.Tooltip.Tooltip.install(title, profileName);
902
-
903
- appendHeaderColumn(element, i18nString(UIStrings.download));
904
- appendHeaderColumn(element, i18nString(UIStrings.upload));
905
- appendHeaderColumn(element, i18nString(UIStrings.latency));
906
- appendHeaderColumn(element, i18nString(UIStrings.packetLoss));
907
- appendHeaderColumn(element, i18nString(UIStrings.packetQueueLength));
908
- appendHeaderColumn(element, i18nString(UIStrings.packetReordering));
909
-
910
- return element;
911
- }