chrome-devtools-frontend 1.0.1602348 → 1.0.1602543

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 (67) hide show
  1. package/AUTHORS +1 -0
  2. package/front_end/core/common/Settings.ts +1 -871
  3. package/front_end/core/common/VersionController.ts +880 -0
  4. package/front_end/core/common/common.ts +2 -0
  5. package/front_end/core/platform/HostRuntime.ts +9 -3
  6. package/front_end/core/protocol_client/InspectorBackend.ts +8 -0
  7. package/front_end/core/root/Runtime.ts +5 -0
  8. package/front_end/core/sdk/Target.ts +5 -0
  9. package/front_end/core/sdk/WebMCPModel.ts +98 -0
  10. package/front_end/core/sdk/sdk.ts +2 -0
  11. package/front_end/entrypoints/heap_snapshot_worker/HeapSnapshot.ts +13 -19
  12. package/front_end/models/ai_assistance/AiConversation.ts +3 -3
  13. package/front_end/models/ai_assistance/agents/AccessibilityAgent.ts +50 -0
  14. package/front_end/models/ai_assistance/agents/AiAgent.ts +14 -1
  15. package/front_end/models/ai_assistance/agents/ContextSelectionAgent.ts +19 -4
  16. package/front_end/models/ai_assistance/agents/NetworkAgent.ts +7 -1
  17. package/front_end/models/ai_assistance/agents/PerformanceAgent.ts +14 -2
  18. package/front_end/models/ai_assistance/agents/StylingAgent.ts +0 -23
  19. package/front_end/models/heap_snapshot_model/HeapSnapshotModel.ts +7 -7
  20. package/front_end/models/lighthouse/RunTypes.ts +3 -1
  21. package/front_end/panels/ai_assistance/AiAssistancePanel.ts +9 -2
  22. package/front_end/panels/ai_assistance/components/ChatMessage.ts +69 -8
  23. package/front_end/panels/ai_assistance/components/chatMessage.css +31 -2
  24. package/front_end/panels/application/AppManifestView.ts +2 -2
  25. package/front_end/panels/application/BackgroundServiceView.ts +9 -9
  26. package/front_end/panels/application/FrameDetailsView.ts +4 -13
  27. package/front_end/panels/application/IndexedDBViews.ts +1 -1
  28. package/front_end/panels/application/ServiceWorkerCacheViews.ts +3 -3
  29. package/front_end/panels/application/components/PermissionsPolicySection.ts +1 -1
  30. package/front_end/panels/application/components/permissionsPolicySection.css +54 -52
  31. package/front_end/panels/application/frameDetailsReportView.css +13 -1
  32. package/front_end/panels/elements/CSSValueTraceView.ts +9 -1
  33. package/front_end/panels/elements/PropertiesWidget.ts +14 -13
  34. package/front_end/panels/elements/PropertyRenderer.ts +10 -9
  35. package/front_end/panels/elements/StandaloneStylesContainer.ts +15 -2
  36. package/front_end/panels/elements/StylePropertyTreeElement.ts +20 -0
  37. package/front_end/panels/elements/StylesSidebarPane.ts +34 -25
  38. package/front_end/panels/elements/stylePropertiesTreeOutline.css +5 -0
  39. package/front_end/panels/issues/AffectedSelectivePermissionsInterventionView.ts +2 -2
  40. package/front_end/panels/lighthouse/LighthouseController.ts +4 -1
  41. package/front_end/panels/media/EventDisplayTable.ts +3 -2
  42. package/front_end/panels/network/EventSourceMessagesView.ts +2 -2
  43. package/front_end/panels/network/ResourceChunkView.ts +1 -1
  44. package/front_end/panels/profiler/HeapDetachedElementsView.ts +9 -4
  45. package/front_end/panels/profiler/HeapProfileView.ts +8 -4
  46. package/front_end/panels/profiler/HeapSnapshotDataGrids.ts +40 -33
  47. package/front_end/panels/profiler/HeapSnapshotGridNodes.ts +1 -1
  48. package/front_end/panels/profiler/HeapSnapshotProxy.ts +1 -1
  49. package/front_end/panels/profiler/HeapSnapshotView.ts +12 -18
  50. package/front_end/panels/profiler/LiveHeapProfileView.ts +3 -4
  51. package/front_end/panels/profiler/ProfileHeader.ts +5 -11
  52. package/front_end/panels/profiler/ProfileView.ts +1 -1
  53. package/front_end/panels/sensors/SensorsView.ts +24 -43
  54. package/front_end/panels/timeline/EventsTimelineTreeView.ts +2 -2
  55. package/front_end/panels/timeline/TimelineTreeView.ts +19 -17
  56. package/front_end/panels/timeline/components/timelineRangeSummaryView.css +3 -1
  57. package/front_end/panels/webauthn/WebauthnPane.ts +52 -0
  58. package/front_end/ui/legacy/Treeoutline.ts +7 -3
  59. package/front_end/ui/legacy/UIUtils.ts +13 -11
  60. package/front_end/ui/legacy/Widget.ts +5 -0
  61. package/front_end/ui/legacy/components/data_grid/DataGrid.ts +1 -1
  62. package/front_end/ui/legacy/components/data_grid/SortableDataGrid.ts +2 -2
  63. package/front_end/ui/legacy/components/object_ui/ObjectPropertiesSection.ts +39 -23
  64. package/front_end/ui/legacy/components/perf_ui/GCActionDelegate.ts +20 -4
  65. package/front_end/ui/legacy/treeoutline.css +4 -0
  66. package/front_end/ui/visual_logging/KnownContextValues.ts +2 -0
  67. package/package.json +1 -1
