chrome-devtools-mcp 0.2.0 → 0.2.2

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 (62) hide show
  1. package/README.md +27 -8
  2. package/build/node_modules/chrome-devtools-frontend/front_end/core/common/Progress.js +60 -53
  3. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/GdpClient.js +1 -1
  4. package/build/node_modules/chrome-devtools-frontend/front_end/core/host/UserMetrics.js +5 -2
  5. package/build/node_modules/chrome-devtools-frontend/front_end/core/protocol_client/InspectorBackend.js +2 -0
  6. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +11 -10
  7. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSModel.js +1 -1
  8. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSPropertyParserMatchers.js +24 -4
  9. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/DebuggerModel.js +1 -1
  10. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EnhancedTracesParser.js +29 -24
  11. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +1 -1
  12. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkRequest.js +1 -1
  13. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RehydratingConnection.js +9 -15
  14. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RemoteObject.js +1 -1
  15. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ResourceTreeModel.js +1 -1
  16. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/RuntimeModel.js +1 -1
  17. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/ServiceWorkerManager.js +1 -1
  18. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/SourceMap.js +4 -31
  19. package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TraceObject.js +5 -2
  20. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/NetworkRequestFormatter.js +6 -4
  21. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js +259 -179
  22. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/UnitFormatters.js +10 -1
  23. package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js +14 -3
  24. package/build/node_modules/chrome-devtools-frontend/front_end/models/bindings/ContentProviderBasedProject.js +6 -4
  25. package/build/node_modules/chrome-devtools-frontend/front_end/models/formatter/FormatterWorkerPool.js +2 -2
  26. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/ModelImpl.js +4 -9
  27. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/Processor.js +17 -9
  28. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/AuctionWorkletsHandler.js +1 -1
  29. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/FramesHandler.js +2 -2
  30. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/LayoutShiftsHandler.js +3 -4
  31. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/MetaHandler.js +10 -9
  32. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ScreenshotsHandler.js +0 -1
  33. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/ScriptsHandler.js +4 -4
  34. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserInteractionsHandler.js +2 -10
  35. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserTimingsHandler.js +3 -4
  36. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/SamplesIntegrator.js +8 -6
  37. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/CLSCulprits.js +1 -1
  38. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DocumentLatency.js +3 -3
  39. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/DuplicatedJavaScript.js +1 -1
  40. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/INPBreakdown.js +1 -1
  41. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ImageDelivery.js +1 -1
  42. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPBreakdown.js +1 -1
  43. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/LCPDiscovery.js +1 -1
  44. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/ModernHTTP.js +1 -1
  45. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/NetworkDependencyTree.js +1 -1
  46. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/insights/RenderBlocking.js +1 -1
  47. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/TraceEvents.js +21 -21
  48. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/SourceMapsResolver.js +5 -3
  49. package/build/node_modules/chrome-devtools-frontend/front_end/models/trace_source_maps_resolver/trace_source_maps_resolver.js +1 -1
  50. package/build/src/McpContext.js +60 -10
  51. package/build/src/McpResponse.js +5 -4
  52. package/build/src/WaitForHelper.js +127 -0
  53. package/build/src/browser.js +12 -9
  54. package/build/src/index.js +20 -21
  55. package/build/src/logger.js +1 -0
  56. package/build/src/tools/input.js +5 -6
  57. package/build/src/tools/pages.js +2 -3
  58. package/build/src/tools/performance.js +16 -14
  59. package/build/src/tools/script.js +1 -2
  60. package/build/src/trace-processing/parse.js +23 -14
  61. package/package.json +15 -16
  62. package/build/src/waitForHelpers.js +0 -109
