chrome-devtools-mcp 1.11.0 → 1.12.0

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 (72) hide show
  1. package/README.md +72 -20
  2. package/build/src/BrowserManager.js +27 -18
  3. package/build/src/McpContext.js +435 -87
  4. package/build/src/McpPage.js +189 -59
  5. package/build/src/McpResponse.js +61 -44
  6. package/build/src/TextSnapshot.js +37 -18
  7. package/build/src/ToolHandler.js +256 -135
  8. package/build/src/bin/chrome-devtools-mcp-main.js +6 -4
  9. package/build/src/bin/chrome-devtools.js +4 -4
  10. package/build/src/collectors/PageCollector.js +13 -9
  11. package/build/src/collectors/ServiceWorkerCollector.js +2 -2
  12. package/build/src/collectors/constants.js +7 -0
  13. package/build/src/config/ConfigParser.js +44 -149
  14. package/build/src/config/ConfigWatcher.js +3 -2
  15. package/build/src/config/ServerConfig.js +251 -0
  16. package/build/src/config/browser-options.js +13 -4
  17. package/build/src/config/cli-options.js +35 -19
  18. package/build/src/config/mcp-options.js +61 -35
  19. package/build/src/config/puppeteer-options.js +4 -2
  20. package/build/src/daemon/client.js +3 -3
  21. package/build/src/daemon/daemon.js +7 -3
  22. package/build/src/daemon/utils.js +2 -1
  23. package/build/src/devtools/DevToolsCommentBridge.js +28 -5
  24. package/build/src/devtools/DevtoolsUtils.js +49 -12
  25. package/build/src/formatters/ConsoleFormatter.js +28 -1
  26. package/build/src/formatters/HeapSnapshotFormatter.js +14 -18
  27. package/build/src/formatters/NetworkFormatter.js +54 -15
  28. package/build/src/formatters/RemoteObjectFormatter.js +231 -0
  29. package/build/src/formatters/SnapshotFormatter.js +13 -3
  30. package/build/src/index.js +256 -104
  31. package/build/src/processors/HeapSnapshotManager.js +390 -128
  32. package/build/src/third_party/THIRD_PARTY_NOTICES +542 -445
  33. package/build/src/third_party/bundled-packages.json +2 -2
  34. package/build/src/third_party/cli.js +9239 -0
  35. package/build/src/third_party/devtools-formatter-worker.js +3089 -2438
  36. package/build/src/third_party/devtools-heap-snapshot-worker.js +172 -1
  37. package/build/src/third_party/index.js +52247 -55764
  38. package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +54576 -52174
  39. package/build/src/tools/ToolDefinition.js +90 -12
  40. package/build/src/tools/comments.js +42 -3
  41. package/build/src/tools/console.js +6 -4
  42. package/build/src/tools/css.js +1 -0
  43. package/build/src/tools/emulation.js +5 -4
  44. package/build/src/tools/extensions.js +5 -0
  45. package/build/src/tools/input.js +21 -6
  46. package/build/src/tools/lighthouse.js +24 -8
  47. package/build/src/tools/memory.js +59 -53
  48. package/build/src/tools/network.js +5 -4
  49. package/build/src/tools/pages.js +48 -6
  50. package/build/src/tools/performance.js +7 -4
  51. package/build/src/tools/pwa.js +7 -0
  52. package/build/src/tools/screencast.js +3 -1
  53. package/build/src/tools/screenshot.js +23 -7
  54. package/build/src/tools/script.js +38 -6
  55. package/build/src/tools/slim/tools.js +21 -5
  56. package/build/src/tools/snapshot.js +13 -3
  57. package/build/src/tools/thirdPartyDeveloper.js +3 -1
  58. package/build/src/tools/webmcp.js +2 -0
  59. package/build/src/utils/TaskRunner.js +136 -0
  60. package/build/src/utils/WaitForHelper.js +1 -1
  61. package/build/src/utils/bytes.js +2 -12
  62. package/build/src/utils/check-for-updates.js +1 -1
  63. package/build/src/utils/disclaimers.js +27 -0
  64. package/build/src/utils/keyboard.js +14 -2
  65. package/build/src/utils/logger.js +69 -0
  66. package/build/src/utils/resourceType.js +27 -0
  67. package/build/src/utils/text.js +29 -0
  68. package/build/src/utils/timeout.js +14 -0
  69. package/build/src/utils/url.js +41 -0
  70. package/build/src/version.js +1 -1
  71. package/package.json +5 -4
  72. package/skills/a11y-debugging/SKILL.md +3 -8
