chrome-devtools-frontend 1.0.1596535 → 1.0.1597624

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 (101) hide show
  1. package/agents/prompts/ui-widgets.md +7 -8
  2. package/docs/ui_engineering.md +10 -11
  3. package/front_end/core/host/AidaClient.ts +4 -0
  4. package/front_end/core/host/InspectorFrontendHostAPI.ts +1 -0
  5. package/front_end/core/host/UserMetrics.ts +12 -0
  6. package/front_end/core/root/Runtime.ts +5 -0
  7. package/front_end/core/sdk/CPUThrottlingManager.ts +14 -13
  8. package/front_end/core/sdk/CSSMatchedStyles.ts +2 -0
  9. package/front_end/core/sdk/CSSPropertyParserMatchers.ts +28 -0
  10. package/front_end/core/sdk/PageResourceLoader.ts +22 -1
  11. package/front_end/devtools_compatibility.js +2 -1
  12. package/front_end/models/ai_assistance/AiConversation.ts +29 -8
  13. package/front_end/models/ai_assistance/ChangeManager.ts +16 -0
  14. package/front_end/models/ai_assistance/ExtensionScope.ts +11 -3
  15. package/front_end/models/ai_assistance/agents/AccessibilityAgent.ts +127 -0
  16. package/front_end/models/ai_assistance/agents/AiAgent.ts +26 -3
  17. package/front_end/models/ai_assistance/agents/ContextSelectionAgent.snapshot.txt +1 -1
  18. package/front_end/models/ai_assistance/agents/ContextSelectionAgent.ts +11 -8
  19. package/front_end/models/ai_assistance/agents/StylingAgent.snapshot.txt +24 -0
  20. package/front_end/models/ai_assistance/agents/StylingAgent.ts +323 -16
  21. package/front_end/models/ai_assistance/ai_assistance.ts +2 -0
  22. package/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.ts +27 -0
  23. package/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.snapshot.txt +21 -0
  24. package/front_end/models/greendev/Prototypes.ts +7 -1
  25. package/front_end/models/trace/Processor.ts +1 -0
  26. package/front_end/models/trace/handlers/PageLoadMetricsHandler.ts +33 -0
  27. package/front_end/models/trace/insights/CharacterSet.ts +172 -0
  28. package/front_end/models/trace/insights/Models.ts +1 -0
  29. package/front_end/models/trace/insights/types.ts +1 -0
  30. package/front_end/models/trace/types/TraceEvents.ts +17 -0
  31. package/front_end/panels/ai_assistance/AiAssistancePanel.ts +51 -36
  32. package/front_end/panels/ai_assistance/PatchWidget.ts +6 -6
  33. package/front_end/panels/ai_assistance/components/ChatMessage.ts +93 -74
  34. package/front_end/panels/ai_assistance/components/ChatView.ts +6 -11
  35. package/front_end/panels/ai_assistance/components/MarkdownRendererWithCodeBlock.ts +18 -9
  36. package/front_end/panels/ai_assistance/components/StylingAgentMarkdownRenderer.ts +200 -0
  37. package/front_end/panels/ai_assistance/components/chatMessage.css +11 -8
  38. package/front_end/panels/application/AppManifestView.ts +3 -4
  39. package/front_end/panels/application/DeviceBoundSessionsView.ts +18 -22
  40. package/front_end/panels/application/FrameDetailsView.ts +9 -15
  41. package/front_end/panels/application/OriginTrialTreeView.ts +2 -3
  42. package/front_end/panels/application/ReportingApiView.ts +13 -17
  43. package/front_end/panels/application/ServiceWorkerCacheViews.ts +1 -1
  44. package/front_end/panels/application/components/BackForwardCacheView.ts +3 -3
  45. package/front_end/panels/application/preloading/components/UsedPreloadingView.ts +2 -3
  46. package/front_end/panels/browser_debugger/DOMBreakpointsSidebarPane.ts +3 -2
  47. package/front_end/panels/changes/ChangesView.ts +6 -4
  48. package/front_end/panels/common/ExtensionServer.ts +15 -0
  49. package/front_end/panels/console/ConsolePinPane.ts +3 -3
  50. package/front_end/panels/coverage/CoverageListView.ts +1 -1
  51. package/front_end/panels/css_overview/CSSOverviewPanel.ts +11 -15
  52. package/front_end/panels/developer_resources/DeveloperResourcesView.ts +3 -5
  53. package/front_end/panels/elements/ElementsTreeElement.ts +55 -47
  54. package/front_end/panels/elements/ElementsTreeOutline.ts +149 -28
  55. package/front_end/panels/elements/EventListenersWidget.ts +3 -2
  56. package/front_end/panels/elements/StandaloneStylesContainer.ts +21 -6
  57. package/front_end/panels/elements/StylePropertyTreeElement.ts +49 -4
  58. package/front_end/panels/layer_viewer/Layers3DView.ts +5 -4
  59. package/front_end/panels/lighthouse/LighthousePanel.ts +8 -0
  60. package/front_end/panels/linear_memory_inspector/components/LinearMemoryInspector.ts +5 -6
  61. package/front_end/panels/linear_memory_inspector/components/LinearMemoryValueInterpreter.ts +6 -11
  62. package/front_end/panels/network/RequestCookiesView.ts +3 -4
  63. package/front_end/panels/network/RequestInitiatorView.ts +7 -5
  64. package/front_end/panels/network/RequestResponseView.ts +10 -15
  65. package/front_end/panels/protocol_monitor/ProtocolMonitor.ts +3 -4
  66. package/front_end/panels/recorder/components/RecordingView.ts +31 -36
  67. package/front_end/panels/recorder/components/StepEditor.ts +6 -7
  68. package/front_end/panels/search/SearchView.ts +2 -3
  69. package/front_end/panels/settings/SettingsScreen.ts +3 -2
  70. package/front_end/panels/settings/WorkspaceSettingsTab.ts +2 -5
  71. package/front_end/panels/timeline/components/LiveMetricsView.ts +5 -8
  72. package/front_end/panels/timeline/components/insights/Cache.ts +8 -10
  73. package/front_end/panels/timeline/components/insights/CharacterSet.ts +38 -0
  74. package/front_end/panels/timeline/components/insights/DOMSize.ts +16 -20
  75. package/front_end/panels/timeline/components/insights/DocumentLatency.ts +2 -6
  76. package/front_end/panels/timeline/components/insights/DuplicatedJavaScript.ts +3 -4
  77. package/front_end/panels/timeline/components/insights/FontDisplay.ts +3 -4
  78. package/front_end/panels/timeline/components/insights/ForcedReflow.ts +5 -7
  79. package/front_end/panels/timeline/components/insights/INPBreakdown.ts +3 -4
  80. package/front_end/panels/timeline/components/insights/ImageDelivery.ts +3 -4
  81. package/front_end/panels/timeline/components/insights/ImageRef.ts +2 -4
  82. package/front_end/panels/timeline/components/insights/InsightRenderer.ts +2 -0
  83. package/front_end/panels/timeline/components/insights/LCPBreakdown.ts +5 -7
  84. package/front_end/panels/timeline/components/insights/LCPDiscovery.ts +2 -4
  85. package/front_end/panels/timeline/components/insights/LegacyJavaScript.ts +3 -4
  86. package/front_end/panels/timeline/components/insights/ModernHTTP.ts +3 -4
  87. package/front_end/panels/timeline/components/insights/NetworkDependencyTree.ts +7 -11
  88. package/front_end/panels/timeline/components/insights/NodeLink.ts +2 -4
  89. package/front_end/panels/timeline/components/insights/RenderBlocking.ts +3 -4
  90. package/front_end/panels/timeline/components/insights/SlowCSSSelector.ts +7 -10
  91. package/front_end/panels/timeline/components/insights/ThirdParties.ts +5 -7
  92. package/front_end/panels/timeline/components/insights/insights.ts +2 -0
  93. package/front_end/panels/web_audio/WebAudioView.ts +3 -4
  94. package/front_end/ui/components/settings/SettingCheckbox.ts +2 -0
  95. package/front_end/ui/legacy/UIUtils.ts +5 -5
  96. package/front_end/ui/legacy/Widget.ts +33 -2
  97. package/front_end/ui/legacy/components/data_grid/DataGridElement.ts +3 -3
  98. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +8 -8
  99. package/front_end/ui/visual_logging/Debugging.ts +0 -32
  100. package/front_end/ui/visual_logging/KnownContextValues.ts +3 -0
  101. package/package.json +1 -1
