chrome-devtools-frontend 1.0.1618066 → 1.0.1621678

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 (69) hide show
  1. package/docs/checklist/README.md +8 -7
  2. package/eslint.config.mjs +7 -0
  3. package/front_end/core/sdk/NetworkManager.ts +23 -2
  4. package/front_end/core/sdk/ServerSentEventsProtocol.ts +1 -1
  5. package/front_end/entrypoints/greendev_floaty/FloatyEntrypoint.ts +119 -13
  6. package/front_end/generated/InspectorBackendCommands.ts +7 -7
  7. package/front_end/generated/SupportedCSSProperties.js +100 -100
  8. package/front_end/generated/protocol-mapping.d.ts +1 -9
  9. package/front_end/generated/protocol-proxy-api.d.ts +1 -9
  10. package/front_end/generated/protocol.ts +6 -1
  11. package/front_end/models/ai_assistance/agents/AiAgent.ts +1 -1
  12. package/front_end/models/ai_assistance/agents/GreenDevAgent.ts +512 -0
  13. package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +95 -104
  14. package/front_end/models/ai_assistance/agents/StylingAgent.ts +9 -16
  15. package/front_end/models/ai_assistance/ai_assistance.ts +2 -0
  16. package/front_end/models/bindings/DebuggerWorkspaceBinding.ts +25 -4
  17. package/front_end/models/bindings/SymbolizedError.ts +86 -2
  18. package/front_end/models/issues_manager/GenericIssue.ts +50 -1
  19. package/front_end/models/issues_manager/descriptions/genericFormModelContextMissingToolDescription.md +5 -0
  20. package/front_end/models/issues_manager/descriptions/genericFormModelContextMissingToolName.md +5 -0
  21. package/front_end/models/issues_manager/descriptions/genericFormModelContextParameterMissingName.md +5 -0
  22. package/front_end/models/issues_manager/descriptions/genericFormModelContextParameterMissingTitleAndDescription.md +5 -0
  23. package/front_end/models/issues_manager/descriptions/genericFormModelContextRequiredParameterMissingName.md +5 -0
  24. package/front_end/models/javascript_metadata/NativeFunctions.js +10 -2
  25. package/front_end/models/stack_trace/DetailedErrorStackParser.ts +11 -3
  26. package/front_end/models/stack_trace/ErrorStackParser.ts +18 -0
  27. package/front_end/models/trace/insights/Common.ts +4 -0
  28. package/front_end/models/trace/insights/types.ts +1 -1
  29. package/front_end/models/web_mcp/WebMCPModel.ts +11 -1
  30. package/front_end/panels/ai_assistance/components/ChatMessage.ts +115 -3
  31. package/front_end/panels/ai_assistance/components/WalkthroughUtils.ts +1 -1
  32. package/front_end/panels/ai_assistance/components/WalkthroughView.ts +9 -2
  33. package/front_end/panels/application/WebMCPView.ts +217 -85
  34. package/front_end/panels/application/webMCPView.css +260 -199
  35. package/front_end/panels/browser_debugger/CategorizedBreakpointsSidebarPane.ts +9 -5
  36. package/front_end/panels/changes/ChangesSidebar.ts +2 -2
  37. package/front_end/panels/changes/ChangesView.ts +4 -7
  38. package/front_end/panels/console/ConsoleViewMessage.ts +1 -19
  39. package/front_end/panels/coverage/CoverageView.ts +4 -5
  40. package/front_end/panels/elements/AdoptedStyleSheetTreeElement.ts +0 -1
  41. package/front_end/panels/elements/ElementsPanel.ts +9 -12
  42. package/front_end/panels/elements/ElementsTreeElement.ts +53 -61
  43. package/front_end/panels/elements/PropertiesWidget.ts +1 -1
  44. package/front_end/panels/elements/StylePropertiesSection.ts +1 -1
  45. package/front_end/panels/elements/components/ElementsBreadcrumbs.ts +19 -20
  46. package/front_end/panels/elements/components/ElementsBreadcrumbsUtils.ts +29 -29
  47. package/front_end/panels/elements/components/QueryContainer.ts +5 -6
  48. package/front_end/panels/elements/components/components.ts +0 -2
  49. package/front_end/panels/emulation/MediaQueryInspector.ts +4 -7
  50. package/front_end/panels/mobile_throttling/NetworkThrottlingSelector.ts +47 -66
  51. package/front_end/panels/network/RequestConditionsDrawer.ts +6 -4
  52. package/front_end/panels/performance_monitor/PerformanceMonitor.ts +6 -9
  53. package/front_end/panels/protocol_monitor/JSONEditor.ts +2 -2
  54. package/front_end/panels/search/SearchView.ts +4 -7
  55. package/front_end/panels/sources/DebuggerPausedMessage.ts +18 -22
  56. package/front_end/panels/sources/ThreadsSidebarPane.ts +2 -4
  57. package/front_end/panels/web_audio/WebAudioView.ts +5 -4
  58. package/front_end/third_party/chromium/README.chromium +1 -1
  59. package/front_end/ui/components/icon_button/iconButton.css +1 -0
  60. package/front_end/ui/components/lists/list.css +4 -0
  61. package/front_end/ui/components/text_editor/TextEditor.ts +1 -3
  62. package/front_end/ui/legacy/Treeoutline.ts +5 -1
  63. package/front_end/ui/legacy/ViewRegistration.ts +2 -2
  64. package/front_end/ui/legacy/Widget.ts +9 -2
  65. package/front_end/ui/legacy/components/utils/Linkifier.ts +32 -11
  66. package/front_end/ui/visual_logging/KnownContextValues.ts +19 -0
  67. package/package.json +1 -1
  68. package/front_end/Images/src/dots-circle.svg +0 -10
  69. package/front_end/panels/elements/components/Helper.ts +0 -35
