chrome-devtools-frontend 1.0.1638082 → 1.0.1640418

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 (105) hide show
  1. package/front_end/core/host/AidaClientTypes.ts +8 -6
  2. package/front_end/core/sdk/DOMStorageModel.ts +1 -1
  3. package/front_end/core/sdk/TargetManager.ts +14 -1
  4. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +147 -0
  5. package/front_end/generated/ARIAProperties.js +0 -4
  6. package/front_end/generated/InspectorBackendCommands.ts +7 -3
  7. package/front_end/generated/protocol-mapping.d.ts +7 -0
  8. package/front_end/generated/protocol-proxy-api.d.ts +14 -0
  9. package/front_end/generated/protocol.ts +80 -0
  10. package/front_end/global_typings/global_defs.d.ts +13 -0
  11. package/front_end/models/ai_assistance/AiAgent2.ts +116 -0
  12. package/front_end/models/ai_assistance/AiConversation.ts +22 -28
  13. package/front_end/models/ai_assistance/AiOrigins.ts +46 -0
  14. package/front_end/models/ai_assistance/README.md +16 -0
  15. package/front_end/models/ai_assistance/StorageItem.ts +30 -26
  16. package/front_end/models/ai_assistance/agents/AccessibilityAgent.ts +2 -2
  17. package/front_end/models/ai_assistance/agents/AiAgent.ts +73 -36
  18. package/front_end/models/ai_assistance/agents/ContextSelectionAgent.snapshot.txt +2 -2
  19. package/front_end/models/ai_assistance/agents/ContextSelectionAgent.ts +25 -10
  20. package/front_end/models/ai_assistance/agents/ConversationSummaryAgent.ts +1 -1
  21. package/front_end/models/ai_assistance/agents/FileAgent.ts +2 -2
  22. package/front_end/models/ai_assistance/agents/GreenDevAgent.ts +1 -1
  23. package/front_end/models/ai_assistance/agents/NetworkAgent.ts +3 -4
  24. package/front_end/models/ai_assistance/agents/PerformanceAgent.snapshot.txt +2 -2
  25. package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +41 -12
  26. package/front_end/models/ai_assistance/agents/StorageAgent.ts +442 -122
  27. package/front_end/models/ai_assistance/agents/StylingAgent.ts +2 -2
  28. package/front_end/models/ai_assistance/ai_assistance.ts +4 -0
  29. package/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.snapshot.txt +2 -2
  30. package/front_end/models/ai_assistance/performance/AIContext.ts +7 -8
  31. package/front_end/models/ai_assistance/skills/README.md +40 -0
  32. package/front_end/models/ai_assistance/skills/Skill.ts +13 -0
  33. package/front_end/models/ai_assistance/skills/SkillRegistry.ts +10 -0
  34. package/front_end/models/ai_assistance/skills/styling.md +6 -0
  35. package/front_end/models/heap_snapshot/HeapSnapshotModel.ts +20 -0
  36. package/front_end/models/heap_snapshot/HeapSnapshotProxy.ts +5 -0
  37. package/front_end/models/javascript_metadata/NativeFunctions.js +6 -2
  38. package/front_end/models/live-metrics/web-vitals-injected/web-vitals-injected.ts +1 -1
  39. package/front_end/models/stack_trace/StackTraceImpl.ts +29 -9
  40. package/front_end/models/stack_trace/StackTraceModel.ts +23 -11
  41. package/front_end/models/stack_trace/Trie.ts +11 -1
  42. package/front_end/models/trace/extras/TraceTree.ts +20 -1
  43. package/front_end/models/trace/insights/Common.ts +9 -0
  44. package/front_end/panels/ai_assistance/AiAssistancePanel.ts +8 -0
  45. package/front_end/panels/ai_assistance/components/ChatMessage.ts +114 -2
  46. package/front_end/panels/ai_assistance/components/PerformanceAgentMarkdownRenderer.ts +2 -3
  47. package/front_end/panels/ai_assistance/components/chatMessage.css +27 -0
  48. package/front_end/panels/application/CookieItemsView.ts +24 -0
  49. package/front_end/panels/application/DOMStorageItemsView.ts +9 -4
  50. package/front_end/panels/application/preloading/components/PreloadingString.ts +6 -0
  51. package/front_end/panels/console/ConsoleViewMessage.ts +13 -12
  52. package/front_end/panels/elements/StandaloneStylesContainer.ts +10 -0
  53. package/front_end/panels/elements/StylePropertyTreeElement.ts +30 -1
  54. package/front_end/panels/elements/StylesContainer.ts +3 -0
  55. package/front_end/panels/elements/StylesSidebarPane.ts +45 -4
  56. package/front_end/panels/layer_viewer/layerDetailsView.css +1 -1
  57. package/front_end/panels/lighthouse/LighthouseController.ts +1 -1
  58. package/front_end/panels/lighthouse/LighthouseProtocolService.ts +4 -4
  59. package/front_end/panels/network/NetworkDataGridNode.ts +14 -0
  60. package/front_end/panels/network/NetworkLogViewColumns.ts +2 -2
  61. package/front_end/panels/network/networkTimingTable.css +2 -4
  62. package/front_end/panels/sources/ScopeChainSidebarPane.ts +169 -106
  63. package/front_end/panels/timeline/components/IgnoreListSetting.ts +1 -0
  64. package/front_end/third_party/chromium/README.chromium +1 -1
  65. package/front_end/third_party/marked/README.chromium +3 -6
  66. package/front_end/third_party/marked/package/README.md +5 -5
  67. package/front_end/third_party/marked/package/bin/main.js +27 -22
  68. package/front_end/third_party/marked/package/bin/marked.js +2 -1
  69. package/front_end/third_party/marked/package/lib/marked.esm.d.ts +346 -256
  70. package/front_end/third_party/marked/package/lib/marked.esm.js +67 -2698
  71. package/front_end/third_party/marked/package/lib/marked.esm.js.map +7 -1
  72. package/front_end/third_party/marked/package/lib/marked.umd.js +69 -2722
  73. package/front_end/third_party/marked/package/lib/marked.umd.js.map +7 -1
  74. package/front_end/third_party/marked/package/man/marked.1 +4 -2
  75. package/front_end/third_party/marked/package/man/marked.1.md +2 -1
  76. package/front_end/third_party/marked/package/package.json +49 -57
  77. package/front_end/tsconfig.json +1 -1
  78. package/front_end/ui/components/markdown_view/CodeBlock.ts +17 -6
  79. package/front_end/ui/components/markdown_view/MarkdownView.ts +39 -3
  80. package/front_end/ui/components/markdown_view/codeBlock.css +11 -0
  81. package/front_end/ui/components/markdown_view/markdownView.css +17 -0
  82. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +0 -79
  83. package/front_end/ui/legacy/components/object_ui/RemoteObjectPreviewFormatter.ts +16 -4
  84. package/front_end/ui/visual_logging/KnownContextValues.ts +2 -0
  85. package/inspector_overlay/testing/InspectorOverlayHelpers.ts +2 -0
  86. package/mcp/mcp.ts +1 -1
  87. package/package.json +7 -9
  88. package/front_end/third_party/marked/package/bin/marked +0 -215
  89. package/front_end/third_party/marked/package/lib/marked.cjs +0 -2726
  90. package/front_end/third_party/marked/package/lib/marked.cjs.map +0 -1
  91. package/front_end/third_party/marked/package/lib/marked.d.cts +0 -670
  92. package/front_end/third_party/marked/package/lib/marked.js +0 -2780
  93. package/front_end/third_party/marked/package/man/marked.1.txt +0 -86
  94. package/front_end/third_party/marked/package/marked.min.js +0 -6
  95. package/front_end/third_party/marked/package/src/Lexer.js +0 -492
  96. package/front_end/third_party/marked/package/src/Parser.js +0 -286
  97. package/front_end/third_party/marked/package/src/Renderer.js +0 -166
  98. package/front_end/third_party/marked/package/src/Slugger.js +0 -49
  99. package/front_end/third_party/marked/package/src/TextRenderer.js +0 -42
  100. package/front_end/third_party/marked/package/src/Tokenizer.js +0 -755
  101. package/front_end/third_party/marked/package/src/defaults.js +0 -29
  102. package/front_end/third_party/marked/package/src/helpers.js +0 -249
  103. package/front_end/third_party/marked/package/src/marked.js +0 -350
  104. package/front_end/third_party/marked/package/src/rules.js +0 -285
  105. /package/front_end/third_party/marked/package/{LICENSE.md → LICENSE} +0 -0