@@ -4,6 +4,7 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { DevTools } from '../third_party/index.js';
7
+ import { truncateText } from '../utils/text.js';
7
8
  const { formatBytesToKb } = DevTools.I18n.ByteUtilities;
8
9
  export const MAX_NAME_LENGTH = 100;
9
10
  /**
@@ -19,10 +20,7 @@ export function formatName(name, options) {
19
20
  * Truncates `value` to `maxLength`, appending an ellipsis if it was cut off.
20
21
  */
21
22
  function truncateValue(value, maxLength = MAX_NAME_LENGTH) {
22
- if (value.length <= maxLength) {
23
- return value;
24
- }
25
- return value.slice(0, maxLength) + '...';
23
+ return truncateText(value, maxLength);
26
24
  }
27
25
  /**
28
26
  * Flattens the analysis into the contexts matching `options`, ranked descending
@@ -153,21 +151,16 @@ export class HeapSnapshotFormatter {
153
151
  return lines.join('\n');
154
152
  }
155
153
  static formatDiffTotals(totals) {
156
- return `Total: # new: ${totals.addedCount}, # deleted: ${totals.removedCount}, # delta: ${formatSignedCount(totals.countDelta)}, alloc size: ${formatSignedSize(totals.addedSize)}, freed size: ${formatSignedSize(totals.removedSize)}, size delta: ${formatSignedSize(totals.sizeDelta)}`;
154
+ return `Total: ${formatDiffCounts(totals)}`;
157
155
  }
158
- static formatDiffDetails(diff, options) {
159
- const lines = [];
160
- lines.push(`${formatName(diff.className, options)}: # new: ${diff.addedCount}, # deleted: ${diff.removedCount}, # delta: ${formatSignedCount(diff.countDelta)}, alloc size: ${formatSignedSize(diff.addedSize)}, freed size: ${formatSignedSize(diff.removedSize)}, size delta: ${formatSignedSize(diff.sizeDelta)}`);
161
- const addedIds = diff.addedIds;
162
- const addedSelfSizes = diff.addedSelfSizes;
163
- const deletedIds = diff.deletedIds;
164
- const deletedSelfSizes = diff.deletedSelfSizes;
165
- lines.push(`Objects:`);
166
- for (let i = 0; i < addedIds.length; i++) {
167
- lines.push(` + @${addedIds[i]} (self_size: ${formatBytesToKb(addedSelfSizes[i])})`);
168
- }
169
- for (let i = 0; i < deletedIds.length; i++) {
170
- lines.push(` - @${deletedIds[i]} (self_size: ${formatBytesToKb(deletedSelfSizes[i])})`);
156
+ static formatDetailedClassDiffHeader(diff, options) {
157
+ return `${formatName(diff.className, options)}: ${formatDiffCounts(diff)}`;
158
+ }
159
+ static formatDetailedClassDiffObjects(objects) {
160
+ const lines = ['Objects:'];
161
+ for (const object of objects) {
162
+ const sign = object.change === 'added' ? '+' : '-';
163
+ lines.push(` ${sign} @${object.id} (self_size: ${formatBytesToKb(object.selfSize)})`);
171
164
  }
172
165
  return lines.join('\n');
173
166
  }
@@ -240,4 +233,7 @@ function formatSignedSize(bytes) {
240
233
  const formatted = formatBytesToKb(bytes);
241
234
  return bytes > 0 ? `+${formatted}` : formatted;
242
235
  }
236
+ function formatDiffCounts(counts) {
237
+ return `# new: ${counts.addedCount}, # deleted: ${counts.removedCount}, # delta: ${formatSignedCount(counts.countDelta)}, alloc size: ${formatSignedSize(counts.addedSize)}, freed size: ${formatSignedSize(counts.removedSize)}, size delta: ${formatSignedSize(counts.sizeDelta)}`;
238
+ }
243
239
  //# sourceMappingURL=HeapSnapshotFormatter.js.map
@@ -5,8 +5,25 @@
5
5
  * */