@@ -8,7 +8,6 @@ import * as i18n from '../../../core/i18n/i18n.js';
8
8
  import * as Platform from '../../../core/platform/platform.js';
9
9
  import * as Root from '../../../core/root/root.js';
10
10
  import * as SDK from '../../../core/sdk/sdk.js';
11
- import type * as Protocol from '../../../generated/protocol.js';
12
11
  import * as Tracing from '../../../services/tracing/tracing.js';
13
12
  import * as Annotations from '../../annotations/annotations.js';
14
13
  import * as Logs from '../../logs/logs.js';
@@ -62,11 +61,10 @@ export type MainThreadSectionLabel = 'nav-to-lcp'|'lcp-ttfb'|'lcp-render-delay'|
62
61
  * chrome_preambles.gcl). Sync local changes with the server-side.
63
62
  */
64
63
 
65
- const greenDevAdditionalAnnotationsFunction = `
64
+ const GREEN_DEV_ANNOTATIONS_INSTRUCTIONS = `
66
65
  - CRITICAL: You also have access to functions called addElementAnnotation and addNeworkRequestAnnotation,
67
- which should be used to highlight elements and network requests (respectively).`;
66
+ which should be used to highlight elements and network requests (respectively).
68
67
 
69
- const greenDevAdditionalAnnotationsGuidelines = `
70
68
  - CRITICAL: Each time an element or a network request is mentioned, you MUST ALSO call the functions
71
69
  addElementAnnotation (for an element) or addNeworkRequestAnnotation (for a network request).
72
70
  - CRITICAL: Don't add more than one annotation per element or network request.
@@ -75,6 +73,24 @@ const greenDevAdditionalAnnotationsGuidelines = `
75
73
  - The annotationMessage should be descriptive and relevant to why the element or network request is being highlighted.
76
74
  `;
77
75
 
76
+ const GREEN_DEV_FRESH_TRACE_ANNOTATIONS_INSTRUCTIONS = `
77
+ When referring to an element for which you know the nodeId, always call the function addElementAnnotation, specifying
78
+ the id and an annotation reason.
79
+ When referring to a network request for which you know the eventKey for, always call the function
80
+ addNetworkRequestAnnotation, specifying the id and an annotation reason.
81
+ - CRITICAL: Each time you add an annotating link you MUST ALSO call the function addElementAnnotation.
82
+ - CRITICAL: Each time you describe an element or network request as being problematic you MUST call the function
83
+ addElementAnnotation and specify an annotation reason.
84
+ - CRITICAL: Each time you describe a network request as being problematic you MUST call the function
85
+ addNetworkRequestAnnotation and specify an annotation reason.
86
+ - CRITICAL: If you spot ANY of the following problems:
87
+ - Render-blocking elements/network requests.
88
+ - Significant long task (especially on main thread).
89
+ - Layout shifts (e.g. due to unsized images).
90
+ ... then you MUST call addNetworkRequestAnnotation for ALL network requests and addaddElementAnnotation for all
91
+ elements described in your conclusion.
92
+ `;
93
+
78
94
  /**
79
95
  * Preamble clocks in at ~1341 tokens.
80
96
  * The prose is around 4.5 chars per token.
@@ -82,9 +98,7 @@ const greenDevAdditionalAnnotationsGuidelines = `
82
98
  *
83
99
  * Check token length in https://aistudio.google.com/
84
100
  */