@@ -160,13 +160,13 @@ export class NodeContext extends ConversationContext<SDK.DOMModel.DOMNode> {
160
160
  this.#node = node;
161
161
  }
162
162
 
163
- getOrigin(): string {
163
+ override getURL(): string {
164
164
  const ownerDocument = this.#node.ownerDocument;
165
165
  if (!ownerDocument) {
166
166
  // The node is detached from a document.
167
167
  return 'detached';
168
168
  }
169
- return new URL(ownerDocument.documentURL).origin;
169
+ return ownerDocument.documentURL;
170
170
  }
171
171
 
172
172
  getItem(): SDK.DOMModel.DOMNode {
@@ -17,8 +17,10 @@ import * as PerformanceAgent from './agents/PerformanceAgent.js';
17
17
  import * as PerformanceAnnotationsAgent from './agents/PerformanceAnnotationsAgent.js';
18
18
  import * as StorageAgent from './agents/StorageAgent.js';
19
19
  import * as StylingAgent from './agents/StylingAgent.js';
20
+ import * as AiAgent2 from './AiAgent2.js';
20
21
  import * as AiConversation from './AiConversation.js';
21
22
  import * as AiHistoryStorage from './AiHistoryStorage.js';
23
+ import * as AiOrigins from './AiOrigins.js';
22
24
  import * as AiUtils from './AiUtils.js';
23
25
  import * as BuiltInAi from './BuiltInAi.js';
24
26
  import * as ChangeManager from './ChangeManager.js';
@@ -41,10 +43,12 @@ export {
41
43
  AccessibilityAgent,
42
44
  AgentProject,
43
45
  AiAgent,
46
+ AiAgent2,
44
47
  AICallTree,
45
48
  AIContext,
46
49
  AiConversation,
47
50
  AiHistoryStorage,
51
+ AiOrigins,
48
52
  AIQueries,
49
53
  AiUtils,
50
54
  BuiltInAi,
@@ -376,7 +376,7 @@ This is the bottom-up summary for the entire trace. Only the top 20 activities (
376
376
 
377
377
  # Third parties
378
378
 
379
- - name: Yahoo!, main thread time: 214 ms, network transfer size: 2.4 MB
379
+ - name: Yahoo!, main thread time: 214 ms, network transfer size: 1.6 MB
380
380
  - name: Taboola, main thread time: 41 ms, network transfer size: 391.7 kB
381
381
  - name: Google/Doubleclick Ads, main thread time: 41 ms, network transfer size: 225.7 kB
382
382
  - name: Google Tag Manager, main thread time: 19 ms, network transfer size: 123.8 kB
@@ -932,7 +932,7 @@ Title: PerformanceTraceFormatter formatThirdPartySummary yahoo-news.json.gz
932
932
  Content:
933
933
  # 3rd party summary
934
934
 
935
- - name: Yahoo!, main thread time: 270 ms, network transfer size: 2.4 MB
935
+ - name: Yahoo!, main thread time: 270 ms, network transfer size: 1.6 MB
936
936
  - name: Google/Doubleclick Ads, main thread time: 53 ms, network transfer size: 258.6 kB
937
937
  - name: Taboola, main thread time: 43 ms, network transfer size: 393.6 kB
938
938
  - name: Google Tag Manager, main thread time: 19 ms, network transfer size: 123.8 kB
@@ -124,15 +124,14 @@ export class AgentFocus {
124
124
  return focus;
125
125
  }
126
126
 
127
- lookupEvent(key: Trace.Types.File.SerializableKey): Trace.Types.Events.Event|null {
127
+ lookupEvent(key: string): Trace.Types.Events.Event|null {
128
128
  try {
129
- return this.eventsSerializer.eventForKey(key, this.#data.parsedTrace);
130
- } catch (err) {
131
- if (err.toString().includes('Unknown trace event') || err.toString().includes('Unknown profile call')) {
132
- return null;
133
- }
134
-
135
- throw err;
129
+ return this.eventsSerializer.eventForKey(key as Trace.Types.File.SerializableKey, this.#data.parsedTrace) ?? null;
130
+ } catch {
131
+ // We must silence all lookup and serialization errors here. Otherwise,
132
+ // any malformed link or invalid event key in the LLM response will throw
133
+ // an unhandled exception, breaking the panel's markdown rendering entirely.
134
+ return null;
136
135
  }
137
136
  }
138
137
 
@@ -0,0 +1,40 @@
1
+ # AI Assistant Skills
2
+
3
+ This directory contains the definitions for skills used by `AiAgent2`.
4
+
5
+ ## Authoring Skills
6
+
7
+ Skills are authored as Markdown files with YAML frontmatter.
8
+
9
+ Example:
10
+ ```markdown
11
+ ---
12
+ name: styling
13
+ allowed-tools: [search_web]
14
+ ---
15
+ You are a CSS expert...
16
+ ```
17
+
18
+ * **Frontmatter**: Contains metadata like `name` and `allowed-tools`.
19
+ * **Body**: The instructions for the skill (prompt).
20
+
21
+ ### Why Markdown?
22
+
23
+ Skills are stored as Markdown to make it easier to share them with other codebases or systems that might not be using TypeScript or the DevTools build system. This is an intentional trade-off that requires a build step for DevTools.
24
+
25
+ ## Build System
26
+
27
+ Markdown files are converted to JavaScript files (`.skill.js`) during the build process.
28
+
29
+ * **Script**: `scripts/build/build_ai_skills.mjs` processes each file individually.
30
+ * **GN Target**: `action_foreach("generate_skills")` in `front_end/models/ai_assistance/skills/BUILD.gn`.
31
+ * **Output**: Files are placed in the generation directory, e.g., `out/Default/gen/front_end/models/ai_assistance/skills/styling.skill.js`.
32
+
33
+ ## Consumption
34
+
35
+ To use a skill in TypeScript:
36
+
37
+ 1. Import it: `import {skill} from './styling.skill.js';`
38
+ 2. Register it in `SkillRegistry.ts`.
39
+
40
+ Types are provided globally in `front_end/global_typings/global_defs.d.ts` via a wildcard module declaration (`*.skill.js`). This avoids the need to generate `tsconfig.json` files for the generated skills.
@@ -0,0 +1,13 @@
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
+ // This will become a union type as we add more skills (e.g. 'styling' | 'network').
6
+ export type SkillName = 'styling';
7
+
8
+ export interface Skill {
9
+ name: SkillName;
10
+ description: string;
11
+ allowedTools: string[];
12
+ instructions: string;
13
+ }
@@ -0,0 +1,10 @@
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 type {Skill, SkillName} from './Skill.js';
6
+ import {skill as stylingSkill} from './styling.skill.js';
7
+
8
+ export const SKILLS: Record<SkillName, Skill> = {
9
+ styling: stylingSkill,
10
+ };
@@ -0,0 +1,6 @@
1
+ ---
2
+ name: styling
3
+ description: Helping with CSS and styling
4
+ allowed-tools: []
5
+ ---
6
+ You are a CSS expert helping the user style elements.
@@ -267,3 +267,23 @@ export class Location {
267
267
  this.columnNumber = columnNumber;
268
268
  }
269
269
  }
270
+
271
+ export interface RetainingEdge {
272
+ edgeIndex: number;
273
+ edgeName: string;
274
+ edgeType: string;
275
+ nodeId: number;
276
+ nodeIndex: number;
277
+ nodeName: string;
278
+ distance: number;
279
+ children: RetainingEdge[];
280
+ }
281
+
282
+ export interface RetainingPaths {
283
+ paths: RetainingEdge[];
284
+ limitsReached: {
285
+ depth?: boolean,
286
+ nodes?: boolean,
287
+ siblings?: boolean,
288
+ };
289
+ }
@@ -363,6 +363,11 @@ export class HeapSnapshotProxy extends HeapSnapshotProxyObject {
363
363
  return this.callMethodPromise('ignoreNodeInRetainersView', nodeIndex);
364
364
  }
365
365
 
366
+ getRetainingPaths(nodeIndex: number, maxDepth?: number, maxNodes?: number, maxSiblings?: number):
367
+ Promise<HeapSnapshotModel.RetainingPaths> {
368
+ return this.callMethodPromise('getRetainingPaths', nodeIndex, maxDepth, maxNodes, maxSiblings);
369
+ }
370
+
366
371
  unignoreNodeInRetainersView(nodeIndex: number): Promise<void> {
367
372
  return this.callMethodPromise('unignoreNodeInRetainersView', nodeIndex);
368
373
  }
@@ -6687,7 +6687,7 @@ export const NativeFunctions = [
6687
6687
  },
6688
6688
  {
6689
6689
  name: "copyElementImageToTexture",
6690
- signatures: [["source","destination"],["source","width","height","destination"],["source","sx","sy","swidth","sheight","destination"],["source","sx","sy","swidth","sheight","width","height","destination"]]
6690
+ signatures: [["source","destination"]]
6691
6691
  },
6692
6692
  {
6693
6693
  name: "multiDrawIndirect",
@@ -6771,7 +6771,7 @@ export const NativeFunctions = [
6771
6771
  },
6772
6772
  {
6773
6773
  name: "texElementImage2D",
6774
- signatures: [["target","level","internalformat","format","type","element"],["target","level","internalformat","width","height","format","type","element"],["target","level","internalformat","sx","sy","swidth","sheight","format","type","element"],["target","level","internalformat","sx","sy","swidth","sheight","width","height","format","type","element"]]
6774
+ signatures: [["target","internalformat","element","?config"]]
6775
6775
  },
6776
6776
  {
6777
6777
  name: "drawingBufferStorage",
@@ -8409,6 +8409,10 @@ export const NativeFunctions = [
8409
8409
  name: "registerTool",
8410
8410
  signatures: [["tool","?options"]]
8411
8411
  },
8412
+ {
8413
+ name: "getTools",
8414
+ signatures: [["?options"]]
8415
+ },
8412
8416
  {
8413
8417
  name: "executeTool",
8414
8418
  signatures: [["tool","input_arguments","?options"]]
@@ -105,7 +105,7 @@ window[Spec.INTERNAL_KILL_SWITCH] = () => {
105
105
 
106
106
  function sendEventToDevTools(event: Spec.WebVitalsEvent): void {
107
107
  const payload = JSON.stringify(event);
108
- window[Spec.EVENT_BINDING_NAME](payload);
108
+ window[Spec.EVENT_BINDING_NAME]?.(payload);
109
109
  }
110
110
 
111
111
  /**
@@ -7,7 +7,7 @@ import type * as SDK from '../../core/sdk/sdk.js';
7
7
  import type * as Workspace from '../workspace/workspace.js';
8
8
 
9
9
  import type * as StackTrace from './stack_trace.js';
10
- import type {FrameNode, ParsedFrameInfo} from './Trie.js';
10
+ import type {EvalOrigin, FrameNode, ParsedFrameInfo} from './Trie.js';
11
11
 
12
12
  export type AnyStackTraceImpl = StackTraceImpl<FragmentImpl|DebuggableFragmentImpl|ParsedErrorStackFragmentImpl>;
13
13
 
@@ -102,6 +102,28 @@ export class FrameImpl implements StackTrace.StackTrace.Frame {
102
102
  }
103
103
  }
104
104
 
105
+ /**
106
+ * Converts the internal recursive `EvalOrigin` trie representation into the public-facing
107
+ * linear `ParsedErrorStackFrameImpl` representation.
108
+ *
109
+ * NOTE: The V8 Error#stack format only allows serializing a single location descriptor
110
+ * per nested eval origin level (e.g. `eval at functionName (location)`). Therefore, the
111
+ * public-facing API only surfaces the top-most logical frame (`evalOrigin.frames[0]`) at each
112
+ * eval level. Any other inlined caller frames at that specific level are technically dropped
113
+ * in the public API, but they are fully preserved in the internal trie representation for
114
+ * debugging, navigation, and ignore list correlation.
115
+ */
116
+ function createParsedErrorStackFrameImplFromEvalOrigin(
117
+ evalOrigin: EvalOrigin|undefined, parsedFrameInfo?: ParsedFrameInfo): ParsedErrorStackFrameImpl|undefined {
118
+ if (!evalOrigin || evalOrigin.frames.length === 0) {
119
+ return undefined;
120
+ }
121
+ const frame = evalOrigin.frames[0];
122
+ const nestedOrigin = createParsedErrorStackFrameImplFromEvalOrigin(
123
+ evalOrigin.evalOrigin, parsedFrameInfo?.evalOrigin?.parsedFrameInfo);
124
+ return new ParsedErrorStackFrameImpl(frame, parsedFrameInfo?.evalOrigin?.parsedFrameInfo, nestedOrigin);
125
+ }
126
+
105
127
  export class ParsedErrorStackFragmentImpl implements StackTrace.StackTrace.ParsedErrorStackFragment {
106
128
  constructor(readonly fragment: FragmentImpl) {
107
129
  }
@@ -114,8 +136,9 @@ export class ParsedErrorStackFragmentImpl implements StackTrace.StackTrace.Parse
114
136
  const frames: ParsedErrorStackFrameImpl[] = [];
115
137
 
116
138
  for (const node of this.fragment.node.getCallStack()) {
139
+ const evalOrigin = createParsedErrorStackFrameImplFromEvalOrigin(node.evalOrigin, node.parsedFrameInfo);
117
140
  for (const frame of node.frames) {
118
- frames.push(new ParsedErrorStackFrameImpl(frame, node.parsedFrameInfo, node.evalOriginFrames));
141
+ frames.push(new ParsedErrorStackFrameImpl(frame, node.parsedFrameInfo, evalOrigin));
119
142
  }
120
143
  }
121
144
 
@@ -126,12 +149,12 @@ export class ParsedErrorStackFragmentImpl implements StackTrace.StackTrace.Parse
126
149
  export class ParsedErrorStackFrameImpl implements StackTrace.StackTrace.ParsedErrorStackFrame {
127
150
  readonly #frame: FrameImpl;
128
151
  readonly #parsedFrameInfo?: ParsedFrameInfo;
129
- readonly #evalOriginFrames?: FrameImpl[];
152
+ readonly #evalOrigin?: ParsedErrorStackFrameImpl;
130
153
 
131
- constructor(frame: FrameImpl, parsedFrameInfo?: ParsedFrameInfo, evalOriginFrames?: FrameImpl[]) {
154
+ constructor(frame: FrameImpl, parsedFrameInfo?: ParsedFrameInfo, evalOrigin?: ParsedErrorStackFrameImpl) {
132
155
  this.#frame = frame;
133
156
  this.#parsedFrameInfo = parsedFrameInfo;
134
- this.#evalOriginFrames = evalOriginFrames;
157
+ this.#evalOrigin = evalOrigin;
135
158
  }
136
159
 
137
160
  get url(): string|undefined {
@@ -166,10 +189,7 @@ export class ParsedErrorStackFrameImpl implements StackTrace.StackTrace.ParsedEr
166
189
  return this.#parsedFrameInfo?.isEval;
167
190
  }
168
191
  get evalOrigin(): ParsedErrorStackFrameImpl|undefined {
169
- if (!this.#evalOriginFrames || this.#evalOriginFrames.length === 0) {
170
- return undefined;
171
- }
172
- return new ParsedErrorStackFrameImpl(this.#evalOriginFrames[0], this.#parsedFrameInfo?.evalOrigin?.parsedFrameInfo);
192
+ return this.#evalOrigin;
173
193
  }
174
194
  get isWasm(): boolean|undefined {
175
195
  return this.#parsedFrameInfo?.isWasm;
@@ -18,7 +18,7 @@ import {
18
18
  ParsedErrorStackFragmentImpl,
19
19
  StackTraceImpl
20
20
  } from './StackTraceImpl.js';
21
- import {type FrameNode, type RawFrame, Trie} from './Trie.js';
21
+ import {EvalOrigin, type FrameNode, type RawFrame, Trie} from './Trie.js';
22
22
 
23
23
  /**
24
24
  * A stack trace translation function.
@@ -135,7 +135,6 @@ export class StackTraceModel extends SDK.SDKModel.SDKModel<unknown> {
135
135
  stackTraceOrPausedEvent: Protocol.Runtime.StackTrace|SDK.DebuggerModel.DebuggerPausedDetails,
136
136
  rawFramesToUIFrames: TranslateRawFrames): Promise<AsyncFragmentImpl[]> {
137
137
  const asyncFragments: Array<Promise<AsyncFragmentImpl>> = [];
138
-
139
138
  const debuggerModel = this.target().model(SDK.DebuggerModel.DebuggerModel);
140
139
  if (debuggerModel) {
141
140
  for await (
@@ -185,15 +184,16 @@ export class StackTraceModel extends SDK.SDKModel.SDKModel<unknown> {
185
184
  const uiFrames = await rawFramesToUIFrames(rawFrames, this.target());
186
185
  console.assert(rawFrames.length === uiFrames.length, 'Broken rawFramesToUIFrames implementation');
187
186
 
188
- const evalOriginPromises: Array<ReturnType<TranslateRawFrames>> = [];
187
+ const evalOriginPromises: Array<Promise<EvalOrigin|undefined>> = [];
189
188
  for (const node of fragment.node.getCallStack()) {
190
189
  if (node.parsedFrameInfo?.evalOrigin) {
191
190
  // Evaluate each eval origin individually, as they are not a contiguous stack trace.
192
- evalOriginPromises.push(rawFramesToUIFrames([node.parsedFrameInfo.evalOrigin], this.target()));
191
+ evalOriginPromises.push(
192
+ translateEvalOrigin(node.parsedFrameInfo.evalOrigin, rawFramesToUIFrames, this.target()));
193
193
  }
194
194
  }
195
195
 
196
- const evalUiFrames = await Promise.all(evalOriginPromises);
196
+ const evalOrigins = await Promise.all(evalOriginPromises);
197
197
 
198
198
  let i = 0;
199
199
  let evalI = 0;
@@ -204,12 +204,7 @@ export class StackTraceModel extends SDK.SDKModel.SDKModel<unknown> {
204
204
  node.rawFrame.functionName));
205
205
 
206
206
  if (node.parsedFrameInfo?.evalOrigin) {
207
- const evalOriginRawFrame = node.parsedFrameInfo.evalOrigin;
208
- // evalUiFrames[evalI] is Array<Array<Frame>>, and since we passed a 1-element array, we take [0]
209
- node.evalOriginFrames = evalUiFrames[evalI++][0].map(
210
- frame => new FrameImpl(
211
- frame.url, frame.uiSourceCode, frame.name, frame.line, frame.column, frame.missingDebugInfo,
212
- evalOriginRawFrame.functionName));
207
+ node.evalOrigin = evalOrigins[evalI++];
213
208
  }
214
209
  }
215
210
  }
@@ -241,4 +236,21 @@ export class StackTraceModel extends SDK.SDKModel.SDKModel<unknown> {
241
236
  }
242
237
  }
243
238
 
239
+ async function translateEvalOrigin(
240
+ rawFrame: RawFrame, rawFramesToUIFrames: TranslateRawFrames,
241
+ target: SDK.Target.Target): Promise<EvalOrigin|undefined> {
242
+ const uiFrames = await rawFramesToUIFrames([rawFrame], target);
243
+ const frames = uiFrames[0].map(
244
+ frame => new FrameImpl(
245
+ frame.url, frame.uiSourceCode, frame.name, frame.line, frame.column, frame.missingDebugInfo,
246
+ rawFrame.functionName));
247
+
248
+ let parentEvalOrigin: EvalOrigin|undefined;
249
+ if (rawFrame.parsedFrameInfo?.evalOrigin) {
250
+ parentEvalOrigin = await translateEvalOrigin(rawFrame.parsedFrameInfo.evalOrigin, rawFramesToUIFrames, target);
251
+ }
252
+
253
+ return new EvalOrigin(frames, parentEvalOrigin);
254
+ }
255
+
244
256
  SDK.SDKModel.SDKModel.register(StackTraceModel, {capabilities: SDK.Target.Capability.NONE, autostart: false});
@@ -41,6 +41,16 @@ export function isBuiltinFrame(rawFrame: RawFrame): boolean {
41
41
  !Boolean(rawFrame.url);
42
42
  }
43
43
 
44
+ export class EvalOrigin {
45
+ readonly frames: FrameImpl[];
46
+ readonly evalOrigin?: EvalOrigin;
47
+
48
+ constructor(frames: FrameImpl[], evalOrigin?: EvalOrigin) {
49
+ this.frames = frames;
50
+ this.evalOrigin = evalOrigin;
51
+ }
52
+ }
53
+
44
54
  interface FrameNodeBase<ChildT, ParentT> {
45
55
  readonly parent: ParentT;
46
56
  readonly children: ChildT[];
@@ -58,7 +68,7 @@ export class FrameNode implements FrameNodeBase<FrameNode, AnyFrameNode> {
58
68
 
59
69
  fragment?: FragmentImpl;
60
70
  parsedFrameInfo?: ParsedFrameInfo;
61
- evalOriginFrames?: FrameImpl[];
71
+ evalOrigin?: EvalOrigin;
62
72
 
63
73
  constructor(rawFrame: RawFrame, parent: AnyFrameNode) {
64
74
  this.rawFrame = rawFrame;
@@ -406,6 +406,17 @@ export class BottomUpRootNode extends Node {
406
406
  const eventGroupIdCallback = this.eventGroupIdCallback;
407
407
  const forceGroupIdCallback = this.forceGroupIdCallback;
408
408
 
409
+ const idToIsCacheHit = new Map<string, boolean>();
410
+ for (const e of this.events) {
411
+ if (Types.Events.isReceivedDataEvent(e) && e.name === 'ResourceReceiveResponse') {
412
+ let id = generateEventID(e);
413
+ if (this.forceGroupIdCallback && this.eventGroupIdCallback) {
414
+ id = `${id}-${this.eventGroupIdCallback(e)}`;
415
+ }
416
+ idToIsCacheHit.set(id, e.args.data.fromCache || false);
417
+ }
418
+ }
419
+
409
420
  // encodedDataLength is provided solely on instant events.
410
421
  const sumTransferSizeOfInstantEvent = (e: Types.Events.Event): void => {
411
422
  if (Types.Events.isReceivedDataEvent(e)) {
@@ -424,7 +435,15 @@ export class BottomUpRootNode extends Node {
424
435
  // ResourceReceivedData events tally up the transfer size over time, but the
425
436
  // ResourceReceiveResponse / ResourceFinish events hold the final result.
426
437
  if (e.name === 'ResourceReceivedData') {
427
- node.transferSize += e.args.data.encodedDataLength;
438
+ if (idToIsCacheHit.get(id)) {
439
+ // It's a cache hit, so the actual network transfer size is 0.
440
+ // We overwrite the tallied sum (which is uncompressed body size) with 0.
441
+ node.transferSize = 0;
442
+ } else {
443
+ node.transferSize += e.args.data.encodedDataLength;
444
+ }
445
+ } else if (e.name === 'ResourceFinish' && e.args.data.encodedDataLength === 0 && idToIsCacheHit.get(id)) {
446
+ node.transferSize = 0;
428
447
  } else if (e.args.data.encodedDataLength > 0) {
429
448
  // For some reason, ResourceFinish can be zero even if data was sent.
430
449
  // Ignore that case.
@@ -417,6 +417,15 @@ export function calculateDocFirstByteTs(docRequest: Types.Events.SyntheticNetwor
417
417
  return docRequest.ts;
418
418
  }
419
419
 
420
+ // @ts-expect-error
421
+ const isLightrider = globalThis.isLightrider;
422
+ if (isLightrider) {
423
+ const lrServerResponseTime = docRequest.args.data.lrServerResponseTime;
424
+ if (lrServerResponseTime !== undefined) {
425
+ return Types.Timing.Micro(docRequest.ts + Helpers.Timing.milliToMicro(lrServerResponseTime));
426
+ }
427
+ }
428
+
420
429
  const timing = docRequest.args.data.timing;
421
430
  if (!timing) {
422
431
  // Older traces do not have timings.
@@ -185,6 +185,10 @@ const UIStringsNotTranslate = {
185
185
  * @description Placeholder text for the chat UI input with branding Gemini (do not translate)
186
186
  */
187
187
  inputPlaceholderForNoContextBranded: 'Ask Gemini',
188
+ /**
189
+ * @description Placeholder text for the chat UI input when AIAgent2 is enabled.
190
+ */
191
+ inputPlaceholderForV2: 'Ask a question (AIAgent2 enabled)',
188
192
  /**
189
193
  * @description Disclaimer text right after the chat input.
190
194
  */
@@ -1363,6 +1367,10 @@ export class AiAssistancePanel extends UI.Panel.Panel {
1363
1367
  return i18nString(UIStrings.followTheSteps);
1364
1368
  }
1365
1369
 
1370
+ if (Root.Runtime.hostConfig.devToolsAiV2Architecture?.enabled) {
1371
+ return lockedString(UIStringsNotTranslate.inputPlaceholderForV2);
1372
+ }
1373
+
1366
1374
  if (this.#conversation && this.#conversation.isBlockedByOrigin) {
1367
1375
  return lockedString(UIStringsNotTranslate.crossOriginError);
1368
1376
  }
@@ -14,12 +14,15 @@ import * as SDK from '../../../core/sdk/sdk.js';
14
14
  import type * as Protocol from '../../../generated/protocol.js';
15
15
  import type {
16
16
  AiWidget, BottomUpTreeAiWidget, ComputedStyleAiWidget, CoreVitalsAiWidget, DomTreeAiWidget, LighthouseReportAiWidget,
17
- NetworkRequestGeneralHeadersAiWidget, PerfInsightAiWidget, PerformanceTraceAiWidget, SourceFileAiWidget,
18
- StylePropertiesAiWidget, TimelineEventSummaryAiWidget,
17
+ NetworkRequestGeneralHeadersAiWidget, PerfInsightAiWidget, PerformanceTraceAiWidget, SourceCodeAiWidget,
18
+ SourceFileAiWidget, SourceFilesListAiWidget, StylePropertiesAiWidget, TimelineEventSummaryAiWidget,
19
19
  TimelineRangeSummaryAiWidget} from '../../../models/ai_assistance/agents/AiAgent.js';
20
20
  import * as AiAssistanceModel from '../../../models/ai_assistance/ai_assistance.js';
21
21
  import * as ComputedStyle from '../../../models/computed_style/computed_style.js';
22
+ import * as Formatter from '../../../models/formatter/formatter.js';
23
+ import * as TextUtils from '../../../models/text_utils/text_utils.js';
22
24
  import * as Trace from '../../../models/trace/trace.js';
25
+ import * as Workspace from '../../../models/workspace/workspace.js';
23
26
  import * as PanelsCommon from '../../../panels/common/common.js';
24
27
  import * as TraceBounds from '../../../services/trace_bounds/trace_bounds.js';
25
28
  import * as Marked from '../../../third_party/marked/marked.js';
@@ -411,6 +414,10 @@ const UIStringsNotTranslate = {
411
414
  * @description Title for the character set declaration widget.
412
415
  */
413
416
  characterSet: 'Character set declaration',
417
+ /**
418
+ * @description Title for the source files list widget.
419
+ */
420
+ inspectedFileNames: 'Inspected file names',
414
421
  } as const;
415
422
 
416
423
  export interface Step {
@@ -1364,6 +1371,101 @@ async function makeSourceFileWidget(widgetData: SourceFileAiWidget): Promise<Wid
1364
1371
  };
1365
1372
  }
1366
1373
 
1374
+ async function makeSourceCodeWidget(widgetData: SourceCodeAiWidget): Promise<WidgetMakerResponse|null> {
1375
+ const url = widgetData.data.url;
1376
+ const filename = url.split('/').pop() || url;
1377
+ const line = widgetData.data.line;
1378
+ const column = widgetData.data.column;
1379
+
1380
+ // If both line and column numbers are provided, we represent a specific function execution,
1381
+ // so the widget title is formatted as 'filename:line:column' (matching the Sources Panel style).
1382
+ // Otherwise, if line and column are not provided, we are viewing the entire file contents,
1383
+ // so the header simply displays 'filename'.
1384
+ const header = line !== undefined && column !== undefined ? `${filename}:${line}:${column}` : filename;
1385
+
1386
+ const uiSourceCode =
1387
+ Workspace.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(url as Platform.DevToolsPath.UrlString);
1388
+ const lastDotIndex = filename.lastIndexOf('.');
1389
+ const fileExtension = lastDotIndex !== -1 ? filename.substring(lastDotIndex + 1) : '';
1390
+
1391
+ let code = widgetData.data.code;
1392
+ if (TextUtils.TextUtils.isMinified(code)) {
1393
+ const canonicalMimeType = uiSourceCode?.contentType().canonicalMimeType() || 'text/javascript';
1394
+ const formatted = await Formatter.ScriptFormatter.formatScriptContent(canonicalMimeType, code, ' ');
1395
+ code = formatted.formattedContent;
1396
+ }
1397
+
1398
+ const renderedWidget = html`
1399
+ <devtools-code-block
1400
+ class="source-code-widget"
1401
+ .displayLimit=${20}
1402
+ .code=${code}
1403
+ .codeLang=${fileExtension}
1404
+ .displayToolbar=${false}
1405
+ .displayNotice=${false}
1406
+ ></devtools-code-block>
1407
+ `;
1408
+
1409
+ return {
1410
+ renderedWidget,
1411
+ title: lockedString(header),
1412
+ revealable: uiSourceCode,
1413
+ accessibleRevealLabel: i18n.i18n.lockedString(`Show ${filename} in Sources`),
1414
+ jslogContext: 'source-code-widget',
1415
+ };
1416
+ }
1417
+
1418
+ function renderFileRevealButton(
1419
+ file: Workspace.UISourceCode.UISourceCode,
1420
+ collapsed: boolean,
1421
+ ): Lit.TemplateResult {
1422
+ const onReveal = (): void => {
1423
+ void Common.Revealer.reveal(file);
1424
+ };
1425
+ const accessibleLabel = i18n.i18n.lockedString(`Show ${file.fullDisplayName()}`);
1426
+ const className = `widget-reveal-button ${collapsed ? 'collapsed-file' : 'visible-file'}`;
1427
+ return html`
1428
+ <devtools-button class=${className}
1429
+ .variant=${Buttons.Button.Variant.TEXT}
1430
+ .accessibleLabel=${accessibleLabel}
1431
+ .jslogContext=${'reveal'}
1432
+ @click=${onReveal}>
1433
+ ${file.fullDisplayName()}
1434
+ <devtools-icon name='tab-move'></devtools-icon>
1435
+ </devtools-button>
1436
+ `;
1437
+ }
1438
+
1439
+ async function makeSourceFilesListWidget(widgetData: SourceFilesListAiWidget): Promise<WidgetMakerResponse|null> {
1440
+ const files = widgetData.data.uiSourceCodes;
1441
+ if (files.length === 0) {
1442
+ return null;
1443
+ }
1444
+
1445
+ // If there are more than 10 files, only show the first 10, and hide the rest unless "Show all" is clicked.
1446
+ // clang-format off
1447
+ const renderedWidget = html`
1448
+ <div class="source-files-widget">
1449
+ ${files.slice(0, 10).map(file => renderFileRevealButton(file, /* collapsed */ false))}
1450
+ ${files.length > 10 ? html`
1451
+ <details class="source-files-details">
1452
+ <summary class="show-more-summary">${i18n.i18n.lockedString(`Show all ${files.length} files`)}</summary>
1453
+ ${files.slice(10).map(file => renderFileRevealButton(file, /* collapsed */ true))}
1454
+ </details> ` : Lit.nothing}
1455
+ </div>`;
1456
+ // clang-format on
1457
+
1458
+ const title = lockedString(UIStringsNotTranslate.inspectedFileNames);
1459
+
1460
+ return {
1461
+ renderedWidget,
1462
+ title,
1463
+ revealable: files[0],
1464
+ accessibleRevealLabel: i18n.i18n.lockedString('Reveal first file in Sources panel'),
1465
+ jslogContext: 'source-files-list-widget',
1466
+ };
1467
+ }
1468
+
1367
1469
  function renderNetworkRequestPreview(networkRequest: NonNullable<DomTreeAiWidget['data']['networkRequest']>):
1368
1470
  Lit.TemplateResult {
1369
1471
  const filename = networkRequest.url.split('/').pop() || networkRequest.url;
@@ -1471,12 +1573,16 @@ export function getWidgetSignature(widget: AiWidget): string {
1471
1573
  return `${widget.name}:${widget.data.bounds.min}-${widget.data.bounds.max}`;
1472
1574
  case 'SOURCE_FILE':
1473
1575
  return `${widget.name}:${widget.data.uiSourceCode.url()}`;
1576
+ case 'SOURCE_FILES_LIST':
1577
+ return `${widget.name}:${widget.data.uiSourceCodes.map(f => f.url()).join(',')}`;
1474
1578
  case 'LIGHTHOUSE_REPORT':
1475
1579
  return `${widget.name}:${widget.data.report.fetchTime}`;
1476
1580
  case 'TIMELINE_EVENT_SUMMARY':
1477
1581
  return `${widget.name}:${widget.data.event.ts}:${widget.data.event.name}`;
1478
1582
  case 'NETWORK_REQUEST_GENERAL_HEADERS':
1479
1583
  return `${widget.name}:${widget.data.request.requestId()}`;
1584
+ case 'SOURCE_CODE':
1585
+ return `${widget.name}:${widget.data.url}:${widget.data.line ?? ''}:${widget.data.column ?? ''}`;
1480
1586
  default:
1481
1587
  Platform.assertNever(widget, 'Unknown AiWidget name');
1482
1588
  }
@@ -1563,6 +1669,9 @@ async function renderWidgets(
1563
1669
  case 'SOURCE_FILE':
1564
1670
  response = await makeSourceFileWidget(widgetData);
1565
1671
  break;
1672
+ case 'SOURCE_FILES_LIST':
1673
+ response = await makeSourceFilesListWidget(widgetData);
1674
+ break;
1566
1675
  case 'LIGHTHOUSE_REPORT':
1567
1676
  response = await makeLighthouseReportWidget(widgetData);
1568
1677
  break;
@@ -1572,6 +1681,9 @@ async function renderWidgets(
1572
1681
  case 'NETWORK_REQUEST_GENERAL_HEADERS':
1573
1682
  response = await makeNetworkRequestGeneralHeadersWidget(widgetData);
1574
1683
  break;
1684
+ case 'SOURCE_CODE':
1685
+ response = await makeSourceCodeWidget(widgetData);
1686
+ break;
1575
1687
  default:
1576
1688
  Platform.assertNever(widgetData, 'Unknown AiWidget name');
1577
1689
  }