6
6
  import { isUtf8 } from 'node:buffer';
7
7
  import { DevTools, } from '../third_party/index.js';
8
+ import { truncateText, truncateUrl } from '../utils/text.js';
8
9
  const BODY_CONTEXT_SIZE_LIMIT = 10000;
9
- const URL_CONTEXT_SIZE_LIMIT = 255;
10
+ /**
11
+ * How long to wait for a response body. Puppeteer reads a body only after the
12
+ * response finished loading, with no timeout of its own, and a response that
13
+ * never finishes (e.g. a `Cache-Control: no-store` response the page did not
14
+ * read) would otherwise hold the tool mutex forever.
15
+ */
16
+ export const RESPONSE_BODY_TIMEOUT_MS = 5000;
17
+ class ResponseBodyTimeoutError extends Error {
18
+ timeout;
19
+ constructor(timeout) {
20
+ super(`Response body timed out after ${timeout} ms`);
21
+ this.timeout = timeout;
22
+ }
23
+ }
24
+ function responseBodyTimeoutMessage(error) {
25
+ return `<Response body not available: the response did not finish loading within ${error.timeout} ms>`;
26
+ }
10
27
  export class NetworkFormatter {
11
28
  #request;
12
29
  #options;
@@ -63,10 +80,13 @@ export class NetworkFormatter {
63
80
  if (this.#options.responseFilePath) {
64
81
  let buffer;
65
82
  try {
66
- buffer = await response.buffer();
83
+ buffer = await this.#readResponseBody(response);
67
84
  }
68
- catch {
69
- // Response body is not available anymore
85
+ catch (error) {
86
+ this.#responseBody =
87
+ error instanceof ResponseBodyTimeoutError
88
+ ? responseBodyTimeoutMessage(error)
89
+ : responseBodyNotAvailableMessage;
70
90
  }
71
91
  if (buffer) {
72
92
  if (!this.#options.saveFile) {
@@ -75,9 +95,6 @@ export class NetworkFormatter {
75
95
  const result = await this.#options.saveFile(buffer, this.#options.responseFilePath, '.network-response');
76
96
  this.#responseBodyFilePath = result.filename;
77
97
  }
78
- else {
79
- this.#responseBody = responseBodyNotAvailableMessage;
80
- }
81
98
  }
82
99
  else {
83
100
  this.#responseBody = await this.#getFormattedResponseBody(response, BODY_CONTEXT_SIZE_LIMIT);
@@ -110,7 +127,12 @@ export class NetworkFormatter {
110
127
  }, {});
111
128
  }
112
129
  toJSONDetailed() {
113
- const redirectChain = this.#request.redirectChain();
130
+ // Puppeteer shares one redirect chain array between all hops of a
131
+ // redirect, so earlier hops also list themselves and the hops after them.
132
+ // Keep only the requests that redirected to this one.
133
+ const fullChain = this.#request.redirectChain();
134
+ const ownIndex = fullChain.indexOf(this.#request);
135
+ const redirectChain = ownIndex === -1 ? fullChain : fullChain.slice(0, ownIndex);
114
136
  const formattedRedirectChain = redirectChain.reverse().map(request => {
115
137
  const id = this.#options.requestIdResolver
116
138
  ? this.#options.requestIdResolver(request)
@@ -158,7 +180,7 @@ export class NetworkFormatter {
158
180
  }
159
181
  async #getFormattedResponseBody(httpResponse, sizeLimit = BODY_CONTEXT_SIZE_LIMIT) {
160
182
  try {
161
- const responseBuffer = await httpResponse.buffer();
183
+ const responseBuffer = await this.#readResponseBody(httpResponse);
162
184
  if (isUtf8(responseBuffer)) {
163
185
  const responseAsTest = responseBuffer.toString('utf-8');
164
186
  if (responseAsTest.length === 0) {
@@ -168,21 +190,38 @@ export class NetworkFormatter {
168
190
  }
169
191
  return '<binary data>';
170
192
  }
171
- catch {
193
+ catch (error) {
194
+ if (error instanceof ResponseBodyTimeoutError) {
195
+ return responseBodyTimeoutMessage(error);
196
+ }
172
197
  return '<not available anymore>';
173
198
  }
174
199
  }
200
+ async #readResponseBody(httpResponse) {
201
+ const timeout = this.#options.responseBodyTimeout ?? RESPONSE_BODY_TIMEOUT_MS;
202
+ let timeoutId;
203
+ try {
204
+ return await Promise.race([
205
+ httpResponse.buffer(),
206
+ new Promise((_, reject) => {
207
+ timeoutId = setTimeout(() => {
208
+ reject(new ResponseBodyTimeoutError(timeout));
209
+ }, timeout);
210
+ }),
211
+ ]);
212
+ }
213
+ finally {
214
+ clearTimeout(timeoutId);
215
+ }
216
+ }
175
217
  }
176
218
  function getSizeLimitedString(text, sizeLimit) {
177
- if (text.length > sizeLimit) {
178
- return text.substring(0, sizeLimit) + '... <truncated>';
179
- }
180
- return text;
219
+ return truncateText(text, sizeLimit, { ellipsis: '... <truncated>' });
181
220
  }
182
221
  function convertNetworkRequestConciseToString(data) {
183
222
  // Long URLs (e.g., data: URLs) bloat the concise list output. The full URL
184
223
  // remains available via the detailed view and the structured content.
185
- const url = getSizeLimitedString(data.url, URL_CONTEXT_SIZE_LIMIT);
224
+ const url = truncateUrl(data.url);
186
225
  return `reqid=${data.requestId} ${data.method} ${url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
187
226
  }
188
227
  function formatHeaders(headers) {
@@ -0,0 +1,231 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2026 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ /**
7
+ * Plain-text port of devtools-frontend's RemoteObjectPreviewFormatter
8
+ * (front_end/ui/legacy/components/object_ui/RemoteObjectPreviewFormatter.ts)
9
+ * at revision f7e7785de52d6f5955d6a9c5956c2fe2d520d091, the
10
+ * third_party/devtools-frontend revision this port was written against. Compare
11
+ * with that file when syncing. It formats the preview that CDP already attaches
12
+ * to console arguments, so nothing is evaluated in the page.
13
+ *
14
+ * Intentional differences from upstream:
15
+ * - Returns plain text instead of Lit templates, so there are no CSS classes,
16
+ * tooltips or localized strings ('empty' and 'empty × N' are English).
17
+ * - No nodeDescription markup: DOM nodes print their description as is instead
18
+ * of splitting it into tag, id and class spans (renderNodeTitle), and trusted
19
+ * types print their description instead of `ClassName "value"`.
20
+ * - 'date' and 'node' are added to the subtypes that print their description
21
+ * instead of a property preview.
22
+ * - The `includeNullOrUndefined` option is dropped; null and undefined
23
+ * properties are always listed.
24
+ * - Top-level strings print as their raw value (as the console does for string
25
+ * arguments), and unserializable primitives (NaN, -0, 1n) print from
26
+ * `unserializableValue`.
27
+ * - The 400-character description limit that upstream passes to
28
+ * trimEndWithMaxLength() inline is named MAX_DESCRIPTION_LENGTH.
29
+ */
30
+ import { DevTools } from '../third_party/index.js';
31
+ const { StringUtilities } = DevTools.Platform;
32
+ const MAX_DESCRIPTION_LENGTH = 400;
33
+ const PROMISE_STATE = '[[PromiseState]]';
34
+ const PROMISE_RESULT = '[[PromiseResult]]';
35
+ const GENERATOR_STATE = '[[GeneratorState]]';
36
+ const PRIMITIVE_VALUE = '[[PrimitiveValue]]';
37
+ const WEAK_REF_TARGET = '[[WeakRefTarget]]';
38
+ // Subtypes whose description is shown instead of a property preview.
39
+ const SUBTYPES_WITHOUT_VALUE_PREVIEW = new Set([
40
+ 'arraybuffer',
41
+ 'dataview',
42
+ 'date',
43
+ 'error',
44
+ 'internal#entry',
45
+ 'null',
46
+ 'node',
47
+ 'regexp',
48
+ 'trustedtype',
49
+ 'webassemblymemory',
50
+ ]);
51
+ function sortValue(property) {
52
+ switch (property.name) {
53
+ case PROMISE_STATE:
54
+ return 1;
55
+ case PROMISE_RESULT:
56
+ return 2;
57
+ case GENERATOR_STATE:
58
+ case PRIMITIVE_VALUE:
59
+ case WEAK_REF_TARGET:
60
+ return 3;
61
+ }
62
+ if (property.type !== 'function' && !property.name.startsWith('#')) {
63
+ return 4;
64
+ }
65
+ return 5;
66
+ }
67
+ function formatName(name) {
68
+ return /^\s|\s$|^$|\n/.test(name) ? `"${name.replace(/\n/g, '↵')}"` : name;
69
+ }
70
+ function abbreviateClassName(description) {
71
+ const parts = description.split('.');
72
+ if (parts.length === 1 && parts[0] === 'Object') {
73
+ return '{…}';
74
+ }
75
+ return parts
76
+ .map((part, i) => i < parts.length - 1 ? StringUtilities.trimMiddle(part, 3) : part)
77
+ .join('.');
78
+ }
79
+ function formatPropertyValue(type, subtype, description = '') {
80
+ switch (type) {
81
+ case 'accessor':
82
+ return '(...)';
83
+ case 'function':
84
+ return 'ƒ';
85
+ case 'string':
86
+ return StringUtilities.formatAsJSLiteral(description);
87
+ case 'object':
88
+ return subtype ? description : abbreviateClassName(description);
89
+ default:
90
+ return description;
91
+ }
92
+ }
93
+ function arrayLength(preview) {
94
+ const match = preview.description?.match(/[[(](\d+)[\])]$/);
95
+ return match ? Number(match[1]) : 0;
96
+ }
97
+ function formatArrayItems(preview) {
98
+ const length = arrayLength(preview);
99
+ const toIndex = (name) => {
100
+ const index = Number(name) >>> 0;
101
+ return String(index) === name && index < length ? index : -1;
102
+ };
103
+ const indexed = preview.properties
104
+ .filter(p => toIndex(p.name) !== -1)
105
+ .sort((a, b) => toIndex(a.name) - toIndex(b.name));
106
+ const others = preview.properties
107
+ .filter(p => toIndex(p.name) === -1)
108
+ .sort((a, b) => sortValue(a) - sortValue(b));
109
+ // Gaps can be shown when all properties are guaranteed to be in the preview.
110
+ const canShowGaps = !preview.overflow;
111
+ const gap = (count) => count === 1 ? 'empty' : `empty × ${count}`;
112
+ const items = [];
113
+ let previous = -1;
114
+ for (const property of indexed) {
115
+ const index = toIndex(property.name);
116
+ const value = formatPropertyValue(property.type, property.subtype, property.value);
117
+ if (canShowGaps) {
118
+ if (index - previous > 1) {
119
+ items.push(gap(index - previous - 1));
120
+ }
121
+ items.push(value);
122
+ }
123
+ else {
124
+ items.push(index === items.length ? value : `${property.name}: ${value}`);
125
+ }
126
+ previous = index;
127
+ }
128
+ if (canShowGaps && length - previous > 1) {
129
+ items.push(gap(length - previous - 1));
130
+ }
131
+ for (const property of others) {
132
+ items.push(`${formatName(property.name)}: ${formatPropertyValue(property.type, property.subtype, property.value)}`);
133
+ }
134
+ return items;
135
+ }
136
+ function formatObjectItems(preview) {
137
+ const properties = preview.properties
138
+ .filter(p => p.type !== 'accessor')
139
+ .sort((a, b) => sortValue(a) - sortValue(b));
140
+ const items = [];
141
+ for (let i = 0; i < properties.length; i++) {
142
+ const property = properties[i];
143
+ const value = formatPropertyValue(property.type, property.subtype, property.value);
144
+ if (preview.subtype === 'promise' && property.name === PROMISE_STATE) {
145
+ const result = properties.at(i + 1);
146
+ if (result?.name === PROMISE_RESULT) {
147
+ i++;
148
+ }
149
+ items.push(property.value !== 'pending' && result?.name === PROMISE_RESULT
150
+ ? `<${property.value}>: ${formatPropertyValue(result.type, result.subtype, result.value)}`
151
+ : `<${property.value}>`);
152
+ }
153
+ else if (preview.subtype === 'generator' &&
154
+ property.name === GENERATOR_STATE) {
155
+ items.push(`<${property.value}>`);
156
+ }
157
+ else if (property.name === PRIMITIVE_VALUE) {
158
+ items.push(value);
159
+ }
160
+ else if (property.name === WEAK_REF_TARGET) {
161
+ items.push(property.type === 'undefined' ? '<cleared>' : value);
162
+ }
163
+ else {
164
+ items.push(`${formatName(property.name)}: ${value}`);
165
+ }
166
+ }
167
+ return items;
168
+ }
169
+ function formatEntryItems(preview) {
170
+ return (preview.entries ?? []).map(({ key, value }) => {
171
+ const formattedValue = formatPropertyValue(value.type, value.subtype, value.description);
172
+ return key
173
+ ? `${formatPropertyValue(key.type, key.subtype, key.description)} => ${formattedValue}`
174
+ : formattedValue;
175
+ });
176
+ }
177
+ /**
178
+ * Formats a `Runtime.ObjectPreview` the way the DevTools console previews it,
179
+ * for example `Map(1) {1 => 2}`, `(3) [1, 2, 3]` or `{a: 1, self: {…}}`.
180
+ */
181
+ function formatObjectPreview(preview) {
182
+ const description = preview.description ?? '';
183
+ if (preview.type !== 'object' ||
184
+ (preview.subtype && SUBTYPES_WITHOUT_VALUE_PREVIEW.has(preview.subtype))) {
185
+ return formatPropertyValue(preview.type, preview.subtype, description);
186
+ }
187
+ const isArray = preview.subtype === 'array' || preview.subtype === 'typedarray';
188
+ let prefix = '';
189
+ if (isArray) {
190
+ const length = arrayLength(preview);
191
+ const lengthText = length > 1 ? `(${length})` : '';
192
+ const name = description.replace(/[[(]\d+[\])]$/, '');
193
+ prefix = name === 'Array' ? lengthText : `${name}${lengthText}`;
194
+ }
195
+ else if (description !== 'Object') {
196
+ prefix = description;
197
+ }
198
+ const items = preview.entries
199
+ ? formatEntryItems(preview)
200
+ : isArray
201
+ ? formatArrayItems(preview)
202
+ : formatObjectItems(preview);
203
+ if (preview.overflow) {
204
+ items.push('…');
205
+ }
206
+ const body = isArray ? `[${items.join(', ')}]` : `{${items.join(', ')}}`;
207
+ return prefix ? `${prefix} ${body}` : body;
208
+ }
209
+ /**
210
+ * Formats a console argument from the description and preview that CDP sends
211
+ * with it.
212
+ */
213
+ export function formatRemoteObject(remoteObject) {
214
+ if (remoteObject.preview &&
215
+ remoteObject.type === 'object' &&
216
+ remoteObject.subtype !== 'node' &&
217
+ remoteObject.subtype !== 'trustedtype') {
218
+ return formatObjectPreview(remoteObject.preview);
219
+ }
220
+ if (remoteObject.type === 'string') {
221
+ return String(remoteObject.value ?? '');
222
+ }
223
+ if (remoteObject.unserializableValue !== undefined) {
224
+ return remoteObject.unserializableValue;
225
+ }
226
+ if (remoteObject.description !== undefined) {
227
+ return StringUtilities.trimEndWithMaxLength(remoteObject.description, MAX_DESCRIPTION_LENGTH);
228
+ }
229
+ return String(remoteObject.value);
230
+ }
231
+ //# sourceMappingURL=RemoteObjectFormatter.js.map
@@ -3,6 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ import { truncateUrl } from '../utils/text.js';
6
7
  export class SnapshotFormatter {
7
8
  #snapshot;
8
9
  constructor(snapshot) {
@@ -29,7 +30,7 @@ Get a verbose snapshot to include all elements if you are interested in the sele
29
30
  const attributes = this.#getAttributes(node);
30
31
  const line = ' '.repeat(depth * 2) +
31
32
  attributes.join(' ') +
32
- (node.id === this.#snapshot.selectedElementUid
33
+ (node.id && node.id === this.#snapshot.selectedElementUid
33
34
  ? ' [selected in the DevTools Elements panel]'
34
35
  : '') +
35
36
  '\n';
@@ -66,7 +67,10 @@ Get a verbose snapshot to include all elements if you are interested in the sele
66
67
  return result;
67
68
  }
68
69
  #getAttributes(serializedAXNodeRoot) {
69
- const attributes = [`uid=${serializedAXNodeRoot.id}`];
70
+ const attributes = [];
71
+ if (serializedAXNodeRoot.id) {
72
+ attributes.push(`uid=${serializedAXNodeRoot.id}`);
73
+ }
70
74
  if (serializedAXNodeRoot.role &&
71
75
  serializedAXNodeRoot.role !== 'StaticText') {
72
76
  attributes.push(serializedAXNodeRoot.role === 'none'
@@ -105,7 +109,9 @@ Get a verbose snapshot to include all elements if you are interested in the sele
105
109
  #getAttributesMap(node, excludeSpecial = false) {
106
110
  const result = {};
107
111
  if (!excludeSpecial) {
108
- result.id = node.id;
112
+ if (node.id) {
113
+ result.id = node.id;
114
+ }
109
115
  if (node.role) {
110
116
  result.role = node.role;
111
117
  }
@@ -134,6 +140,10 @@ Get a verbose snapshot to include all elements if you are interested in the sele
134
140
  result[attr] = true;
135
141
  }
136
142
  }
143
+ else if (attr === 'url' && typeof value === 'string') {
144
+ // Keep other URLs whole: the snapshot is their only full copy.
145
+ result[attr] = value.startsWith('data:') ? truncateUrl(value) : value;
146
+ }
137
147
  else if (typeof value === 'string' || typeof value === 'number') {
138
148
  result[attr] = value;
139
149
  }