@@ -29,7 +29,7 @@ export class RehydratingConnection {
29
29
  sessions = new Map();
30
30
  #onConnectionLost;
31
31
  #rehydratingWindow;
32
- #onReceiveHostWindowPayloadBound = this.#onReceiveHostWindowPayload.bind(this);
32
+ #onReceiveHostWindowPayloadBound = this.onReceiveHostWindowPayload.bind(this);
33
33
  constructor(onConnectionLost) {
34
34
  // If we're invoking this class, we're in the rehydrating pop-up window. Rename window for clarity.
35
35
  this.#onConnectionLost = onConnectionLost;
@@ -48,12 +48,12 @@ export class RehydratingConnection {
48
48
  * This is a callback for rehydrated session to receive payload from host window. Payload includes but not limited to
49
49
  * the trace event and all necessary data to power a rehydrated session.
50
50
  */
51
- #onReceiveHostWindowPayload(event) {
51
+ onReceiveHostWindowPayload(event) {
52
52
  if (event.data.type === 'REHYDRATING_TRACE_FILE') {
53
53
  const traceJson = event.data.traceJson;
54
54
  let trace;
55
55
  try {
56
- trace = JSON.parse(traceJson);
56
+ trace = new TraceObject(JSON.parse(traceJson));
57
57
  }
58
58
  catch {
59
59
  this.#onConnectionLost(i18nString(UIStrings.errorLoadingLog));
@@ -96,10 +96,10 @@ export class RehydratingConnection {
96
96
  },
97
97
  },
98
98
  });
99
- // Create new session associated to the target created and send
100
- // Target.attachedToTarget to frontend.
101
99
  sessionId += 1;
102
- this.sessions.set(sessionId, new RehydratingSession(sessionId, target, executionContexts, scripts, this));
100
+ const session = new RehydratingSession(sessionId, target, executionContexts, scripts, this);
101
+ this.sessions.set(sessionId, session);
102
+ session.declareSessionAttachedToTarget();
103
103
  }
104
104
  await this.#onRehydrated();
105
105
  return true;
@@ -110,8 +110,7 @@ export class RehydratingConnection {
110
110
  }
111
111
  this.rehydratingConnectionState = 3 /* RehydratingConnectionState.REHYDRATED */;
112
112
  // Use revealer to load trace into performance panel
113
- const trace = new TraceObject(this.trace.traceEvents, this.trace.metadata);
114
- await Common.Revealer.reveal(trace);
113
+ await Common.Revealer.reveal(this.trace);
115
114
  }
116
115
  setOnMessage(onMessage) {
117
116
  this.onMessage = onMessage;
@@ -165,11 +164,7 @@ class RehydratingSessionBase {
165
164
  this.connection = connection;
166
165
  }
167
166
  sendMessageToFrontend(payload) {
168
- requestAnimationFrame(() => {
169
- if (this.connection) {
170
- this.connection.postToFrontend(payload);
171
- }
172
- });
167
+ this.connection?.postToFrontend(payload);
173
168
  }
174
169
  handleFrontendMessageAsFakeCDPAgent(data) {
175
170
  // Send default response in default session.
@@ -190,7 +185,6 @@ export class RehydratingSession extends RehydratingSessionBase {
190
185
  this.target = target;
191
186
  this.executionContexts = executionContexts;
192
187
  this.scripts = scripts;
193
- this.sessionAttachToTarget();
194
188
  }
195
189
  sendMessageToFrontend(payload, attachSessionId = true) {
196
190
  // Attach the session's Id to the message.
@@ -221,7 +215,7 @@ export class RehydratingSession extends RehydratingSessionBase {
221
215
  break;
222
216
  }
223
217
  }
224
- sessionAttachToTarget() {
218
+ declareSessionAttachedToTarget() {
225
219
  this.sendMessageToFrontend({
226
220
  method: 'Target.attachedToTarget',
227
221
  params: {
@@ -1,4 +1,4 @@
1
- // Copyright 2021 The Chromium Authors
1
+ // Copyright 2009 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  // This cannot be an interface due to "instanceof RemoteObject" checks in the code.
@@ -1,4 +1,4 @@
1
- // Copyright 2021 The Chromium Authors
1
+ // Copyright 2011 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  import * as Common from '../common/common.js';
@@ -1,4 +1,4 @@
1
- // Copyright 2021 The Chromium Authors
1
+ // Copyright 2012 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  import * as Common from '../common/common.js';
@@ -1,4 +1,4 @@
1
- // Copyright 2021 The Chromium Authors
1
+ // Copyright 2011 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
4
  import * as Common from '../common/common.js';
@@ -1,35 +1,7 @@
1
- // Copyright 2021 The Chromium Authors
1
+ // Copyright 2012 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
- /*
5
- * Copyright (C) 2012 Google Inc. All rights reserved.
6
- *
7
- * Redistribution and use in source and binary forms, with or without
8
- * modification, are permitted provided that the following conditions are
9
- * met:
10
- *
11
- * * Redistributions of source code must retain the above copyright
12
- * notice, this list of conditions and the following disclaimer.
13
- * * Redistributions in binary form must reproduce the above
14
- * copyright notice, this list of conditions and the following disclaimer
15
- * in the documentation and/or other materials provided with the
16
- * distribution.
17
- * * Neither the #name of Google Inc. nor the names of its
18
- * contributors may be used to endorse or promote products derived from
19
- * this software without specific prior written permission.
20
- *
21
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
- */
4
+ var _a;
33
5
  import * as TextUtils from '../../models/text_utils/text_utils.js';
34
6
  import * as ScopesCodec from '../../third_party/source-map-scopes-codec/source-map-scopes-codec.js';
35
7
  import * as Common from '../common/common.js';
@@ -302,7 +274,7 @@ export class SourceMap {
302
274
  this.mappings().sort(SourceMapEntry.compare);
303
275
  this.#computeReverseMappings(this.#mappings);
304
276
  }
305
- if (!SourceMap.retainRawSourceMaps) {
277
+ if (!_a.retainRawSourceMaps) {
306
278
  this.#json = null;
307
279
  }
308
280
  }
@@ -614,6 +586,7 @@ export class SourceMap {
614
586
  return this.#scopesInfo?.findOriginalFunctionName(position) ?? null;
615
587
  }
616
588
  }
589
+ _a = SourceMap;
617
590
  const VLQ_BASE_SHIFT = 5;
618
591
  const VLQ_BASE_MASK = (1 << 5) - 1;
619
592
  const VLQ_CONTINUATION_MASK = 1 << 5;
@@ -7,8 +7,11 @@ import { ResourceTreeModel } from './ResourceTreeModel.js';
7
7
  export class TraceObject {
8
8
  traceEvents;
9
9
  metadata;
10
- constructor(traceEvents, metadata = {}) {
11
- this.traceEvents = traceEvents;
10
+ constructor(payload, meta = {}) {
11
+ // Handle the typical traceEvent array juggling here.
12
+ const events = Array.isArray(payload) ? payload : payload.traceEvents;
13
+ const metadata = meta ?? (!Array.isArray(payload) && payload.metadata) ?? {};
14
+ this.traceEvents = events;
12
15
  this.metadata = metadata;
13
16
  }
14
17
  }
@@ -1,6 +1,7 @@
1
1
  // Copyright 2025 The Chromium Authors
2
2
  // Use of this source code is governed by a BSD-style license that can be
3
3
  // found in the LICENSE file.
4
+ var _a;
4
5
  import * as Logs from '../../logs/logs.js';
5
6
  import * as NetworkTimeCalculator from '../../network_time_calculator/network_time_calculator.js';
6
7
  import { seconds } from './UnitFormatters.js';
@@ -40,10 +41,10 @@ export class NetworkRequestFormatter {
40
41
  this.#calculator = calculator;
41
42
  }
42
43
  formatRequestHeaders() {
43
- return NetworkRequestFormatter.formatHeaders('Request headers:', this.#request.requestHeaders());
44
+ return _a.formatHeaders('Request headers:', this.#request.requestHeaders());
44
45
  }
45
46
  formatResponseHeaders() {
46
- return NetworkRequestFormatter.formatHeaders('Response headers:', this.#request.responseHeaders);
47
+ return _a.formatHeaders('Response headers:', this.#request.responseHeaders);
47
48
  }
48
49
  /**
49
50
  * Note: nothing here should include information from origins other than
@@ -73,7 +74,7 @@ Request initiator chain:\n${this.formatRequestInitiatorChain()}`;
73
74
  const graph = Logs.NetworkLog.NetworkLog.instance().initiatorGraphForRequest(this.#request);
74
75
  for (const initiator of Array.from(graph.initiators).reverse()) {
75
76
  initiatorChain = initiatorChain + lineStart +
76
- NetworkRequestFormatter.formatInitiatorUrl(initiator.url(), allowedOrigin) + '\n';
77
+ _a.formatInitiatorUrl(initiator.url(), allowedOrigin) + '\n';
77
78
  lineStart = '\t' + lineStart;
78
79
  if (initiator === this.#request) {
79
80
  initiatorChain =
@@ -136,7 +137,7 @@ Request initiator chain:\n${this.formatRequestInitiatorChain()}`;
136
137
  if (!visited.has(keyRequest)) {
137
138
  visited.add(keyRequest);
138
139
  initiatorChain = initiatorChain + lineStart +
139
- NetworkRequestFormatter.formatInitiatorUrl(keyRequest.url(), allowedOrigin) + '\n';
140
+ _a.formatInitiatorUrl(keyRequest.url(), allowedOrigin) + '\n';
140
141
  initiatorChain =
141
142
  this.#formatRequestInitiated(initiated, keyRequest, initiatorChain, '\t' + lineStart, allowedOrigin);
142
143
  }
@@ -145,6 +146,7 @@ Request initiator chain:\n${this.formatRequestInitiatorChain()}`;
145
146
  return initiatorChain;
146
147
  }
147
148
  }
149
+ _a = NetworkRequestFormatter;
148
150
  // Header names that could be included in the prompt, lowercase.
149
151
  const allowedHeaders = new Set([
150
152
  ':authority',