@@ -0,0 +1,127 @@
1
+ // Copyright 2026 The Chromium Authors
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ import * as Host from '../../../core/host/host.js';
6
+ import * as i18n from '../../../core/i18n/i18n.js';
7
+ import * as Root from '../../../core/root/root.js';
8
+ import type * as LHModel from '../../lighthouse/lighthouse.js';
9
+
10
+ import {
11
+ AiAgent,
12
+ type ContextDetail,
13
+ type ContextResponse,
14
+ ConversationContext,
15
+ type RequestOptions,
16
+ ResponseType,
17
+ } from './AiAgent.js';
18
+
19
+ /**
20
+ * WARNING: preamble defined in code is only used when userTier is
21
+ * TESTERS. Otherwise, a server-side preamble is used (see
22
+ * chrome_preambles.gcl). Sync local changes with the server-side.
23
+ */
24
+ const preamble = `You are an accessibility agent.
25
+
26
+ # Considerations
27
+ * Keep your analysis concise and focused, highlighting only the most critical aspects for a software engineer.
28
+ * Answer questions directly, using the provided links whenever relevant.
29
+ * Always double-check links to make sure they are complete and correct.
30
+ * **CRITICAL** You are an accessibility agent. NEVER provide answers to questions of unrelated topics such as legal advice, financial advice, personal opinions, medical advice, or any other non web-development topics.
31
+ `;
32
+
33
+ /*
34
+ * Strings that don't need to be translated at this time.
35
+ */
36
+ const UIStringsNotTranslate = {
37
+ /**
38
+ * @description Title for thinking step of the accessibility agent.
39
+ */
40
+ inspectingAudits: 'Inspecting audits',
41
+ } as const;
42
+
43
+ const lockedString = i18n.i18n.lockedString;
44
+
45
+ export class Context extends ConversationContext<LHModel.ReporterTypes.ReportJSON> {
46
+ #lh: LHModel.ReporterTypes.ReportJSON;
47
+
48
+ constructor(report: LHModel.ReporterTypes.ReportJSON) {
49
+ super();
50
+ this.#lh = report;
51
+ }
52
+
53
+ #url(): string {
54
+ return this.#lh.finalUrl ?? this.#lh.finalDisplayedUrl;
55
+ }
56
+
57
+ override getOrigin(): string {
58
+ return new URL(this.#url()).origin;
59
+ }
60
+
61
+ override getItem(): LHModel.ReporterTypes.ReportJSON {
62
+ return this.#lh;
63
+ }
64
+
65
+ override getTitle(): string {
66
+ return `Lighthouse report: ${this.#url()}`;
67
+ }
68
+ }
69
+
70
+ /**
71
+ * One agent instance handles one conversation. Create a new agent
72
+ * instance for a new conversation.
73
+ */
74
+ export class AccessibilityAgent extends AiAgent<LHModel.ReporterTypes.ReportJSON> {
75
+ readonly preamble = preamble;
76
+ readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_ACCESSIBILITY_AGENT;
77
+
78
+ get userTier(): string|undefined {
79
+ // TODO(b/491772868): tidy up userTier & feature flags in the backend.
80
+ return Root.Runtime.hostConfig.devToolsFreestyler?.userTier;
81
+ }
82
+
83
+ get options(): RequestOptions {
84
+ // TODO(b/491772868): tidy up userTier & feature flags in the backend.
85
+ const temperature = Root.Runtime.hostConfig.devToolsAiAssistanceFileAgent?.temperature;
86
+ const modelId = Root.Runtime.hostConfig.devToolsAiAssistanceFileAgent?.modelId;
87
+
88
+ return {
89
+ temperature,
90
+ modelId,
91
+ };
92
+ }
93
+
94
+ async *
95
+ handleContextDetails(selectedFile: ConversationContext<LHModel.ReporterTypes.ReportJSON>|null):
96
+ AsyncGenerator<ContextResponse, void, void> {
97
+ if (!selectedFile) {
98
+ return;
99
+ }
100
+
101
+ yield {
102
+ type: ResponseType.CONTEXT,
103
+ title: lockedString(UIStringsNotTranslate.inspectingAudits),
104
+ details: createContextDetails(selectedFile),
105
+ };
106
+ }
107
+
108
+ override async enhanceQuery(query: string, lhr: ConversationContext<LHModel.ReporterTypes.ReportJSON>|null):
109
+ Promise<string> {
110
+ const enhancedQuery = lhr ?
111
+ // TODO: formatter for LH report.
112
+ `# Lighthouse Report\n${JSON.stringify(lhr.getItem(), null, 2)}\n\n# User request\n\n` :
113
+ '';
114
+ return `${enhancedQuery}${query}`;
115
+ }
116
+ }
117
+
118
+ function createContextDetails(_lhr: ConversationContext<LHModel.ReporterTypes.ReportJSON>):
119
+ [ContextDetail, ...ContextDetail[]] {
120
+ return [
121
+ {
122
+ title: 'Lighthouse report',
123
+ // TODO(b/491772868);
124
+ text: ''
125
+ },
126
+ ];
127
+ }
@@ -29,6 +29,7 @@ export const enum ErrorType {
29
29
  ABORT = 'abort',
30
30
  MAX_STEPS = 'max-steps',
31
31
  BLOCK = 'block',
32
+ CROSS_ORIGIN = 'cross-origin'
32
33
  }