85
- const buildPreamble = (): string => {
86
- const annotationsEnabled = Annotations.AnnotationRepository.annotationsEnabled();
87
- return `You are an assistant, expert in web performance and highly skilled with Chrome DevTools.
101
+ const preamble = `You are an assistant, expert in web performance and highly skilled with Chrome DevTools.
88
102
 
89
103
  Your primary goal is to provide actionable advice to web developers about their web page by using the Chrome Performance Panel and analyzing a trace. You may need to diagnose problems yourself, or you may be given direction for what to focus on by the user.
90
104
 
@@ -94,8 +108,6 @@ Always call getInsightDetails to gather more data on an insight or the actual LC
94
108
 
95
109
  You have functions available to learn more about the trace. Use these to confirm hypotheses, or to further explore the trace when diagnosing performance issues.
96
110
 
97
- ${annotationsEnabled ? greenDevAdditionalAnnotationsFunction : ''}
98
-
99
111
  You will be given bounds representing a time range within the trace. Bounds include a min and a max time in microseconds. max is always bigger than min in a bounds.
100
112
 
101
113
  The 3 main performance metrics are:
@@ -167,8 +179,6 @@ Note: if the user asks a specific question about the trace (such as "What is my
167
179
  - Structure your response using markdown headings and bullet points for improved readability.
168
180
  - Be direct and to the point. Avoid unnecessary introductory phrases or filler content. Focus on delivering actionable advice efficiently.
169
181
 
170
- ${annotationsEnabled ? greenDevAdditionalAnnotationsGuidelines : ''}
171
-
172
182
  ## Strict Constraints
173
183
 
174
184
  Adhere to the following critical requirements:
@@ -186,7 +196,6 @@ Adhere to the following critical requirements:
186
196
  - Do not provide answers on non-web-development topics, such as legal, financial, medical, or personal advice.
187
197
  - Use the precision of Strunk & White, the brevity of Hemingway, and the simple clarity of Vonnegut. Don't add repeated information, and keep the whole answer short.
188
198
  `;
189
- };
190
199
 
191
200
  const extraPreambleWhenNotExternal = `Additional notes:
192
201
 
@@ -198,38 +207,14 @@ When referring to a trace event that has a corresponding \`eventKey\`, annotate
198
207
  When asking the user to make a choice between options, output a list of choices at the end of your text response. The format is \`SUGGESTIONS: ["suggestion1", "suggestion2", "suggestion3"]\`. This MUST start on a newline, and be a single line.
199
208
  `;
200
209
 
201
- const buildExtraPreambleWhenFreshTrace = (): string => {
202
- const annotationsEnabled = Annotations.AnnotationRepository.annotationsEnabled();
203
- const greenDevAdditionalGuidelineFreshTrace = `
204
- When referring to an element for which you know the nodeId, always call the function addElementAnnotation, specifying
205
- the id and an annotation reason.
206
- When referring to a network request for which you know the eventKey for, always call the function
207
- addNetworkRequestAnnotation, specifying the id and an annotation reason.
208
- - CRITICAL: Each time you add an annotating link you MUST ALSO call the function addElementAnnotation.
209
- - CRITICAL: Each time you describe an element or network request as being problematic you MUST call the function
210
- addElementAnnotation and specify an annotation reason.
211
- - CRITICAL: Each time you describe a network request as being problematic you MUST call the function
212
- addNetworkRequestAnnotation and specify an annotation reason.
213
- - CRITICAL: If you spot ANY of the following problems:
214
- - Render-blocking elements/network requests.
215
- - Significant long task (especially on main thread).
216
- - Layout shifts (e.g. due to unsized images).
217
- ... then you MUST call addNetworkRequestAnnotation for ALL network requests and addaddElementAnnotation for all
218
- elements described in your conclusion.
219
- `;
220
-
221
- const extraPreambleWhenFreshTrace = `Additional notes:
210
+ const freshTracePreamble = `Additional notes:
222
211
 
223
212
  When referring to an element for which you know the nodeId, annotate your output using markdown link syntax:
224
213
  - For example, if nodeId is 23: [LCP element](#node-23)
225
214
  - This link will reveal the element in the Elements panel
226
215
  - Never mention node or nodeId when referring to the element, and especially not in the link text.
227
216
  - When referring to the LCP, it's useful to also mention what the LCP element is via its nodeId. Use the markdown link syntax to do so.
228
-
229
- ${annotationsEnabled ? greenDevAdditionalGuidelineFreshTrace : ''}`;
230
-
231
- return extraPreambleWhenFreshTrace;
232
- };
217
+ `;
233
218
 
234
219
  enum ScorePriority {
235
220
  REQUIRED = 3,
@@ -237,6 +222,12 @@ enum ScorePriority {
237
222
  DEFAULT = 1,
238
223
  }
239
224
 
225
+ // TODO(crbug.com/503296282): Remove this when we add support for all insights
226
+ const SUPPORTED_INSIGHT_WIDGETS = new Set<Trace.Insights.Types.InsightKeys>([
227
+ Trace.Insights.Types.InsightKeys.LCP_BREAKDOWN,
228
+ Trace.Insights.Types.InsightKeys.RENDER_BLOCKING,
229
+ ]);
230
+
240
231
  export class PerformanceTraceContext extends ConversationContext<AgentFocus> {
241
232
  static fromParsedTrace(parsedTrace: Trace.TraceModel.ParsedTrace): PerformanceTraceContext {
242
233
  return new PerformanceTraceContext(AgentFocus.fromParsedTrace(parsedTrace));
@@ -349,8 +340,8 @@ export class PerformanceTraceContext extends ConversationContext<AgentFocus> {
349
340
  const failingInsightSuggestions =
350
341
  Object.values(insightSet.model)
351
342
  .filter(model => {
352
- return model.state !== 'pass' &&
353
- !poorMetrics.has(model.insightKey as Trace.Insights.Types.InsightKeys);
343
+ return model.state !== 'pass' && Trace.Insights.Common.isInsightKey(model.insightKey) &&
344
+ !poorMetrics.has(model.insightKey);
354
345
  })
355
346
  .map(model => new PerformanceInsightFormatter(focus, model).getSuggestions().at(-1))
356
347
  .filter((suggestion): suggestion is ConversationSuggestion => !!suggestion)
@@ -406,6 +397,7 @@ export function getLabelName(label: MainThreadSectionLabel, focus: AgentFocus):
406
397
  * instance for a new conversation.
407
398
  */
408
399
  export class PerformanceAgent extends AiAgent<AgentFocus> {
400
+ readonly preamble = preamble;
409
401
  #formatter: PerformanceTraceFormatter|null = null;
410
402
  #lastEventForEnhancedQuery: Trace.Types.Events.Event|undefined;
411
403
  #lastInsightForEnhancedQuery: Trace.Insights.Types.InsightModel|undefined;
@@ -428,7 +420,15 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
428
420
  metadata: {source: 'devtools', score: ScorePriority.CRITICAL}
429
421
  };
430
422
  #freshTraceExtraPreambleFact: Host.AidaClient.RequestFact = {
431
- text: buildExtraPreambleWhenFreshTrace(),
423
+ text: freshTracePreamble,
424
+ metadata: {source: 'devtools', score: ScorePriority.CRITICAL}
425
+ };
426
+ #greenDevAnnotationsFact: Host.AidaClient.RequestFact = {
427
+ text: GREEN_DEV_ANNOTATIONS_INSTRUCTIONS,
428
+ metadata: {source: 'devtools', score: ScorePriority.CRITICAL}
429
+ };
430
+ #greenDevFreshTraceAnnotationsFact: Host.AidaClient.RequestFact = {
431
+ text: GREEN_DEV_FRESH_TRACE_ANNOTATIONS_INSTRUCTIONS,
432
432
  metadata: {source: 'devtools', score: ScorePriority.CRITICAL}
433
433
  };
434
434
  #networkDataDescriptionFact: Host.AidaClient.RequestFact = {
@@ -450,6 +450,8 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
450
450
  this.#networkDataDescriptionFact,
451
451
  this.#freshTraceExtraPreambleFact,
452
452
  this.#notExternalExtraPreambleFact,
453
+ this.#greenDevAnnotationsFact,
454
+ this.#greenDevFreshTraceAnnotationsFact,
453
455
  ]);
454
456
 
455
457
  /**
@@ -459,20 +461,6 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
459
461
  */
460
462
  #additionalSelectionsForQuery: string[] = [];
461
463
 
462
- /**
463
- * The CWV widget is shown when we analyze the trace summary, but we don't
464
- * want to show it on every single "Analyzing data..." pill, as we show one
465
- * after every prompt. So we make sure for a given Insight Set (which is based on navigation)
466
- * we only show it once.
467
- */
468
- #hasShownWidgetForInsightSet = new WeakSet<Trace.Insights.Types.InsightSet>();
469
- #hasShownWidgetForCallTree = new WeakSet<AICallTree>();
470
- #hasShownWidgetForInsight = new WeakSet<Trace.Insights.Types.InsightModel>();
471
-
472
- get preamble(): string {
473
- return buildPreamble();
474
- }
475
-
476
464
  get clientFeature(): Host.AidaClient.ClientFeature {
477
465
  return Host.AidaClient.ClientFeature.CHROME_PERFORMANCE_FULL_AGENT;
478
466
  }
@@ -531,48 +519,46 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
531
519
 
532
520
  // Case 1: Specific task (call tree) -> timeline summary & bottom up tree widgets
533
521
  if (focus.callTree) {
534
- if (!this.#hasShownWidgetForCallTree.has(focus.callTree)) {
535
- const event = focus.callTree.selectedNode?.event;
536
- if (event) {
537
- const {startTime, endTime} = Trace.Helpers.Timing.eventTimingsMicroSeconds(event);
538
- const bounds = Trace.Helpers.Timing.traceWindowFromMicroSeconds(startTime, endTime);
539
- widgets.push({
540
- name: 'TIMELINE_RANGE_SUMMARY',
541
- data: {
542
- bounds,
543
- parsedTrace: focus.parsedTrace,
544
- track: 'main',
545
- },
546
- });
547
- widgets.push({
548
- name: 'BOTTOM_UP_TREE',
549
- data: {
550
- bounds,
551
- parsedTrace: focus.parsedTrace,
552
- },
553
- });
554
- this.#hasShownWidgetForCallTree.add(focus.callTree);
555
- }
522
+ const event = focus.callTree.selectedNode?.event;
523
+ if (event) {
524
+ const {startTime, endTime} = Trace.Helpers.Timing.eventTimingsMicroSeconds(event);
525
+ const bounds = Trace.Helpers.Timing.traceWindowFromMicroSeconds(startTime, endTime);
526
+ widgets.push({
527
+ name: 'TIMELINE_RANGE_SUMMARY',
528
+ data: {
529
+ bounds,
530
+ parsedTrace: focus.parsedTrace,
531
+ track: 'main',
532
+ },
533
+ });
534
+ widgets.push({
535
+ name: 'BOTTOM_UP_TREE',
536
+ data: {
537
+ bounds,
538
+ parsedTrace: focus.parsedTrace,
539
+ },
540
+ });
556
541
  }
557
542
  return widgets;
558
543
  }
559
544
 
560
- // Case 2: LCP Insight -> LCP breakdown & CWV widgets
561
- if (focus.insight && Trace.Insights.Models.LCPBreakdown.isLCPBreakdownInsight(focus.insight) &&
562
- !this.#hasShownWidgetForInsight.has(focus.insight)) {
563
- widgets.push({
564
- name: 'PERF_INSIGHT',
565
- data: {
566
- insight: 'lcp',
567
- insightData: focus.insight,
568
- },
569
- });
570
- this.#hasShownWidgetForInsight.add(focus.insight);
545
+ // Case 2: Insight -> PERF_INSIGHT widget
546
+ if (focus.insight) {
547
+ const insightKey = focus.insight.insightKey;
548
+ if (Trace.Insights.Common.isInsightKey(insightKey) && SUPPORTED_INSIGHT_WIDGETS.has(insightKey)) {
549
+ widgets.push({
550
+ name: 'PERF_INSIGHT',
551
+ data: {
552
+ insight: insightKey,
553
+ insightData: focus.insight,
554
+ },
555
+ });
556
+ }
571
557
  }
572
558
 
573
559
  // Case 3: Whole Trace or insight other than LCP -> CWV widget
574
560
  const primaryInsightSet = focus.primaryInsightSet;
575
- if (primaryInsightSet && !this.#hasShownWidgetForInsightSet.has(primaryInsightSet)) {
561
+ if (primaryInsightSet) {
576
562
  widgets.push({
577
563
  name: 'CORE_VITALS',
578
564
  data: {
@@ -580,7 +566,6 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
580
566
  insightSetKey: primaryInsightSet.id,
581
567
  },
582
568
  });
583
- this.#hasShownWidgetForInsightSet.add(primaryInsightSet);
584
569
  }
585
570
 
586
571
  return widgets;
@@ -833,9 +818,17 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
833
818
  this.addFact(this.#notExternalExtraPreambleFact);
834
819
  }
835
820
 
821
+ const annotationsEnabled = Annotations.AnnotationRepository.annotationsEnabled();
822
+ if (annotationsEnabled) {
823
+ this.addFact(this.#greenDevAnnotationsFact);
824
+ }
825
+
836
826
  const isFresh = Tracing.FreshRecording.Tracker.instance().recordingIsFresh(focus.parsedTrace);
837
827
  if (isFresh) {
838
828
  this.addFact(this.#freshTraceExtraPreambleFact);
829
+ if (annotationsEnabled) {
830
+ this.addFact(this.#greenDevFreshTraceAnnotationsFact);
831
+ }
839
832
  }
840
833
 
841
834
  this.addFact(this.#callFrameDataDescriptionFact);
@@ -935,7 +928,6 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
935
928
  #declareFunctions(context: PerformanceTraceContext): void {
936
929
  const focus = context.getItem();
937
930
  const {parsedTrace} = focus;
938
- const processedNodeIds = new Set<Protocol.DOM.BackendNodeId>();
939
931
 
940
932
  this.declareFunction<{insightSetId: string, insightName: string}, {details: string}>('getInsightDetails', {
941
933
  description:
@@ -992,9 +984,7 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
992
984
  const lcpEvent = lcpMetric?.event;
993
985
  if (lcpEvent && Trace.Types.Events.isAnyLargestContentfulPaintCandidate(lcpEvent)) {
994
986
  const nodeId = lcpEvent.args.data?.nodeId;
995
- // We want to show only one DOM tree widget per walkthrough per node.
996
- // We do want to show the widget for the same node again, if it's within a new walkthrough.
997
- if (nodeId && !processedNodeIds.has(nodeId)) {
987
+ if (nodeId) {
998
988
  const target = SDK.TargetManager.TargetManager.instance().primaryPageTarget();
999
989
  const domModel = target?.model(SDK.DOMModel.DOMModel);
1000
990
  if (domModel) {
@@ -1021,20 +1011,21 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
1021
1011
  networkRequest,
1022
1012
  },
1023
1013
  });
1024
- processedNodeIds.add(nodeId);
1025
1014
  }
1026
1015
  }
1027
1016
  }
1028
1017
  }
1029
- if (params.insightName === 'LCPBreakdown') {
1030
- widgets.push({
1031
- name: 'PERF_INSIGHT',
1032
- data: {
1033
- insight: 'lcp',
1034
- insightData: insight as Trace.Insights.Types.InsightModel,
1035
- },
1036
- });
1037
- }
1018
+ }
1019
+
1020
+ const insightKey = params.insightName;
1021
+ if (Trace.Insights.Common.isInsightKey(insightKey) && SUPPORTED_INSIGHT_WIDGETS.has(insightKey)) {
1022
+ widgets.push({
1023
+ name: 'PERF_INSIGHT',
1024
+ data: {
1025
+ insight: insightKey,
1026
+ insightData: insight as Trace.Insights.Types.InsightModel,
1027
+ },
1028
+ });
1038
1029
  }
1039
1030
 
1040
1031
  const key = `getInsightDetails('${params.insightSetId}', '${params.insightName}')`;
@@ -47,14 +47,7 @@ const UIStringsNotTranslate = {
47
47
 
48
48
  const lockedString = i18n.i18n.lockedString;
49
49
 
50
- function getPreamble(): string {
51
- /**
52
- * WARNING: preamble defined in code is only used when userTier is
53
- * TESTERS. Otherwise, a server-side preamble is used (see
54
- * chrome_preambles.gcl). Sync local changes with the server-side.
55
- */
56
- /* clang-format off */
57
- let preamble = `You are the most advanced CSS/DOM/HTML debugging assistant integrated into Chrome DevTools.
50
+ const preamble = `You are the most advanced CSS/DOM/HTML debugging assistant integrated into Chrome DevTools.
58
51
  You always suggest considering the best web development practices and the newest platform features such as view transitions.
59
52
  The user selected a DOM element in the browser's DevTools and sends a query about the page or the selected DOM element.
60
53
  First, examine the provided context, then use the functions to gather additional context and resolve the user request.
@@ -92,9 +85,7 @@ If the user asks a question that requires an investigation of a problem, use thi
92
85
  - [Suggestion 1]
93
86
  - [Suggestion 2]`;
94
87
 
95
- const greenDevEmulationEnabled = Greendev.Prototypes.instance().isEnabled('emulationCapabilities');
96
- if (greenDevEmulationEnabled) {
97
- preamble += `
88
+ const emulationInstructions = `
98
89
  # Emulation and Screenshots
99
90
 
100
91
  * If asked to verify whether the page is visually broken or if there are display problems with specific devices, use the \`activateDeviceEmulation\` tool. This tool will activate emulation for a specified device and capture a screenshot.
@@ -127,10 +118,6 @@ When referring to an element for which you know the nodeId, annotate your output
127
118
  - Always prefix the nodeId with the 'node-' prefix when using the markdown syntax.
128
119
  - This link will reveal the element in the Elements panel
129
120
  - Never mention node or nodeId when referring to the element, and especially not in the link text.`;
130
- }
131
-
132
- return preamble;
133
- }
134
121
 
135
122
  /* clang-format on */
136
123
 
@@ -242,7 +229,7 @@ export class NodeContext extends ConversationContext<SDK.DOMModel.DOMNode> {
242
229
  * instance for a new conversation.
243
230
  */
244
231
  export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
245
- preamble = getPreamble();
232
+ readonly preamble = preamble;
246
233
  readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_STYLING_AGENT;
247
234
  get userTier(): string|undefined {
248
235
  const greenDevEmulationEnabled = Greendev.Prototypes.instance().isEnabled('emulationCapabilities');
@@ -278,6 +265,7 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
278
265
  #createExtensionScope: CreateExtensionScopeFunction;
279
266
  #greenDevEmulationScreenshot: string|null = null;
280
267
  #greenDevEmulationAxTree: string|null = null;
268
+ #hasAddedEmulationInstructions = false;
281
269
  #currentTurnId = 0;
282
270
 
283
271
  constructor(opts: ExecuteJsAgentOptions) {
@@ -821,6 +809,11 @@ export class StylingAgent extends AiAgent<SDK.DOMModel.DOMNode> {
821
809
  this.#greenDevEmulationAxTree = null;
822
810
  }
823
811
 
812
+ if (Greendev.Prototypes.instance().isEnabled('emulationCapabilities') && !this.#hasAddedEmulationInstructions) {
813
+ multimodalInputEnhancementQuery = emulationInstructions + '\n' + multimodalInputEnhancementQuery;
814
+ this.#hasAddedEmulationInstructions = true;
815
+ }
816
+
824
817
  const elementEnchancementQuery = selectedElement ?
825
818
  `# Inspected element\n\n${
826
819
  await StylingAgent.describeElement(selectedElement.getItem())}\n\n# User request\n\n` :
@@ -9,6 +9,7 @@ import * as BreakpointDebuggerAgent from './agents/BreakpointDebuggerAgent.js';
9
9
  import * as ContextSelectionAgent from './agents/ContextSelectionAgent.js';
10
10
  import * as ConversationSummaryAgent from './agents/ConversationSummaryAgent.js';
11
11
  import * as FileAgent from './agents/FileAgent.js';
12
+ import * as GreenDevAgent from './agents/GreenDevAgent.js';
12
13
  import * as NetworkAgent from './agents/NetworkAgent.js';
13
14
  import * as PatchAgent from './agents/PatchAgent.js';
14
15
  import * as PerformanceAgent from './agents/PerformanceAgent.js';
@@ -53,6 +54,7 @@ export {
53
54
  ExtensionScope,
54
55
  FileAgent,
55
56
  FileFormatter,
57
+ GreenDevAgent,
56
58
  Injected,
57
59
  LighthouseFormatter,
58
60
  NetworkAgent,
@@ -7,7 +7,7 @@ import * as Platform from '../../core/platform/platform.js';
7
7
  import * as Root from '../../core/root/root.js';
8
8
  import * as SDK from '../../core/sdk/sdk.js';
9
9
  import * as Protocol from '../../generated/protocol.js';
10
- import type * as StackTrace from '../stack_trace/stack_trace.js';
10
+ import * as StackTrace from '../stack_trace/stack_trace.js';
11
11
  // eslint-disable-next-line @devtools/es-modules-import
12
12
  import * as StackTraceImpl from '../stack_trace/stack_trace_impl.js';
13
13
  import type * as TextUtils from '../text_utils/text_utils.js';
@@ -20,7 +20,13 @@ import {type LiveLocation, type LiveLocationPool, LiveLocationWithPool} from './
20
20
  import {NetworkProject} from './NetworkProject.js';
21
21
  import type {ResourceMapping} from './ResourceMapping.js';
22
22
  import {type ResourceScriptFile, ResourceScriptMapping} from './ResourceScriptMapping.js';
23
- import {SymbolizedError} from './SymbolizedError.js';
23
+ import {
24
+ isErrorLike,
25
+ type SymbolizedError,
26
+ SymbolizedErrorObject,
27
+ SymbolizedSyntaxError,
28
+ UnparsableError,
29
+ } from './SymbolizedError.js';
24
30
 
25
31
  export class DebuggerWorkspaceBinding implements SDK.TargetManager.SDKModelObserver<SDK.DebuggerModel.DebuggerModel> {
26
32
  readonly resourceMapping: ResourceMapping;
@@ -233,8 +239,18 @@ export class DebuggerWorkspaceBinding implements SDK.TargetManager.SDKModelObser
233
239
  fetchedExceptionDetails = details;
234
240
  causeRemoteObject = causeRemote;
235
241
 
242
+ if (remoteObject.className === 'SyntaxError' && fetchedExceptionDetails) {
243
+ const syntaxError = await SymbolizedSyntaxError.fromExceptionDetails(
244
+ remoteObject.runtimeModel().target(), this, fetchedExceptionDetails);
245
+ if (syntaxError) {
246
+ return syntaxError;
247
+ }
248
+ }
236
249
  } else if (remoteObject.type === 'string') {
237
250
  errorStack = remoteObject.description || '';
251
+ if (!isErrorLike(errorStack)) {
252
+ return null;
253
+ }
238
254
  } else {
239
255
  return null;
240
256
  }
@@ -245,12 +261,17 @@ export class DebuggerWorkspaceBinding implements SDK.TargetManager.SDKModelObser
245
261
  causeRemoteObject ? this.createSymbolizedError(causeRemoteObject) : Promise.resolve(null),
246
262
  ]);
247
263
 
264
+ const issueSummary = fetchedExceptionDetails?.exceptionMetaData?.issueSummary;
265
+ if (typeof issueSummary === 'string') {
266
+ errorStack = StackTrace.ErrorStackParser.concatErrorDescriptionAndIssueSummary(errorStack, issueSummary);
267
+ }
268
+
248
269
  if (!stackTrace) {
249
- return null;
270
+ return new UnparsableError(errorStack, cause);
250
271
  }
251
272
 
252
273
  const message = StackTraceImpl.DetailedErrorStackParser.parseMessage(errorStack);
253
- return new SymbolizedError(message, stackTrace, cause);
274
+ return new SymbolizedErrorObject(message, stackTrace, cause);
254
275
  }
255
276
 
256
277
  async createLiveLocation(
@@ -3,9 +3,45 @@
3
3
  // found in the LICENSE file.
4
4
 
5
5
  import * as Common from '../../core/common/common.js';
6
+ import * as SDK from '../../core/sdk/sdk.js';
7
+ import type * as Protocol from '../../generated/protocol.js';
6
8
  import * as StackTrace from '../stack_trace/stack_trace.js';
9
+ import type * as Workspace from '../workspace/workspace.js';
7
10
 
8
- export class SymbolizedError extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
11
+ import type {DebuggerWorkspaceBinding} from './DebuggerWorkspaceBinding.js';
12
+ import {type LiveLocation, LiveLocationPool} from './LiveLocation.js';
13
+
14
+ export function isErrorLike(stack: string): boolean {
15
+ return /\n\s*at\s/.test(stack) || stack.startsWith('SyntaxError:');
16
+ }
17
+
18
+ export type SymbolizedError = SymbolizedErrorObject|SymbolizedSyntaxError|UnparsableError;
19
+
20
+ export class UnparsableError extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
21
+ readonly errorStack: string;
22
+ readonly cause: SymbolizedError|null;
23
+
24
+ constructor(errorStack: string, cause: SymbolizedError|null) {
25
+ super();
26
+ this.errorStack = errorStack;
27
+ this.cause = cause;
28
+
29
+ this.cause?.addEventListener(Events.UPDATED, this.#fireUpdated, this);
30
+ }
31
+
32
+ dispose(): void {
33
+ this.cause?.removeEventListener(Events.UPDATED, this.#fireUpdated, this);
34
+ if (this.cause instanceof SymbolizedErrorObject || this.cause instanceof UnparsableError) {
35
+ this.cause.dispose();
36
+ }
37
+ }
38
+
39
+ #fireUpdated(): void {
40
+ this.dispatchEventToListeners(Events.UPDATED);
41
+ }
42
+ }
43
+
44
+ export class SymbolizedErrorObject extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
9
45
  readonly message: string;
10
46
  readonly stackTrace: StackTrace.StackTrace.ParsedErrorStackTrace;
11
47
  readonly cause: SymbolizedError|null;
@@ -23,7 +59,9 @@ export class SymbolizedError extends Common.ObjectWrapper.ObjectWrapper<EventTyp
23
59
  dispose(): void {
24
60
  this.stackTrace.removeEventListener(StackTrace.StackTrace.Events.UPDATED, this.#fireUpdated, this);
25
61
  this.cause?.removeEventListener(Events.UPDATED, this.#fireUpdated, this);
26
- this.cause?.dispose();
62
+ if (this.cause instanceof SymbolizedErrorObject || this.cause instanceof UnparsableError) {
63
+ this.cause.dispose();
64
+ }
27
65
  }
28
66
 
29
67
  #fireUpdated(): void {
@@ -31,6 +69,52 @@ export class SymbolizedError extends Common.ObjectWrapper.ObjectWrapper<EventTyp
31
69
  }
32
70
  }
33
71
 
72
+ export class SymbolizedSyntaxError extends Common.ObjectWrapper.ObjectWrapper<EventTypes> {
73
+ readonly message: string;
74
+ #uiLocation: Workspace.UISourceCode.UILocation|null = null;
75
+
76
+ constructor(message: string) {
77
+ super();
78
+ this.message = message;
79
+ }
80
+
81
+ get uiLocation(): Workspace.UISourceCode.UILocation|null {
82
+ return this.#uiLocation;
83
+ }
84
+
85
+ static async fromExceptionDetails(
86
+ target: SDK.Target.Target, debuggerWorkspaceBinding: DebuggerWorkspaceBinding,
87
+ exceptionDetails: Protocol.Runtime.ExceptionDetails): Promise<SymbolizedSyntaxError|null> {
88
+ const {exception, scriptId, lineNumber, columnNumber} = exceptionDetails;
89
+ if (!exception || exception.subtype !== 'error' || exception.className !== 'SyntaxError') {
90
+ throw new Error('SymbolizedSyntaxError.fromExceptionDetails expects a SyntaxError');
91
+ }
92
+ if (!scriptId) {
93
+ return null;
94
+ }
95
+
96
+ const debuggerModel = target.model(SDK.DebuggerModel.DebuggerModel);
97
+ if (!debuggerModel) {
98
+ return null;
99
+ }
100
+
101
+ const rawLocation = debuggerModel.createRawLocationByScriptId(scriptId, lineNumber, columnNumber);
102
+ const symbolizedSyntaxError = new SymbolizedSyntaxError(exception.description || '');
103
+
104
+ // We don't implement dispose here. We won't create many of these so a couple
105
+ // LiveLocationPools and SymbolizedSyntaxError instances leaking is fine.
106
+ await debuggerWorkspaceBinding.createLiveLocation(
107
+ rawLocation, symbolizedSyntaxError.#update.bind(symbolizedSyntaxError), new LiveLocationPool());
108
+
109
+ return symbolizedSyntaxError;
110
+ }
111
+
112
+ async #update(liveLocation: LiveLocation): Promise<void> {
113
+ this.#uiLocation = await liveLocation.uiLocation();
114
+ this.dispatchEventToListeners(Events.UPDATED);
115
+ }
116
+ }
117
+
34
118
  export const enum Events {
35
119
  UPDATED = 'UPDATED',
36
120
  }