@@ -34,6 +34,7 @@ import * as StringOutputStream from './StringOutputStream.js';
34
34
  import * as TextDictionary from './TextDictionary.js';
35
35
  import * as Throttler from './Throttler.js';
36
36
  import * as Trie from './Trie.js';
37
+ import * as VersionController from './VersionController.js';
37
38
 
38
39
  /*
39
40
  * This is re-exported here because we moved UIString into platform from
@@ -74,4 +75,5 @@ export {
74
75
  TextDictionary,
75
76
  Throttler,
76
77
  Trie,
78
+ VersionController,
77
79
  };
@@ -14,12 +14,18 @@ export const IS_BROWSER =
14
14
  typeof window !== 'undefined' || (typeof self !== 'undefined' && typeof self.postMessage === 'function');
15
15
 
16
16
  export const HOST_RUNTIME = await (async(): Promise<Api.HostRuntime.HostRuntime> => {
17
- if (IS_NODE) {
18
- return (await import('./node/node.js')).HostRuntime.HOST_RUNTIME;
19
- }
17
+ // Check IS_BROWSER first: in some embedder environments, both IS_NODE
18
+ // and IS_BROWSER can be true because `process` is available in renderer
19
+ // contexts. The browser runtime is always correct when browser APIs
20
+ // (window/self) are available; the Node.js runtime should only be used in
21
+ // pure Node.js environments where those APIs don't exist.
20
22
  if (IS_BROWSER) {
21
23
  return (await import('./browser/browser.js')).HostRuntime.HOST_RUNTIME;
22
24
  }
23
25
 
26
+ if (IS_NODE) {
27
+ return (await import('./node/node.js')).HostRuntime.HOST_RUNTIME;
28
+ }
29
+
24
30
  throw new Error('Unknown runtime!');
25
31
  })();
@@ -491,6 +491,10 @@ export class TargetBase {
491
491
  return this.getAgent('WebAuthn');
492
492
  }
493
493
 
494
+ webMCPAgent(): ProtocolProxyApi.WebMCPApi {
495
+ return this.getAgent('WebMCP');
496
+ }
497
+
494
498
  // Dispatcher registration and de-registration, keep alphabetically sorted.
495
499
 
496
500
  /**
@@ -638,6 +642,10 @@ export class TargetBase {
638
642
  registerWebAuthnDispatcher(dispatcher: ProtocolProxyApi.WebAuthnDispatcher): void {
639
643
  this.registerDispatcher('WebAuthn', dispatcher);
640
644
  }
645
+
646
+ registerWebMCPDispatcher(dispatcher: ProtocolProxyApi.WebMCPDispatcher): void {
647
+ this.registerDispatcher('WebMCP', dispatcher);
648
+ }
641
649
  }
642
650
 
643
651
  /** These are not logged as console.error */
@@ -606,6 +606,10 @@ interface DevToolsProtocolMonitor {
606
606
  enabled: boolean;
607
607
  }
608
608
 