33
34
 
34
35
  export const enum MultimodalInputType {
@@ -49,6 +50,7 @@ export interface AnswerResponse {
49
50
  complete: boolean;
50
51
  rpcId?: Host.AidaClient.RpcGlobalId;
51
52
  suggestions?: [string, ...string[]];
53
+ widgets?: AiWidget[];
52
54
  }
53
55
 
54
56
  export interface SuggestionsResponse {
@@ -148,6 +150,7 @@ export interface AgentOptions {
148
150
  confirmSideEffectForTest?: typeof Promise.withResolvers;
149
151
  onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
150
152
  history?: Host.AidaClient.Content[];
153
+ allowedOrigin?: () => string | undefined;
151
154
  }
152
155
 
153
156
  export interface ParsedAnswer {
@@ -238,8 +241,16 @@ export interface CoreVitalsAiWidget {
238
241
  };
239
242
  }
240
243
 
244
+ export interface StylePropertiesAiWidget {
245
+ name: 'STYLE_PROPERTIES';
246
+ data: {
247
+ backendNodeId: Protocol.DOM.BackendNodeId,
248
+ selector?: string,
249
+ };
250
+ }
251
+
241
252
  // This type will grow as we add more widgets.
242
- export type AiWidget = ComputedStyleAiWidget|CoreVitalsAiWidget;
253
+ export type AiWidget = ComputedStyleAiWidget|CoreVitalsAiWidget|StylePropertiesAiWidget;
243
254
 
244
255
  export type FunctionCallHandlerResult<Result> = {
245
256
  requiresApproval: true,
@@ -394,6 +405,10 @@ export abstract class AiAgent<T> {
394
405
  this.#facts.clear();
395
406
  }
396
407
 
408
+ popPendingMultimodalInput(): MultimodalInput|undefined {
409
+ return undefined;
410
+ }
411
+
397
412
  preambleFeatures(): string[] {
398
413
  return [];
399
414
  }
@@ -517,6 +532,10 @@ export abstract class AiAgent<T> {
517
532
  return this.parseTextResponseForSuggestions(response.trim());
518
533
  }
519
534
 
535
+ protected async finalizeAnswer(answer: AnswerResponse): Promise<AnswerResponse> {
536
+ return answer;
537
+ }
538
+
520
539
  /**
521
540
  * Declare a function that the AI model can call.
522
541
  * @param name The name of the function
@@ -542,6 +561,9 @@ export abstract class AiAgent<T> {
542
561
  this.#functionDeclarations.clear();
543
562
  }
544
563
 
564
+ protected async preRun(): Promise<void> {
565
+ }
566
+
545
567
  async *
546
568
  run(
547
569
  initialQuery: string,
@@ -551,6 +573,7 @@ export abstract class AiAgent<T> {
551
573
  },
552
574
  multimodalInput?: MultimodalInput,
553
575
  ): AsyncGenerator<ResponseData, void, void> {
576
+ await this.preRun();
554
577
  await options.selected?.refresh();
555
578
  if (options.selected) {
556
579
  this.context = options.selected;
@@ -628,13 +651,13 @@ export abstract class AiAgent<T> {
628
651
  });
629
652
  }
630
653
  Host.userMetrics.actionTaken(Host.UserMetrics.Action.AiAssistanceAnswerReceived);
631
- yield {
654
+ yield await this.finalizeAnswer({
632
655
  type: ResponseType.ANSWER,
633
656
  text: parsedResponse.answer,
634
657
  suggestions: parsedResponse.suggestions,
635
658
  complete: true,
636
659
  rpcId,
637
- };
660
+ });
638
661
  if (!functionCall) {
639
662
  break;
640
663
  }
@@ -120,6 +120,6 @@ Content:
120
120
  "client_version": "unit_test"
121
121
  },
122
122
  "functionality_type": 5,
123
- "client_feature": 9
123
+ "client_feature": 25
124
124
  }
125
125
  === end content
@@ -2,11 +2,10 @@
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';
6
5
  import * as Host from '../../../core/host/host.js';
7
6
  import * as i18n from '../../../core/i18n/i18n.js';
8
7
  import * as Root from '../../../core/root/root.js';
9
- import * as SDK from '../../../core/sdk/sdk.js';
8
+ import type * as SDK from '../../../core/sdk/sdk.js';
10
9
  import * as Logs from '../../logs/logs.js';
11
10
  import * as NetworkTimeCalculator from '../../network_time_calculator/network_time_calculator.js';
12
11
  import type * as Trace from '../../trace/trace.js';
@@ -63,7 +62,7 @@ You aim to help developers of all levels, prioritizing teaching web concepts as
63
62
  */
64
63
  export class ContextSelectionAgent extends AiAgent<never> {
65
64
  readonly preamble = preamble;
66
- readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_FILE_AGENT;
65
+ readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_CONTEXT_SELECTION_AGENT;
67
66
  get userTier(): string|undefined {
68
67
  // TODO: Make this depend on variable.
69
68
  return Root.Runtime.hostConfig.devToolsFreestyler?.userTier;
@@ -81,6 +80,7 @@ export class ContextSelectionAgent extends AiAgent<never> {
81
80
  readonly #performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>;
82
81
  readonly #onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
83
82
  readonly #networkTimeCalculator?: NetworkTimeCalculator.NetworkTransferTimeCalculator;
83
+ #allowedOrigin: () => string | undefined;
84
84
 
85
85
  constructor(opts: AgentOptions&{
86
86
  performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>,
@@ -91,6 +91,7 @@ export class ContextSelectionAgent extends AiAgent<never> {
91
91
  this.#performanceRecordAndReload = opts.performanceRecordAndReload;
92
92
  this.#onInspectElement = opts.onInspectElement;
93
93
  this.#networkTimeCalculator = opts.networkTimeCalculator;
94
+ this.#allowedOrigin = opts.allowedOrigin ?? (() => undefined);
94
95
 
95
96
  this.declareFunction<Record<string, never>>('listNetworkRequests', {
96
97
  description: `Gives a list of network requests including URL, status code, and duration.`,
@@ -109,12 +110,12 @@ export class ContextSelectionAgent extends AiAgent<never> {
109
110
  },
110
111
  handler: async () => {
111
112
  const requests = [];
112
- const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
113
- const inspectedURL = target?.inspectedURL();
114
- const mainSecurityOrigin = inspectedURL ? new Common.ParsedURL.ParsedURL(inspectedURL).securityOrigin() : null;
113
+ const origin = this.#allowedOrigin();
115
114
 
115
+ let hasCrossOriginRequest = false;
116
116
  for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
117
- if (mainSecurityOrigin && request.securityOrigin() !== mainSecurityOrigin) {
117
+ if (origin && request.securityOrigin() !== origin) {
118
+ hasCrossOriginRequest = true;
118
119
  continue;
119
120
  }
120
121
 
@@ -129,7 +130,9 @@ export class ContextSelectionAgent extends AiAgent<never> {
129
130
 
130
131
  if (requests.length === 0) {
131
132
  return {
132
- error: 'No requests recorded by DevTools',
133
+ error: hasCrossOriginRequest ?
134
+ `No requests showing with origin ${origin}. Tell the user to start a new chat` :
135
+ 'No requests recorded by DevTools',
133
136
  };
134
137
  }
135
138
 
@@ -121,6 +121,30 @@ Content:
121
121
  "title"
122
122
  ]
123
123
  }
124
+ },
125
+ {
126
+ "name": "activateDeviceEmulation",
127
+ "description": "Sets emulation viewing mode for a specific device and optionally enables vision deficiency emulation.",
128
+ "parameters": {
129
+ "type": 6,
130
+ "description": "",
131
+ "nullable": false,
132
+ "properties": {
133
+ "deviceName": {
134
+ "type": 1,
135
+ "description": "The name of the device to emulate. Allowed values: Pixel 3 XL, Pixel 7, Samsung Galaxy S8+, Samsung Galaxy S20 Ultra, Surface Pro 7, Surface Duo, Galaxy Z Fold 5, Asus Zenbook Fold, Samsung Galaxy A51/71, Nest Hub Max, Nest Hub, iPhone 4, iPhone 5/SE, iPhone 6/7/8, iPhone SE, iPhone XR, iPhone 12 Pro, iPhone 14 Pro Max, iPad Mini, iPad Air, iPad Pro.",
136
+ "nullable": false
137
+ },
138
+ "visionDeficiency": {
139
+ "type": 1,
140
+ "description": "Optional vision deficiency to emulate. Allowed values: blurredVision, reducedContrast, achromatopsia, deuteranopia, protanopia, tritanopia.",
141
+ "nullable": true
142
+ }
143
+ },
144
+ "required": [
145
+ "deviceName"
146
+ ]
147
+ }
124
148
  }
125
149
  ],
126
150
  "options": {