609
+ interface DevToolsWebMCPSupport {
610
+ enabled: boolean;
611
+ }
612
+
609
613
  /**
610
614
  * The host configuration that we expect from the DevTools back-end.
611
615
  *
@@ -657,6 +661,7 @@ export type HostConfig = Platform.TypeScriptUtilities.RecursivePartial<{
657
661
  devToolsConsoleInsightsTeasers: ConsoleInsightsTeasers,
658
662
  devToolsGeminiRebranding: HostConfigGeminiRebranding,
659
663
  devToolsProtocolMonitor: DevToolsProtocolMonitor,
664
+ devToolsWebMCPSupport: DevToolsWebMCPSupport,
660
665
  }>;
661
666
 
662
667
  /**
@@ -6,6 +6,7 @@ import type * as Protocol from '../../generated/protocol.js';
6
6
  import * as Common from '../common/common.js';
7
7
  import * as Platform from '../platform/platform.js';
8
8
  import * as ProtocolClient from '../protocol_client/protocol_client.js';
9
+ import * as Root from '../root/root.js';
9
10
 
10
11
  import {SDKModel, type SDKModelConstructor} from './SDKModel.js';
11
12
  import type {TargetManager} from './TargetManager.js';
@@ -50,6 +51,9 @@ export class Target extends ProtocolClient.InspectorBackend.TargetBase {
50
51
  Capability.LOG | Capability.NETWORK | Capability.TARGET | Capability.TRACING | Capability.EMULATION |
51
52
  Capability.INPUT | Capability.INSPECTOR | Capability.AUDITS | Capability.WEB_AUTHN | Capability.IO |
52
53
  Capability.MEDIA | Capability.EVENT_BREAKPOINTS | Capability.DOM_STORAGE;
54
+ if (Root.Runtime.hostConfig.devToolsWebMCPSupport?.enabled) {
55
+ this.#capabilitiesMask |= Capability.WEB_MCP;
56
+ }
53
57
  if (parentTarget?.type() !== Type.FRAME) {
54
58
  // This matches backend exposing certain capabilities only for the main frame.
55
59
  this.#capabilitiesMask |=
@@ -320,5 +324,6 @@ export const enum Capability {
320
324
  MEDIA = 1 << 18,
321
325
  EVENT_BREAKPOINTS = 1 << 19,
322
326
  DOM_STORAGE = 1 << 20,
327
+ WEB_MCP = 1 << 21,
323
328
  NONE = 0,
324
329
  }
@@ -0,0 +1,98 @@
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 * as ProtocolProxyApi from '../../generated/protocol-proxy-api.js';
6
+ import type * as Protocol from '../../generated/protocol.js';
7
+ import type * as Common from '../common/common.js';
8
+
9
+ import {Events as RuntimeModelEvents, type ExecutionContext, RuntimeModel} from './RuntimeModel.js';
10
+ import {SDKModel} from './SDKModel.js';
11
+ import {Capability, type Target} from './Target.js';
12
+
13
+ export const enum Events {
14
+ TOOLS_ADDED = 'ToolsAdded',
15
+ TOOLS_REMOVED = 'ToolsRemoved',
16
+ }
17
+
18
+ export interface EventTypes {
19
+ [Events.TOOLS_ADDED]: ReadonlyArray<Readonly<Protocol.WebMCP.Tool>>;
20
+ [Events.TOOLS_REMOVED]: ReadonlyArray<Readonly<Protocol.WebMCP.Tool>>;
21
+ }
22
+
23
+ export class WebMCPModel extends SDKModel<EventTypes> {
24
+ readonly #tools = new Map<Protocol.Page.FrameId, Map<string, Protocol.WebMCP.Tool>>();
25
+ readonly agent: ProtocolProxyApi.WebMCPApi;
26
+ #enabled = false;
27
+
28
+ constructor(target: Target) {
29
+ super(target);
30
+ this.agent = target.webMCPAgent();
31
+ target.registerWebMCPDispatcher(new WebMCPDispatcher(this));
32
+
33
+ const runtimeModel = target.model(RuntimeModel);
34
+ if (runtimeModel) {
35
+ runtimeModel.addEventListener(
36
+ RuntimeModelEvents.ExecutionContextDestroyed, this.#executionContextDestroyed, this);
37
+ }
38
+
39
+ void this.enable();
40
+ }
41
+
42
+ get tools(): IteratorObject<Protocol.WebMCP.Tool> {
43
+ return this.#tools.values().flatMap(toolMap => toolMap.values());
44
+ }
45
+
46
+ async enable(): Promise<void> {
47
+ if (this.#enabled) {
48
+ return;
49
+ }
50
+ await this.agent.invoke_enable();
51
+ this.#enabled = true;
52
+ }
53
+
54
+ #executionContextDestroyed(event: Common.EventTarget.EventTargetEvent<ExecutionContext>): void {
55
+ const executionContext = event.data;
56
+ if (executionContext.isDefault && executionContext.frameId) {
57
+ const frameTools = this.#tools.get(executionContext.frameId);
58
+ if (frameTools) {
59
+ const toolsToRemove = [...frameTools.values()];
60
+ this.#tools.delete(executionContext.frameId);
61
+ this.dispatchEventToListeners(Events.TOOLS_REMOVED, toolsToRemove);
62
+ }
63
+ }
64
+ }
65
+
66
+ onToolsRemoved(tools: Protocol.WebMCP.Tool[]): void {
67
+ const deletedTools = tools.filter(tool => this.#tools.get(tool.frameId)?.delete(tool.name));
68
+ this.dispatchEventToListeners(Events.TOOLS_REMOVED, deletedTools);
69
+ }
70
+
71
+ onToolsAdded(tools: Protocol.WebMCP.Tool[]): void {
72
+ for (const tool of tools) {
73
+ const frameTools = this.#tools.get(tool.frameId) ?? new Map();
74
+ if (!this.#tools.has(tool.frameId)) {
75
+ this.#tools.set(tool.frameId, frameTools);
76
+ }
77
+ frameTools.set(tool.name, tool);
78
+ }
79
+ this.dispatchEventToListeners(Events.TOOLS_ADDED, tools);
80
+ }
81
+ }
82
+
83
+ class WebMCPDispatcher implements ProtocolProxyApi.WebMCPDispatcher {
84
+ readonly #model: WebMCPModel;
85
+ constructor(model: WebMCPModel) {
86
+ this.#model = model;
87
+ }
88
+
89
+ toolsAdded(params: Protocol.WebMCP.ToolsAddedEvent): void {
90
+ this.#model.onToolsAdded(params.tools);
91
+ }
92
+
93
+ toolsRemoved(params: Protocol.WebMCP.ToolsRemovedEvent): void {
94
+ this.#model.onToolsRemoved(params.tools);
95
+ }
96
+ }
97
+
98
+ SDKModel.register(WebMCPModel, {capabilities: Capability.WEB_MCP, autostart: true});
@@ -90,6 +90,7 @@ import * as Target from './Target.js';
90
90
  import * as TargetManager from './TargetManager.js';
91
91
  import * as TraceObject from './TraceObject.js';
92
92
  import * as WebAuthnModel from './WebAuthnModel.js';
93
+ import * as WebMCPModel from './WebMCPModel.js';
93
94
 
94
95
  export {
95
96
  AccessibilityModel,
@@ -173,4 +174,5 @@ export {
173
174
  TargetManager,
174
175
  TraceObject,
175
176
  WebAuthnModel,
177
+ WebMCPModel,
176
178
  };
@@ -875,7 +875,7 @@ export abstract class HeapSnapshot {
875
875
  interfaceDefinitions: string,
876
876
  aggregates: Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregateForDiff>,
877
877
  };
878
- #aggregates: Record<string, Record<string, AggregatedInfo>> = {};
878
+ #aggregates: Record<string, Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>> = {};
879
879
  #aggregatesSortedFlags: Record<string, boolean> = {};
880
880
  profile: Profile;
881
881
  nodeTypeOffset!: number;
@@ -1288,7 +1288,7 @@ export abstract class HeapSnapshot {
1288
1288
  }
1289
1289
 
1290
1290
  aggregatesWithFilter(nodeFilter: HeapSnapshotModel.HeapSnapshotModel.NodeFilter):
1291
- Record<string, HeapSnapshotModel.HeapSnapshotModel.Aggregate> {
1291
+ Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo> {
1292
1292
  const filter = this.createFilter(nodeFilter);
1293
1293
  // @ts-expect-error key is added in createFilter
1294
1294
  const key = filter ? filter.key : 'allObjects';
@@ -1473,8 +1473,8 @@ export abstract class HeapSnapshot {
1473
1473
  }
1474
1474
 
1475
1475
  getAggregatesByClassKey(sortedIndexes: boolean, key?: string, filter?: ((arg0: HeapSnapshotNode) => boolean)):
1476
- Record<string, HeapSnapshotModel.HeapSnapshotModel.Aggregate> {
1477
- let aggregates: Record<string, HeapSnapshotModel.HeapSnapshotModel.Aggregate>;
1476
+ Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo> {
1477
+ let aggregates: Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>;
1478
1478
  if (key && this.#aggregates[key]) {
1479
1479
  aggregates = this.#aggregates[key];
1480
1480
  } else {
@@ -1504,7 +1504,7 @@ export abstract class HeapSnapshot {
1504
1504
  }
1505
1505
  }
1506
1506
 
1507
- return aggregates as Record<string, HeapSnapshotModel.HeapSnapshotModel.Aggregate>;
1507
+ return aggregates;
1508
1508
  }
1509
1509
 
1510
1510
  allocationTracesTops(): HeapSnapshotModel.HeapSnapshotModel.SerializedAllocationNode[] {
@@ -1653,8 +1653,9 @@ export abstract class HeapSnapshot {
1653
1653
  }
1654
1654
  }
1655
1655
 
1656
- private buildAggregates(filter?: ((arg0: HeapSnapshotNode) => boolean)): Map<string|number, AggregatedInfo> {
1657
- const aggregates = new Map<string|number, AggregatedInfo>();
1656
+ private buildAggregates(filter?: ((arg0: HeapSnapshotNode) => boolean)):
1657
+ Map<string|number, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo> {
1658
+ const aggregates = new Map<string|number, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>();
1658
1659
 
1659
1660
  const nodes = this.nodes;
1660
1661
  const nodesLength = nodes.length;
@@ -1703,7 +1704,8 @@ export abstract class HeapSnapshot {
1703
1704
  }
1704
1705
 
1705
1706
  private calculateClassesRetainedSize(
1706
- aggregates: Map<string|number, AggregatedInfo>, filter?: ((arg0: HeapSnapshotNode) => boolean)): void {
1707
+ aggregates: Map<string|number, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>,
1708
+ filter?: ((arg0: HeapSnapshotNode) => boolean)): void {
1707
1709
  const rootNodeIndex = this.rootNodeIndexInternal;
1708
1710
  const node = this.createNode(rootNodeIndex);
1709
1711
  const list = [rootNodeIndex];
@@ -1725,7 +1727,7 @@ export abstract class HeapSnapshot {
1725
1727
  const dominatedIndexTo = firstDominatedNodeIndex[nodeOrdinal + 1];
1726
1728
 
1727
1729
  if (!seen && (!filter || filter(node)) && node.selfSize()) {
1728
- (aggregates.get(classKey) as AggregatedInfo).maxRet += node.retainedSize();
1730
+ (aggregates.get(classKey) as HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo).maxRet += node.retainedSize();
1729
1731
  if (dominatedIndexFrom !== dominatedIndexTo) {
1730
1732
  seenClassKeys.set(classKey, true);
1731
1733
  sizes.push(list.length);
@@ -1745,7 +1747,7 @@ export abstract class HeapSnapshot {
1745
1747
  }
1746
1748
  }
1747
1749
 
1748
- private sortAggregateIndexes(aggregates: Record<string, AggregatedInfo>): void {
1750
+ private sortAggregateIndexes(aggregates: Record<string, HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>): void {
1749
1751
  const nodeA = this.createNode();
1750
1752
  const nodeB = this.createNode();
1751
1753
 
@@ -2700,7 +2702,7 @@ export abstract class HeapSnapshot {
2700
2702
 
2701
2703
  private calculateDiffForClass(
2702
2704
  baseAggregate: HeapSnapshotModel.HeapSnapshotModel.AggregateForDiff,
2703
- aggregate?: HeapSnapshotModel.HeapSnapshotModel.Aggregate): HeapSnapshotModel.HeapSnapshotModel.Diff|null {
2705
+ aggregate?: HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo): HeapSnapshotModel.HeapSnapshotModel.Diff|null {
2704
2706
  const baseIds = baseAggregate.ids;
2705
2707
  const baseIndexes = baseAggregate.indexes;
2706
2708
  const baseSelfSizes = baseAggregate.selfSizes;
@@ -4024,11 +4026,3 @@ export class JSHeapSnapshotRetainerEdge extends HeapSnapshotRetainerEdge {
4024
4026
  return this.edge().isWeak();
4025
4027
  }
4026
4028
  }
4027
- export interface AggregatedInfo {
4028
- count: number;
4029
- distance: number;
4030
- self: number;
4031
- maxRet: number;
4032
- name: string;
4033
- idxs: number[];
4034
- }
@@ -54,7 +54,7 @@ export interface AiConversationOptions {
54
54
  performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>;
55
55
  onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
56
56
  networkTimeCalculator?: NetworkTimeCalculator.NetworkTransferTimeCalculator;
57
- lighthouseRecording?: () => Promise<LHModel.ReporterTypes.ReportJSON|null>;
57
+ lighthouseRecording?: (overrides?: LHModel.RunTypes.RunOverrides) => Promise<LHModel.ReporterTypes.ReportJSON|null>;
58
58
  }
59
59
 
60
60
  export class AiConversation {
@@ -91,7 +91,7 @@ export class AiConversation {
91
91
  #contexts: Array<ConversationContext<unknown>> = [];
92
92
 
93
93
  #performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>;
94
- #lighthouseRecording?: () => Promise<LHModel.ReporterTypes.ReportJSON|null>;
94
+ #lighthouseRecording?: (overrides?: LHModel.RunTypes.RunOverrides) => Promise<LHModel.ReporterTypes.ReportJSON|null>;
95
95
  #onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
96
96
  #networkTimeCalculator?: NetworkTimeCalculator.NetworkTransferTimeCalculator;
97
97
 
@@ -334,9 +334,9 @@ export class AiConversation {
334
334
  sessionId: this.id,
335
335
  changeManager: this.#changeManager,
336
336
  performanceRecordAndReload: this.#performanceRecordAndReload,
337
- lighthouseRecording: this.#lighthouseRecording,
338
337
  onInspectElement: this.#onInspectElement,
339
338
  networkTimeCalculator: this.#networkTimeCalculator,
339
+ lighthouseRecording: this.#lighthouseRecording,
340
340
  allowedOrigin: this.allowedOrigin,
341
341
  history,
342
342
  };
@@ -11,6 +11,7 @@ import {LighthouseFormatter} from '../data_formatters/LighthouseFormatter.js';
11
11
  import {debugLog} from '../debug.js';
12
12
 
13
13
  import {
14
+ type AgentOptions,
14
15
  AiAgent,
15
16
  type ContextDetail,
16
17
  type ContextResponse,
@@ -41,6 +42,7 @@ Your role is to help users understand and fix accessibility issues found in Ligh
41
42
 
42
43
  # Capabilities
43
44
  * \`getLighthouseAudits\`: Get detailed audit data.
45
+ * \`runAccessibilityAudits\`: Trigger new accessibility snapshot audits.
44
46
  * \`getStyles\`: Get computed styles for an element by its path.
45
47
  * \`getElementAccessibilityDetails\`: Get A11y properties for an element by its path.
46
48
 
@@ -81,6 +83,13 @@ export class AccessibilityContext extends ConversationContext<LHModel.ReporterTy
81
83
  export class AccessibilityAgent extends AiAgent<LHModel.ReporterTypes.ReportJSON> {
82
84
  readonly preamble = preamble;
83
85
  readonly clientFeature = Host.AidaClient.ClientFeature.CHROME_ACCESSIBILITY_AGENT;
86
+ readonly #lighthouseRecording?:
87
+ (overrides?: LHModel.RunTypes.RunOverrides) => Promise<LHModel.ReporterTypes.ReportJSON|null>;
88
+
89
+ constructor(opts: AgentOptions) {
90
+ super(opts);
91
+ this.#lighthouseRecording = opts.lighthouseRecording;
92
+ }
84
93
 
85
94
  get userTier(): string|undefined {
86
95
  return Root.Runtime.hostConfig.devToolsFreestyler?.userTier;
@@ -127,6 +136,47 @@ export class AccessibilityAgent extends AiAgent<LHModel.ReporterTypes.ReportJSON
127
136
  }
128
137
 
129
138
  #declareFunctions(): void {
139
+ this.declareFunction<{explanation: string}, {audits: string}>('runAccessibilityAudits', {
140
+ description:
141
+ 'Triggers new Lighthouse accessibility audits in snapshot mode. Use this if the user has made changes to the page and you want to re-evaluate the accessibility audits.',
142
+ parameters: {
143
+ type: Host.AidaClient.ParametersTypes.OBJECT,
144
+ description: '',
145
+ nullable: false,
146
+ properties: {
147
+ explanation: {
148
+ type: Host.AidaClient.ParametersTypes.STRING,
149
+ description: 'Explain why you want to run new audits.',
150
+ nullable: false,
151
+ },
152
+ },
153
+ required: ['explanation'],
154
+ },
155
+ displayInfoFromArgs: params => {
156
+ return {
157
+ title: i18n.i18n.lockedString('Running accessibility audits…'),
158
+ thought: params.explanation,
159
+ action: 'runAccessibilityAudits()'
160
+ };
161
+ },
162
+ handler: async params => {
163
+ debugLog('Function call: runAccessibilityAudits', params);
164
+ if (!this.#lighthouseRecording) {
165
+ return {error: 'Lighthouse recording is not available.'};
166
+ }
167
+ const report = await this.#lighthouseRecording({
168
+ mode: 'snapshot',
169
+ categoryIds: ['accessibility'],
170
+ isAIControlled: true,
171
+ });
172
+ if (!report) {
173
+ return {error: 'Failed to run accessibility audits.'};
174
+ }
175
+ const audits = new LighthouseFormatter().audits(report, 'accessibility');
176
+ return {result: {audits}};
177
+ }
178
+ });
179
+
130
180
  this.declareFunction<{categoryId: LHModel.RunTypes.CategoryId}, {audits: string}>('getLighthouseAudits', {
131
181
  description:
132
182
  'Returns the audits for a specific Lighthouse category. Use this to get more information about the performance, accessibility, best-practices, or seo audits.',
@@ -7,6 +7,7 @@ import * as Root from '../../../core/root/root.js';
7
7
  import type * as SDK from '../../../core/sdk/sdk.js';
8
8
  import type * as Protocol from '../../../generated/protocol.js';
9
9
  import * as Greendev from '../../greendev/greendev.js';
10
+ import type * as LHModel from '../../lighthouse/lighthouse.js';
10
11
  import type * as Trace from '../../trace/trace.js';
11
12
  import {debugLog, isStructuredLogEnabled} from '../debug.js';
12
13
 
@@ -151,6 +152,7 @@ export interface AgentOptions {
151
152
  onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
152
153
  history?: Host.AidaClient.Content[];
153
154
  allowedOrigin?: () => string | undefined;
155
+ lighthouseRecording?: (overrides?: LHModel.RunTypes.RunOverrides) => Promise<LHModel.ReporterTypes.ReportJSON|null>;
154
156
  }
155
157
 
156
158
  export interface ParsedAnswer {
@@ -277,9 +279,20 @@ export interface LcpBreakdownAiWidget {
277
279
  };
278
280
  }
279
281
 
282
+ export interface TimelineRangeSummaryAiWidget {
283
+ name: 'TIMELINE_RANGE_SUMMARY';
284
+ data: {
285
+ bounds: Trace.Types.Timing.TraceWindowMicro,
286
+ parsedTrace: Trace.TraceModel.ParsedTrace,
287
+ // We can use this component for other tracks summaries later, so
288
+ // we include the track in the data.
289
+ track: 'main',
290
+ };
291
+ }
292
+
280
293
  // This type will grow as we add more widgets.
281
294
  export type AiWidget = ComputedStyleAiWidget|CoreVitalsAiWidget|StylePropertiesAiWidget|DomTreeAiWidget|
282
- PerformanceTraceAiWidget|LcpBreakdownAiWidget;
295
+ PerformanceTraceAiWidget|LcpBreakdownAiWidget|TimelineRangeSummaryAiWidget;
283
296
 
284
297
  export type FunctionCallHandlerResult<Result> = {
285
298
  requiresApproval: true,
@@ -82,14 +82,14 @@ export class ContextSelectionAgent extends AiAgent<never> {
82
82
  readonly #performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>;
83
83
  readonly #onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>;
84
84
  readonly #networkTimeCalculator?: NetworkTimeCalculator.NetworkTransferTimeCalculator;
85
- readonly #lighthouseRecording?: (() => Promise<LHModel.ReporterTypes.ReportJSON|null>);
85
+ readonly #lighthouseRecording?:
86
+ (overrides?: LHModel.RunTypes.RunOverrides) => Promise<LHModel.ReporterTypes.ReportJSON|null>;
86
87
  #allowedOrigin: () => string | undefined;
87
88
 
88
89
  constructor(opts: AgentOptions&{
89
90
  performanceRecordAndReload?: () => Promise<Trace.TraceModel.ParsedTrace>,
90
91
  onInspectElement?: () => Promise<SDK.DOMModel.DOMNode|null>,
91
92
  networkTimeCalculator?: NetworkTimeCalculator.NetworkTransferTimeCalculator,
92
- lighthouseRecording?: () => Promise<LHModel.ReporterTypes.ReportJSON|null>,
93
93
  }) {
94
94
  super(opts);
95
95
  this.#performanceRecordAndReload = opts.performanceRecordAndReload;
@@ -119,7 +119,16 @@ export class ContextSelectionAgent extends AiAgent<never> {
119
119
 
120
120
  let hasCrossOriginRequest = false;
121
121
  for (const request of Logs.NetworkLog.NetworkLog.instance().requests()) {
122
- if (origin && request.securityOrigin() !== origin) {
122
+ const requestOrigin = new URL(request.documentURL).origin;
123
+ /**
124
+ * NOTE: this origin check does not ensure that all the requests are
125
+ * from the same origin as the target page. Instead, it ensures that
126
+ * the document that loaded the request is the same as the target
127
+ * page. This ensures that we limit the scope to all requests fetched
128
+ * during the loading of the target page, and do not leak URLs from
129
+ * other pages.
130
+ */
131
+ if (origin && requestOrigin !== origin) {
123
132
  hasCrossOriginRequest = true;
124
133
  continue;
125
134
  }
@@ -170,8 +179,14 @@ export class ContextSelectionAgent extends AiAgent<never> {
170
179
  };
171
180
  },
172
181
  handler: async ({id}) => {
182
+ const origin = this.#allowedOrigin();
173
183
  const request = Logs.NetworkLog.NetworkLog.instance().requests().find(req => {
174
- return req.requestId() === id;
184
+ if (req.requestId() !== id) {
185
+ return false;
186
+ }
187
+
188
+ const requestOrigin = new URL(req.documentURL).origin;
189
+ return !origin || requestOrigin === origin;
175
190
  });
176
191
 
177
192
  if (request) {
@@ -95,8 +95,14 @@ export class RequestContext extends ConversationContext<SDK.NetworkRequest.Netwo
95
95
  this.#calculator = calculator;
96
96
  }
97
97
 
98
+ /**
99
+ * Note: this is not the literal origin of the network request. This origin
100
+ * is used to determine when we should force the user to start a new AI
101
+ * conversation when the context changes. We allow a single AI conversation to
102
+ * inspect all network requests that were made for that given target URL.
103
+ */
98
104
  override getOrigin(): string {
99
- return new URL(this.#request.url()).origin;
105
+ return this.#request.documentURL;
100
106
  }
101
107
 
102
108
  override getItem(): SDK.NetworkRequest.NetworkRequest {
@@ -942,7 +942,17 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
942
942
 
943
943
  const key = `getMainThreadTrackSummary({min: ${bounds.min}, max: ${bounds.max}})`;
944
944
  this.#cacheFunctionResult(focus, key, summary);
945
- return {result: {summary}};
945
+ return {
946
+ result: {summary},
947
+ widgets: [{
948
+ name: 'TIMELINE_RANGE_SUMMARY',
949
+ data: {
950
+ parsedTrace,
951
+ bounds,
952
+ track: 'main',
953
+ },
954
+ }],
955
+ };
946
956
  },
947
957
 
948
958
  });
@@ -999,7 +1009,9 @@ export class PerformanceAgent extends AiAgent<AgentFocus> {
999
1009
 
1000
1010
  const key = `getNetworkTrackSummary({min: ${bounds.min}, max: ${bounds.max}})`;
1001
1011
  this.#cacheFunctionResult(focus, key, summary);
1002
- return {result: {summary}};
1012
+ return {
1013
+ result: {summary},
1014
+ };
1003
1015
  },
1004
1016
 
1005
1017
  });
@@ -20,7 +20,6 @@ import {AI_ASSISTANCE_CSS_CLASS_NAME, FREESTYLER_WORLD_NAME} from '../injected.j
20
20
  import {
21
21
  type AgentOptions as BaseAgentOptions,
22
22
  AiAgent,
23
- type AnswerResponse,
24
23
  type ComputedStyleAiWidget,
25
24
  type ContextResponse,
26
25
  ConversationContext,
@@ -1052,28 +1051,6 @@ const data = {
1052
1051
  this.#currentTurnId++;
1053
1052
  }
1054
1053
 
1055
- protected override async finalizeAnswer(answer: AnswerResponse): Promise<AnswerResponse> {
1056
- if (!Root.Runtime.hostConfig.devToolsAiAssistanceV2?.enabled) {
1057
- return answer;
1058
- }
1059
-
1060
- const changedNodeIds = this.#changes.getChangedNodesForGroupId(this.sessionId, this.#currentTurnId);
1061
- if (changedNodeIds.length === 0) {
1062
- return answer;
1063
- }
1064
- answer.widgets = [
1065
- ...(answer.widgets ?? []),
1066
- ...changedNodeIds.map(id => ({
1067
- name: 'STYLE_PROPERTIES' as const,
1068
- data: {
1069
- backendNodeId: id,
1070
- selector: AI_ASSISTANCE_FILTER_REGEX,
1071
- },
1072
- })),
1073
- ];
1074
- return answer;
1075
- }
1076
-
1077
1054
  override async enhanceQuery(
1078
1055
  query: string, selectedElement: ConversationContext<SDK.DOMModel.DOMNode>|null,
1079
1056
  multimodalInputType?: MultimodalInputType): Promise<string> {
@@ -108,13 +108,13 @@ export class Edge {
108
108
  }
109
109
  }
110
110
 
111
- export class Aggregate {
112
- count!: number;
113
- distance!: number;
114
- self!: number;
115
- maxRet!: number;
116
- name!: string;
117
- idxs!: number[];
111
+ export interface AggregatedInfo {
112
+ count: number;
113
+ distance: number;
114
+ self: number;
115
+ maxRet: number;
116
+ name: string;
117
+ idxs: number[];
118
118
  }
119
119
 
120
120
  export class AggregateForDiff {
@@ -6,6 +6,7 @@ import type * as Host from '../../core/host/host.js';
6
6
  import type * as Platform from '../../core/platform/platform.js';
7
7
 
8
8
  export type CategoryId = 'performance'|'accessibility'|'best-practices'|'seo';
9
+ export type RunMode = 'navigation'|'timespan'|'snapshot';
9
10
 
10
11
  export interface Preset {
11
12
  setting: Common.Settings.Setting<boolean>;
@@ -33,10 +34,11 @@ export interface Flags {
33
34
  disableStorageReset?: boolean;
34
35
  throttlingMethod?: string;
35
36
  formFactor?: string|boolean;
36
- mode?: string|boolean;
37
+ mode?: RunMode;
37
38
  }
38
39
 
39
40
  export interface RunOverrides {
40
41
  categoryIds?: CategoryId[];
42
+ mode?: RunMode;
41
43
  isAIControlled?: boolean;
42
44
  }