browser-debugger-cli 0.13.0 → 0.15.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 (159) hide show
  1. package/.claude/skills/bdg/SKILL.md +101 -187
  2. package/README.md +4 -4
  3. package/dist/commands/cdp.js +1 -0
  4. package/dist/commands/cleanup.js +3 -0
  5. package/dist/commands/console.js +5 -1
  6. package/dist/commands/dom/a11y.d.ts +1 -1
  7. package/dist/commands/dom/a11y.js +20 -20
  8. package/dist/commands/dom/eval.d.ts +3 -1
  9. package/dist/commands/dom/eval.js +8 -5
  10. package/dist/commands/dom/formInteraction.js +1 -1
  11. package/dist/commands/dom/get.js +25 -7
  12. package/dist/commands/dom/helpers/evalResult.d.ts +36 -0
  13. package/dist/commands/dom/helpers/evalResult.js +59 -0
  14. package/dist/commands/dom/index.js +7 -2
  15. package/dist/commands/dom/query.d.ts +2 -1
  16. package/dist/commands/dom/query.js +5 -3
  17. package/dist/commands/dom/screenshot.js +1 -0
  18. package/dist/commands/helpJson.d.ts +1 -1
  19. package/dist/commands/helpJson.js +4 -4
  20. package/dist/commands/helpTopic.js +10 -4
  21. package/dist/commands/network/har.js +18 -14
  22. package/dist/commands/network/list.js +46 -3
  23. package/dist/commands/optionBehaviors.d.ts +25 -2
  24. package/dist/commands/optionBehaviors.js +60 -42
  25. package/dist/commands/peek.js +3 -0
  26. package/dist/commands/shared/CommandRunner.js +13 -13
  27. package/dist/commands/shared/daemonErrorHandler.js +2 -2
  28. package/dist/commands/shared/dataFetcher.d.ts +4 -2
  29. package/dist/commands/shared/dataFetcher.js +11 -3
  30. package/dist/commands/shared/handleValidationError.js +3 -3
  31. package/dist/commands/shared/optionTypes.d.ts +15 -3
  32. package/dist/commands/shared/outputFile.d.ts +2 -1
  33. package/dist/commands/shared/outputFile.js +7 -4
  34. package/dist/commands/shared/startHelpers.js +3 -3
  35. package/dist/commands/status.js +3 -1
  36. package/dist/commands/stop.js +2 -1
  37. package/dist/connection/chromeIdentity.d.ts +8 -2
  38. package/dist/connection/chromeIdentity.js +85 -13
  39. package/dist/connection/launcher/flagsBuilder.d.ts +46 -0
  40. package/dist/connection/launcher/flagsBuilder.js +107 -23
  41. package/dist/connection/launcher.d.ts +1 -1
  42. package/dist/connection/launcher.js +1 -2
  43. package/dist/constants.d.ts +31 -5
  44. package/dist/constants.js +37 -5
  45. package/dist/daemon/SessionController.js +2 -0
  46. package/dist/daemon/launcher.d.ts +17 -3
  47. package/dist/daemon/launcher.js +37 -7
  48. package/dist/daemon/session/Session.d.ts +2 -1
  49. package/dist/daemon/session/Session.js +10 -2
  50. package/dist/daemon/session/TelemetryStore.d.ts +7 -0
  51. package/dist/daemon/session/TelemetryStore.js +6 -0
  52. package/dist/daemon/session/commandRegistry.js +25 -7
  53. package/dist/daemon/session/matchedStylesReset.d.ts +26 -0
  54. package/dist/daemon/session/matchedStylesReset.js +46 -0
  55. package/dist/daemon/session/plugins.js +1 -0
  56. package/dist/daemon/session/triggeredRequests.d.ts +0 -5
  57. package/dist/daemon/session/triggeredRequests.js +13 -7
  58. package/dist/daemon.js +8742 -8315
  59. package/dist/errors/messages.d.ts +31 -0
  60. package/dist/errors/messages.js +96 -6
  61. package/dist/index.js +1129 -548
  62. package/dist/ipc/client.d.ts +6 -1
  63. package/dist/ipc/client.js +11 -2
  64. package/dist/ipc/protocol/commands.d.ts +8 -0
  65. package/dist/ipc/protocol/inspectTypes.d.ts +5 -2
  66. package/dist/ipc/session/types.d.ts +5 -1
  67. package/dist/ipc/transport/index.d.ts +6 -0
  68. package/dist/ipc/transport/index.js +16 -1
  69. package/dist/program.d.ts +14 -0
  70. package/dist/program.js +53 -0
  71. package/dist/runtime/dom/elementGeometry.d.ts +23 -0
  72. package/dist/runtime/dom/elementGeometry.js +17 -15
  73. package/dist/runtime/dom/elementInfo.d.ts +13 -4
  74. package/dist/runtime/dom/elementInfo.js +15 -5
  75. package/dist/runtime/dom/evalHelpers.d.ts +24 -4
  76. package/dist/runtime/dom/evalHelpers.js +40 -12
  77. package/dist/runtime/dom/frameScopedConnection.d.ts +7 -0
  78. package/dist/runtime/dom/frameScopedConnection.js +2 -2
  79. package/dist/runtime/dom/frames.d.ts +2 -1
  80. package/dist/runtime/dom/frames.js +3 -1
  81. package/dist/runtime/dom/inspect.d.ts +17 -3
  82. package/dist/runtime/dom/inspect.js +40 -26
  83. package/dist/runtime/dom/inspectModel.d.ts +3 -3
  84. package/dist/runtime/dom/inspectRules.d.ts +29 -3
  85. package/dist/runtime/dom/inspectRules.js +205 -11
  86. package/dist/runtime/dom/layout.d.ts +0 -2
  87. package/dist/runtime/dom/layout.js +1 -2
  88. package/dist/runtime/dom/reactEventHelpers.d.ts +4 -1
  89. package/dist/runtime/dom/reactEventHelpers.js +9 -2
  90. package/dist/runtime/dom/targetNode.d.ts +10 -6
  91. package/dist/runtime/dom/targetNode.js +15 -8
  92. package/dist/runtime/page/emulation.js +6 -5
  93. package/dist/runtime/page/userAgent.d.ts +86 -2
  94. package/dist/runtime/page/userAgent.js +154 -33
  95. package/dist/session/paths.d.ts +38 -3
  96. package/dist/session/paths.js +154 -7
  97. package/dist/session/portClaims.d.ts +0 -8
  98. package/dist/session/portClaims.js +1 -22
  99. package/dist/session/sessionList.d.ts +5 -1
  100. package/dist/session/sessionList.js +5 -1
  101. package/dist/telemetry/a11y.d.ts +15 -1
  102. package/dist/telemetry/a11y.js +83 -0
  103. package/dist/telemetry/har/builder.d.ts +12 -1
  104. package/dist/telemetry/har/builder.js +11 -3
  105. package/dist/telemetry/har/sanitize.d.ts +24 -0
  106. package/dist/telemetry/har/sanitize.js +138 -0
  107. package/dist/telemetry/har/sanitizeBody.d.ts +38 -0
  108. package/dist/telemetry/har/sanitizeBody.js +168 -0
  109. package/dist/telemetry/network.d.ts +13 -16
  110. package/dist/telemetry/network.js +30 -52
  111. package/dist/telemetry/networkRetention.d.ts +83 -0
  112. package/dist/telemetry/networkRetention.js +117 -0
  113. package/dist/types.d.ts +26 -0
  114. package/dist/ui/OutputBuilder.d.ts +10 -0
  115. package/dist/ui/OutputBuilder.js +12 -0
  116. package/dist/ui/formatters/a11y.d.ts +5 -7
  117. package/dist/ui/formatters/a11y.js +7 -61
  118. package/dist/ui/formatters/console/chronological.js +4 -4
  119. package/dist/ui/formatters/console/follow.d.ts +4 -2
  120. package/dist/ui/formatters/console/follow.js +6 -3
  121. package/dist/ui/formatters/console/json.d.ts +3 -6
  122. package/dist/ui/formatters/console/json.js +9 -13
  123. package/dist/ui/formatters/console/shared.d.ts +17 -2
  124. package/dist/ui/formatters/console/shared.js +17 -0
  125. package/dist/ui/formatters/console/summarize.d.ts +2 -2
  126. package/dist/ui/formatters/console/summarize.js +22 -7
  127. package/dist/ui/formatters/console.d.ts +1 -1
  128. package/dist/ui/formatters/console.js +1 -5
  129. package/dist/ui/formatters/details.js +1 -1
  130. package/dist/ui/formatters/dom.d.ts +13 -4
  131. package/dist/ui/formatters/dom.js +25 -7
  132. package/dist/ui/formatters/layout.js +2 -1
  133. package/dist/ui/formatters/longValues.d.ts +14 -0
  134. package/dist/ui/formatters/longValues.js +23 -0
  135. package/dist/ui/formatters/networkList.d.ts +8 -2
  136. package/dist/ui/formatters/networkList.js +11 -2
  137. package/dist/ui/formatters/preview.d.ts +4 -1
  138. package/dist/ui/formatters/preview.js +55 -13
  139. package/dist/ui/formatters/sessions.d.ts +3 -2
  140. package/dist/ui/formatters/sessions.js +10 -3
  141. package/dist/ui/formatters/status.js +7 -0
  142. package/dist/ui/formatters/triggeredRequests.js +2 -1
  143. package/dist/ui/messages/chrome.d.ts +34 -7
  144. package/dist/ui/messages/chrome.js +81 -15
  145. package/dist/ui/messages/commands.d.ts +29 -8
  146. package/dist/ui/messages/commands.js +36 -8
  147. package/dist/ui/messages/networkMessages.d.ts +50 -0
  148. package/dist/ui/messages/networkMessages.js +66 -0
  149. package/dist/ui/messages/session.d.ts +8 -0
  150. package/dist/ui/messages/session.js +10 -0
  151. package/dist/utils/atomicFile.d.ts +2 -1
  152. package/dist/utils/atomicFile.js +5 -2
  153. package/dist/utils/directories.d.ts +41 -0
  154. package/dist/utils/directories.js +48 -0
  155. package/dist/utils/http.d.ts +9 -2
  156. package/dist/utils/http.js +4 -3
  157. package/dist/utils/strings.d.ts +19 -0
  158. package/dist/utils/strings.js +16 -0
  159. package/package.json +2 -2
@@ -9,6 +9,16 @@ import type { BdgResponse } from '../types.js';
9
9
  * @returns `{ version, success: true, data }`
10
10
  */
11
11
  export declare function buildSuccessResponse<T>(data: T): BdgResponse<T>;
12
+ /**
13
+ * Serialize a `--json` response envelope for stdout.
14
+ *
15
+ * Indented by two spaces when stdout is a terminal, so a person can read it;
16
+ * on one line otherwise, since agents and pipes only pay for the whitespace.
17
+ *
18
+ * @param envelope - Response envelope (or other `--json` payload)
19
+ * @returns JSON text
20
+ */
21
+ export declare function stringifyEnvelope(envelope: unknown): string;
12
22
  /** Builders for JSON error envelopes. */
13
23
  export declare class OutputBuilder {
14
24
  /**
@@ -11,6 +11,18 @@ import { VERSION } from '../utils/version.js';
11
11
  export function buildSuccessResponse(data) {
12
12
  return { version: VERSION, success: true, data };
13
13
  }
14
+ /**
15
+ * Serialize a `--json` response envelope for stdout.
16
+ *
17
+ * Indented by two spaces when stdout is a terminal, so a person can read it;
18
+ * on one line otherwise, since agents and pipes only pay for the whitespace.
19
+ *
20
+ * @param envelope - Response envelope (or other `--json` payload)
21
+ * @returns JSON text
22
+ */
23
+ export function stringifyEnvelope(envelope) {
24
+ return process.stdout.isTTY ? JSON.stringify(envelope, null, 2) : JSON.stringify(envelope);
25
+ }
14
26
  /** Builders for JSON error envelopes. */
15
27
  export class OutputBuilder {
16
28
  /**
@@ -1,5 +1,5 @@
1
1
  import type { DomContext } from '../../types.js';
2
- import type { A11yTree, A11yQueryResult, A11yNode } from '../../types.js';
2
+ import type { A11yQueryResult, A11yNode, ListedA11yTree } from '../../types.js';
3
3
  /**
4
4
  * Data structure for a11y node with DOM context.
5
5
  */
@@ -8,15 +8,13 @@ interface A11yNodeWithContext {
8
8
  domContext: DomContext | null;
9
9
  }
10
10
  /**
11
- * Format accessibility tree for human-readable output.
11
+ * Format the listed part of an accessibility tree for human-readable output:
12
+ * one indented line per node, and when nodes were cut, how to see more.
12
13
  *
13
- * Displays the tree structure with role, name, and key properties.
14
- * Shows up to 50 nodes by default for manageable output.
15
- *
16
- * @param tree - Accessibility tree data
14
+ * @param tree - Listed accessibility tree
17
15
  * @returns Formatted output string
18
16
  */
19
- export declare function formatA11yTree(tree: A11yTree): string;
17
+ export declare function formatA11yTree(tree: ListedA11yTree): string;
20
18
  /**
21
19
  * Format query result for human-readable output.
22
20
  *
@@ -1,79 +1,25 @@
1
1
  import { OutputFormatter, areHintsHidden } from '../formatting.js';
2
- import { a11yMoreMatchesNote } from '../messages/commands.js';
3
- /**
4
- * Maximum number of nodes to display in tree output before truncating.
5
- * Prevents overwhelming terminal output for large accessibility trees.
6
- */
7
- const MAX_TREE_NODES_DISPLAY = 50;
2
+ import { a11yMoreMatchesNote, a11yTreeMoreNote, a11yTreeShownNote, } from '../messages/commands.js';
8
3
  /**
9
4
  * Separator width for section dividers in formatted output.
10
5
  */
11
6
  const SEPARATOR_WIDTH = 50;
12
7
  /**
13
- * Format accessibility tree for human-readable output.
14
- *
15
- * Displays the tree structure with role, name, and key properties.
16
- * Shows up to 50 nodes by default for manageable output.
8
+ * Format the listed part of an accessibility tree for human-readable output:
9
+ * one indented line per node, and when nodes were cut, how to see more.
17
10
  *
18
- * @param tree - Accessibility tree data
11
+ * @param tree - Listed accessibility tree
19
12
  * @returns Formatted output string
20
13
  */
21
14
  export function formatA11yTree(tree) {
22
15
  const fmt = new OutputFormatter();
23
16
  fmt.text(`Accessibility Tree (${tree.count} nodes)`).separator('─', SEPARATOR_WIDTH).blank();
24
- const { lines, truncated } = treeLines(tree);
25
- lines.forEach((line) => fmt.text(line));
26
- if (truncated) {
27
- fmt
28
- .blank()
29
- .text(`Showing the first ${MAX_TREE_NODES_DISPLAY} nodes (text boxes and repeated text left out)`)
30
- .text('Use --json flag for complete output, or bdg dom a11y query "role:<role>" to search');
17
+ tree.nodes.forEach((node) => fmt.text(' '.repeat(node.depth) + formatA11yNodeOneLine(node)));
18
+ if (tree.omitted) {
19
+ fmt.blank().text(a11yTreeShownNote(tree.nodes.length)).text(a11yTreeMoreNote(tree.omitted));
31
20
  }
32
21
  return fmt.build();
33
22
  }
34
- /** Roles that only lay out their children and say nothing themselves */
35
- const LAYOUT_ROLES = new Set([
36
- 'generic',
37
- 'none',
38
- 'presentation',
39
- 'LayoutTable',
40
- 'LayoutTableRow',
41
- 'LayoutTableCell',
42
- ]);
43
- /**
44
- * The tree as indented lines, depth-first from the root. Text boxes, blank
45
- * text, text that repeats its parent's name, and nameless layout wrappers are left out
46
- * (their children move up a level), so the budget goes to meaningful nodes.
47
- *
48
- * @param tree - Accessibility tree
49
- * @returns Up to {@link MAX_TREE_NODES_DISPLAY} lines, and whether nodes were left
50
- */
51
- function treeLines(tree) {
52
- const lines = [];
53
- const visited = new Set();
54
- let truncated = false;
55
- const visit = (node, depth, parentName) => {
56
- if (visited.has(node.nodeId))
57
- return;
58
- visited.add(node.nodeId);
59
- if (lines.length >= MAX_TREE_NODES_DISPLAY) {
60
- truncated = true;
61
- return;
62
- }
63
- const skip = node.role === 'InlineTextBox' ||
64
- (node.role === 'StaticText' && (node.name === parentName || !node.name?.trim())) ||
65
- (LAYOUT_ROLES.has(node.role) && !node.name);
66
- if (!skip)
67
- lines.push(' '.repeat(depth) + formatA11yNodeOneLine(node));
68
- for (const childId of node.childIds ?? []) {
69
- const child = tree.nodes.get(childId);
70
- if (child)
71
- visit(child, skip ? depth : depth + 1, node.name ?? parentName);
72
- }
73
- };
74
- visit(tree.root, 0, undefined);
75
- return { lines, truncated };
76
- }
77
23
  /** Roles whose elements take a value (the next step is fill, not click) */
78
24
  const FILLABLE_ROLES = new Set([
79
25
  'textbox',
@@ -2,11 +2,11 @@
2
2
  * Chronological list view (--list mode): all messages with timestamps,
3
3
  * level prefixes, and navigation reload markers.
4
4
  */
5
+ import { MAX_CONSOLE_TEXT_LENGTH } from '../../../constants.js';
6
+ import { capForDisplay } from '../longValues.js';
5
7
  import { OutputFormatter } from '../../formatting.js';
6
8
  import { consoleDroppedNote, consoleIndexGapNote } from '../../messages/consoleMessages.js';
7
- import { truncateByLength } from '../../../utils/strings.js';
8
9
  import { formatSourceLocation, formatTimestamp } from './shared.js';
9
- const MAX_LIST_TEXT_LENGTH = 200;
10
10
  /**
11
11
  * Format console output as chronological list (--list mode).
12
12
  *
@@ -46,8 +46,8 @@ export function formatConsoleChronological(messages, options) {
46
46
  }
47
47
  lastNavigationId = msg.navigationId;
48
48
  }
49
- const truncatedText = truncateByLength(msg.text, MAX_LIST_TEXT_LENGTH);
50
- fmt.text(`${index} ${level} ${time} ${truncatedText}`);
49
+ const text = capForDisplay(msg.text, MAX_CONSOLE_TEXT_LENGTH, options.full);
50
+ fmt.text(`${index} ${level} ${time} ${text}`);
51
51
  const source = formatSourceLocation(msg.stackTrace);
52
52
  if (source) {
53
53
  fmt.text(`${sourceIndent}→ ${source}`);
@@ -6,14 +6,16 @@ import type { ConsoleMessage } from '../../../types.js';
6
6
  /**
7
7
  * Lines of the console stream: the new messages since the last poll, with
8
8
  * a rule the first time (the stream banner is on stderr) and a separator
9
- * after a navigation.
9
+ * after a navigation. Texts are cut like `console --list` cuts them.
10
10
  *
11
11
  * @param messages - New messages
12
- * @param options - `header` the first time; `navigationId` when the page changed
12
+ * @param options - `header` the first time; `navigationId` when the page
13
+ * changed; `full` to print the texts whole
13
14
  * @returns Text to print (empty when there is nothing new)
14
15
  */
15
16
  export declare function formatConsoleFollowLines(messages: ConsoleMessage[], options?: {
16
17
  header?: boolean;
17
18
  navigationId?: number;
19
+ full?: boolean | undefined;
18
20
  }): string;
19
21
  //# sourceMappingURL=follow.d.ts.map
@@ -2,15 +2,18 @@
2
2
  * Follow-mode (live streaming) view. Compact format optimised for
3
3
  * repeated polling output.
4
4
  */
5
+ import { MAX_CONSOLE_TEXT_LENGTH } from '../../../constants.js';
6
+ import { capForDisplay } from '../longValues.js';
5
7
  import { OutputFormatter } from '../../formatting.js';
6
8
  import { formatSourceLocation, formatTimestamp } from './shared.js';
7
9
  /**
8
10
  * Lines of the console stream: the new messages since the last poll, with
9
11
  * a rule the first time (the stream banner is on stderr) and a separator
10
- * after a navigation.
12
+ * after a navigation. Texts are cut like `console --list` cuts them.
11
13
  *
12
14
  * @param messages - New messages
13
- * @param options - `header` the first time; `navigationId` when the page changed
15
+ * @param options - `header` the first time; `navigationId` when the page
16
+ * changed; `full` to print the texts whole
14
17
  * @returns Text to print (empty when there is nothing new)
15
18
  */
16
19
  export function formatConsoleFollowLines(messages, options = {}) {
@@ -26,7 +29,7 @@ export function formatConsoleFollowLines(messages, options = {}) {
26
29
  for (const msg of messages) {
27
30
  const time = formatTimestamp(msg.timestamp);
28
31
  const level = msg.type.padEnd(7);
29
- fmt.text(`${time} ${level} ${msg.text}`);
32
+ fmt.text(`${time} ${level} ${capForDisplay(msg.text, MAX_CONSOLE_TEXT_LENGTH, options.full)}`);
30
33
  const source = formatSourceLocation(msg.stackTrace);
31
34
  if (source)
32
35
  fmt.text(` → ${source}`);
@@ -7,15 +7,12 @@ import type { ConsoleMessage } from '../../../types.js';
7
7
  import { type ConsoleFormatOptions, type ConsoleJsonOutput } from './shared.js';
8
8
  /**
9
9
  * Build the rich JSON output shape (summary + the newest deduped
10
- * errors/warnings, plus the message list when --list is requested).
10
+ * errors/warnings, plus the message list when --list is requested). Texts
11
+ * longer than 10000 characters are cut with
12
+ * `truncatedFrom`, unless `--full`.
11
13
  *
12
14
  * Returns a plain object so callers (e.g. runCommand's JSON envelope) can
13
15
  * embed it without re-parsing a stringified payload.
14
16
  */
15
17
  export declare function buildConsoleJsonOutput(messages: ConsoleMessage[], options: ConsoleFormatOptions): ConsoleJsonOutput;
16
- /**
17
- * Format console output as a JSON string. Thin wrapper around
18
- * buildConsoleJsonOutput for callers that want a serialized payload.
19
- */
20
- export declare function formatConsoleJson(messages: ConsoleMessage[], options: ConsoleFormatOptions): string;
21
18
  //# sourceMappingURL=json.d.ts.map
@@ -4,7 +4,7 @@
4
4
  * --list is set.
5
5
  */
6
6
  import { lastMessages } from './chronological.js';
7
- import { analyzeMessages, newestGroups, } from './shared.js';
7
+ import { analyzeMessages, capMessageText, newestGroups, } from './shared.js';
8
8
  function toJsonError(dedup, includeStackTrace) {
9
9
  const source = dedup.message.stackTrace?.[0];
10
10
  return {
@@ -26,7 +26,9 @@ function toJsonError(dedup, includeStackTrace) {
26
26
  }
27
27
  /**
28
28
  * Build the rich JSON output shape (summary + the newest deduped
29
- * errors/warnings, plus the message list when --list is requested).
29
+ * errors/warnings, plus the message list when --list is requested). Texts
30
+ * longer than 10000 characters are cut with
31
+ * `truncatedFrom`, unless `--full`.
30
32
  *
31
33
  * Returns a plain object so callers (e.g. runCommand's JSON envelope) can
32
34
  * embed it without re-parsing a stringified payload.
@@ -37,22 +39,16 @@ export function buildConsoleJsonOutput(messages, options) {
37
39
  const warnings = newestGroups(grouped.warnings, options.groupLimit);
38
40
  const output = {
39
41
  summary,
40
- errors: errors.shown.map((d) => toJsonError(d, true)),
41
- warnings: warnings.shown.map((d) => toJsonError(d, false)),
42
+ errors: errors.shown.map((d) => capMessageText(toJsonError(d, true), options.full)),
43
+ warnings: warnings.shown.map((d) => capMessageText(toJsonError(d, false), options.full)),
42
44
  ...(errors.more > 0 && { moreErrors: errors.more }),
43
45
  ...(warnings.more > 0 && { moreWarnings: warnings.more }),
44
46
  ...(options.dropped && { dropped: options.dropped }),
45
47
  ...(options.pageCrashedAt !== undefined && { pageCrashedAt: options.pageCrashedAt }),
46
48
  };
47
- if (options.list)
48
- output.messages = lastMessages(messages, options.last);
49
+ if (options.list) {
50
+ output.messages = lastMessages(messages, options.last).map((message) => capMessageText(message, options.full));
51
+ }
49
52
  return output;
50
53
  }
51
- /**
52
- * Format console output as a JSON string. Thin wrapper around
53
- * buildConsoleJsonOutput for callers that want a serialized payload.
54
- */
55
- export function formatConsoleJson(messages, options) {
56
- return JSON.stringify(buildConsoleJsonOutput(messages, options), null, 2);
57
- }
58
54
  //# sourceMappingURL=json.js.map
@@ -43,8 +43,6 @@ export interface ConsoleSummary {
43
43
  * Options for console formatting.
44
44
  */
45
45
  export interface ConsoleFormatOptions {
46
- /** Output as JSON */
47
- json?: boolean | undefined;
48
46
  /** List all messages chronologically (--list flag) */
49
47
  list?: boolean | undefined;
50
48
  /** Follow mode (live streaming) */
@@ -63,6 +61,8 @@ export interface ConsoleFormatOptions {
63
61
  dropped?: number | undefined;
64
62
  /** When the page crashed (epoch ms), while it is not loaded again */
65
63
  pageCrashedAt?: number | undefined;
64
+ /** Print message texts whole (`--full`) */
65
+ full?: boolean | undefined;
66
66
  }
67
67
  /** Distinct errors and warnings the summary lists without `--last` */
68
68
  export declare const DEFAULT_GROUP_LIMIT = 50;
@@ -95,6 +95,8 @@ export interface JsonErrorEntry {
95
95
  count: number;
96
96
  level: string;
97
97
  text: string;
98
+ /** Original length of `text` when it was cut (`--full` keeps it whole) */
99
+ truncatedFrom?: number;
98
100
  /** Position in the session's message list (what `details console <n>` takes) */
99
101
  index?: number;
100
102
  /** Where it came from; no line/column for a resource URL (e.g. a failed load) */
@@ -175,4 +177,17 @@ export declare function formatSectionHeader(label: string, unique: number, total
175
177
  * @returns Location text
176
178
  */
177
179
  export declare function formatFramePosition(frame: StackFrame): string;
180
+ /**
181
+ * A console message (or error entry) for JSON output: its text cut to
182
+ * {@link MAX_CONSOLE_JSON_TEXT_LENGTH} characters with `truncatedFrom`, or
183
+ * whole with `--full`.
184
+ *
185
+ * @param message - Message with a text
186
+ * @param full - `--full`: keep the text whole
187
+ * @returns The message, with the text cut when too long
188
+ */
189
+ export declare function capMessageText<T extends {
190
+ text: string;
191
+ truncatedFrom?: number;
192
+ }>(message: T, full: boolean | undefined): T;
178
193
  //# sourceMappingURL=shared.d.ts.map
@@ -1,6 +1,8 @@
1
1
  /**
2
2
  * Shared types, constants, and helpers used by every console formatter.
3
3
  */
4
+ import { MAX_CONSOLE_JSON_TEXT_LENGTH } from '../../../constants.js';
5
+ import { capLength } from '../../../utils/strings.js';
4
6
  /** Distinct errors and warnings the summary lists without `--last` */
5
7
  export const DEFAULT_GROUP_LIMIT = 50;
6
8
  /**
@@ -171,4 +173,19 @@ export function formatFramePosition(frame) {
171
173
  ? frame.url
172
174
  : `${frame.url}:${frame.lineNumber + 1}:${frame.columnNumber + 1}`;
173
175
  }
176
+ /**
177
+ * A console message (or error entry) for JSON output: its text cut to
178
+ * {@link MAX_CONSOLE_JSON_TEXT_LENGTH} characters with `truncatedFrom`, or
179
+ * whole with `--full`.
180
+ *
181
+ * @param message - Message with a text
182
+ * @param full - `--full`: keep the text whole
183
+ * @returns The message, with the text cut when too long
184
+ */
185
+ export function capMessageText(message, full) {
186
+ if (full)
187
+ return message;
188
+ const { text, truncatedFrom } = capLength(message.text, MAX_CONSOLE_JSON_TEXT_LENGTH);
189
+ return truncatedFrom === undefined ? message : { ...message, text, truncatedFrom };
190
+ }
174
191
  //# sourceMappingURL=shared.js.map
@@ -10,8 +10,8 @@ import { type ConsoleFormatOptions } from './shared.js';
10
10
  * dropped its oldest messages.
11
11
  *
12
12
  * @param messages - Messages to summarise
13
- * @param options - Distinct messages listed and messages dropped
13
+ * @param options - Distinct messages listed, messages dropped and `--full`
14
14
  * @returns Summary
15
15
  */
16
- export declare function formatConsoleSummary(messages: ConsoleMessage[], options?: Pick<ConsoleFormatOptions, 'groupLimit' | 'dropped'>): string;
16
+ export declare function formatConsoleSummary(messages: ConsoleMessage[], options?: Pick<ConsoleFormatOptions, 'groupLimit' | 'dropped' | 'full'>): string;
17
17
  //# sourceMappingURL=summarize.d.ts.map
@@ -2,9 +2,21 @@
2
2
  * Smart summary view: prioritises errors and warnings with deduplication
3
3
  * and shows info/debug/other as count-only footer entries.
4
4
  */
5
+ import { MAX_CONSOLE_TEXT_LENGTH } from '../../../constants.js';
6
+ import { capForDisplay } from '../longValues.js';
5
7
  import { OutputFormatter, pluralize } from '../../formatting.js';
6
8
  import { consoleDroppedNote, consoleMoreGroupsNote } from '../../messages/consoleMessages.js';
7
9
  import { analyzeMessages, formatCountPrefix, formatSectionHeader, formatSourceLocation, newestGroups, } from './shared.js';
10
+ /**
11
+ * A message's text cut like `console --list` cuts it, or whole with `--full`.
12
+ *
13
+ * @param message - Message
14
+ * @param full - `--full`
15
+ * @returns Text to print
16
+ */
17
+ function messageText(message, full) {
18
+ return capForDisplay(message.text, MAX_CONSOLE_TEXT_LENGTH, full);
19
+ }
8
20
  /**
9
21
  * The errors: the newest distinct ones, with a note for the earlier ones.
10
22
  *
@@ -12,8 +24,9 @@ import { analyzeMessages, formatCountPrefix, formatSectionHeader, formatSourceLo
12
24
  * @param errors - Distinct errors in order of first appearance
13
25
  * @param total - Errors logged
14
26
  * @param limit - Distinct errors listed (0 = all)
27
+ * @param full - Print the texts whole (`--full`)
15
28
  */
16
- function renderErrorSection(fmt, errors, total, limit) {
29
+ function renderErrorSection(fmt, errors, total, limit, full) {
17
30
  if (errors.length === 0)
18
31
  return;
19
32
  const { shown, more } = newestGroups(errors, limit);
@@ -22,7 +35,7 @@ function renderErrorSection(fmt, errors, total, limit) {
22
35
  if (more > 0)
23
36
  fmt.text(consoleMoreGroupsNote(more, 'error')).blank();
24
37
  for (const { message, count } of shown) {
25
- fmt.text(`${formatCountPrefix(count)}${message.text}`);
38
+ fmt.text(`${formatCountPrefix(count)}${messageText(message, full)}`);
26
39
  const source = formatSourceLocation(message.stackTrace);
27
40
  if (source) {
28
41
  fmt.text(` → ${source}`);
@@ -37,8 +50,9 @@ function renderErrorSection(fmt, errors, total, limit) {
37
50
  * @param warnings - Distinct warnings in order of first appearance
38
51
  * @param total - Warnings logged
39
52
  * @param limit - Distinct warnings listed (0 = all)
53
+ * @param full - Print the texts whole (`--full`)
40
54
  */
41
- function renderWarningSection(fmt, warnings, total, limit) {
55
+ function renderWarningSection(fmt, warnings, total, limit, full) {
42
56
  if (warnings.length === 0)
43
57
  return;
44
58
  const { shown, more } = newestGroups(warnings, limit);
@@ -47,7 +61,7 @@ function renderWarningSection(fmt, warnings, total, limit) {
47
61
  if (more > 0)
48
62
  fmt.text(consoleMoreGroupsNote(more, 'warning'));
49
63
  for (const { message, count } of shown) {
50
- fmt.text(`• ${formatCountPrefix(count)}${message.text}`);
64
+ fmt.text(`• ${formatCountPrefix(count)}${messageText(message, full)}`);
51
65
  const source = formatSourceLocation(message.stackTrace);
52
66
  if (source)
53
67
  fmt.text(` → ${source}`);
@@ -71,7 +85,7 @@ function renderOtherSummary(fmt, summary) {
71
85
  * dropped its oldest messages.
72
86
  *
73
87
  * @param messages - Messages to summarise
74
- * @param options - Distinct messages listed and messages dropped
88
+ * @param options - Distinct messages listed, messages dropped and `--full`
75
89
  * @returns Summary
76
90
  */
77
91
  export function formatConsoleSummary(messages, options = {}) {
@@ -82,8 +96,9 @@ export function formatConsoleSummary(messages, options = {}) {
82
96
  if (options.dropped)
83
97
  fmt.text(consoleDroppedNote(options.dropped));
84
98
  fmt.blank();
85
- renderErrorSection(fmt, grouped.errors, summary.errors.total, options.groupLimit);
86
- renderWarningSection(fmt, grouped.warnings, summary.warnings.total, options.groupLimit);
99
+ const { groupLimit, full } = options;
100
+ renderErrorSection(fmt, grouped.errors, summary.errors.total, groupLimit, full);
101
+ renderWarningSection(fmt, grouped.warnings, summary.warnings.total, groupLimit, full);
87
102
  if (grouped.errors.length === 0 && grouped.warnings.length === 0) {
88
103
  fmt.text('No errors or warnings found');
89
104
  fmt.blank();
@@ -11,7 +11,7 @@ export type { ConsoleFormatOptions, ConsoleJsonOutput, ConsoleLevel, ConsoleSkip
11
11
  export { LEVEL_MAP } from './console/shared.js';
12
12
  export { formatConsoleChronological, lastMessages } from './console/chronological.js';
13
13
  export { formatConsoleFollowLines } from './console/follow.js';
14
- export { buildConsoleJsonOutput, formatConsoleJson } from './console/json.js';
14
+ export { buildConsoleJsonOutput } from './console/json.js';
15
15
  export { formatConsoleSummary } from './console/summarize.js';
16
16
  /**
17
17
  * Format console output based on options. Routes to the per-mode formatter:
@@ -7,12 +7,11 @@
7
7
  */
8
8
  import { withPageCrashedNote } from '../messages/commands.js';
9
9
  import { formatConsoleChronological } from './console/chronological.js';
10
- import { formatConsoleJson } from './console/json.js';
11
10
  import { formatConsoleSummary } from './console/summarize.js';
12
11
  export { LEVEL_MAP } from './console/shared.js';
13
12
  export { formatConsoleChronological, lastMessages } from './console/chronological.js';
14
13
  export { formatConsoleFollowLines } from './console/follow.js';
15
- export { buildConsoleJsonOutput, formatConsoleJson } from './console/json.js';
14
+ export { buildConsoleJsonOutput } from './console/json.js';
16
15
  export { formatConsoleSummary } from './console/summarize.js';
17
16
  /**
18
17
  * Format console output based on options. Routes to the per-mode formatter:
@@ -21,9 +20,6 @@ export { formatConsoleSummary } from './console/summarize.js';
21
20
  * starts with a warning when the page crashed.
22
21
  */
23
22
  export function formatConsole(messages, options) {
24
- if (options.json) {
25
- return formatConsoleJson(messages, options);
26
- }
27
23
  const body = options.list || options.level
28
24
  ? formatConsoleChronological(messages, options)
29
25
  : formatConsoleSummary(messages, options);
@@ -1,4 +1,4 @@
1
- import { skippedBodyReason } from '../../telemetry/network.js';
1
+ import { skippedBodyReason } from '../../telemetry/networkRetention.js';
2
2
  import { formatFramePosition, formatTimestamp } from './console/shared.js';
3
3
  import { headerValueLines } from './networkHeaders.js';
4
4
  import { formatRequestStatus } from './requestStatus.js';
@@ -33,10 +33,13 @@ export declare function formatDomQuery(data: DomQueryResult): string;
33
33
  /**
34
34
  * Format DOM get results for human-readable output.
35
35
  *
36
- * Displays full outerHTML for matched elements. For single elements, shows HTML directly.
37
- * For multiple elements, shows numbered list with HTML for each.
36
+ * Displays the outerHTML of matched elements, each cut to its first
37
+ * {@link MAX_VALUE_LENGTH} characters with a pointer naming `--full`. For
38
+ * single elements, shows HTML directly. For multiple elements, shows
39
+ * numbered list with HTML for each.
38
40
  *
39
41
  * @param data - DOM get result containing array of nodes with outerHTML
42
+ * @param options - `full` to print the HTML whole
40
43
  * @returns Formatted output string
41
44
  *
42
45
  * @example
@@ -59,7 +62,9 @@ export declare function formatDomQuery(data: DomQueryResult): string;
59
62
  * // [1] <span class="error">Error 2</span>
60
63
  * ```
61
64
  */
62
- export declare function formatDomGet(data: DomGetResult): string;
65
+ export declare function formatDomGet(data: DomGetResult, options?: {
66
+ full?: boolean | undefined;
67
+ }): string;
63
68
  /**
64
69
  * Format DOM eval results for human-readable output.
65
70
  *
@@ -69,9 +74,11 @@ export declare function formatDomGet(data: DomGetResult): string;
69
74
  * JSON-quoted. Other values are formatted JSON, and values Chrome only
70
75
  * describes (functions, DOM nodes) their description. The iframe it ran in
71
76
  * (`--frame`) is reported on stderr, so stdout stays the bare value. `--json`
72
- * output is unchanged (the value in `data.result`).
77
+ * output is unchanged (the value in `data.result`). The text is cut to its
78
+ * first {@link MAX_VALUE_LENGTH} characters with a pointer naming `--full`.
73
79
  *
74
80
  * @param data - DOM eval result containing the evaluated value
81
+ * @param options - `full` to print the value whole
75
82
  * @returns The string, or formatted JSON
76
83
  *
77
84
  * @example
@@ -90,6 +97,8 @@ export declare function formatDomGet(data: DomGetResult): string;
90
97
  export declare function formatDomEval(data: {
91
98
  result: unknown;
92
99
  type?: string;
100
+ }, options?: {
101
+ full?: boolean | undefined;
93
102
  }): string;
94
103
  /**
95
104
  * Format the page's iframes, one per line, nested frames indented below
@@ -1,4 +1,6 @@
1
+ import { MAX_VALUE_LENGTH } from '../../constants.js';
1
2
  import { keyAttributeItems } from './keyAttributes.js';
3
+ import { capForDisplay } from './longValues.js';
2
4
  import { OutputFormatter } from '../formatting.js';
3
5
  import { frameLabel, framesStillLoadingNote, noFramesMessage, queryMoreMatchesNote, queryViewportCheckedNote, queryNextSteps, screenshotGrownNote, screenshotScaledNote, viewportPositionHint, } from '../messages/commands.js';
4
6
  /**
@@ -75,10 +77,13 @@ function queryTagAttributes(node) {
75
77
  /**
76
78
  * Format DOM get results for human-readable output.
77
79
  *
78
- * Displays full outerHTML for matched elements. For single elements, shows HTML directly.
79
- * For multiple elements, shows numbered list with HTML for each.
80
+ * Displays the outerHTML of matched elements, each cut to its first
81
+ * {@link MAX_VALUE_LENGTH} characters with a pointer naming `--full`. For
82
+ * single elements, shows HTML directly. For multiple elements, shows
83
+ * numbered list with HTML for each.
80
84
  *
81
85
  * @param data - DOM get result containing array of nodes with outerHTML
86
+ * @param options - `full` to print the HTML whole
82
87
  * @returns Formatted output string
83
88
  *
84
89
  * @example
@@ -101,15 +106,16 @@ function queryTagAttributes(node) {
101
106
  * // [1] <span class="error">Error 2</span>
102
107
  * ```
103
108
  */
104
- export function formatDomGet(data) {
109
+ export function formatDomGet(data, options = {}) {
105
110
  const { nodes } = data;
111
+ const html = (node) => capForDisplay(node.outerHTML ?? '', MAX_VALUE_LENGTH, options.full);
106
112
  if (nodes.length === 1) {
107
113
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
108
- return nodes[0].outerHTML ?? '';
114
+ return html(nodes[0]);
109
115
  }
110
116
  const fmt = new OutputFormatter();
111
117
  nodes.forEach((node, i) => {
112
- fmt.text(`[${i}] ${node.outerHTML}`);
118
+ fmt.text(`[${i}] ${html(node)}`);
113
119
  });
114
120
  return fmt.build();
115
121
  }
@@ -122,9 +128,11 @@ export function formatDomGet(data) {
122
128
  * JSON-quoted. Other values are formatted JSON, and values Chrome only
123
129
  * describes (functions, DOM nodes) their description. The iframe it ran in
124
130
  * (`--frame`) is reported on stderr, so stdout stays the bare value. `--json`
125
- * output is unchanged (the value in `data.result`).
131
+ * output is unchanged (the value in `data.result`). The text is cut to its
132
+ * first {@link MAX_VALUE_LENGTH} characters with a pointer naming `--full`.
126
133
  *
127
134
  * @param data - DOM eval result containing the evaluated value
135
+ * @param options - `full` to print the value whole
128
136
  * @returns The string, or formatted JSON
129
137
  *
130
138
  * @example
@@ -140,7 +148,17 @@ export function formatDomGet(data) {
140
148
  * // }
141
149
  * ```
142
150
  */
143
- export function formatDomEval(data) {
151
+ export function formatDomEval(data, options = {}) {
152
+ return capForDisplay(evalResultText(data), MAX_VALUE_LENGTH, options.full);
153
+ }
154
+ /**
155
+ * An eval result as text: a string as is unless it would read as another
156
+ * value, else formatted JSON.
157
+ *
158
+ * @param data - DOM eval result
159
+ * @returns Text of the value
160
+ */
161
+ function evalResultText(data) {
144
162
  if (data.type === 'undefined')
145
163
  return 'undefined';
146
164
  const { result } = data;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Human-readable output of `bdg dom layout`.
3
3
  */
4
+ import { LAYOUT_ELEMENT_LIMIT } from '../../constants.js';
4
5
  import { indexSourceText } from '../../errors/messages.js';
5
6
  import { OutputFormatter } from '../formatting.js';
6
7
  import { coverText, indexLayoutHeadline, layoutHeadline, layoutPositionLabel, maskedText, moreMatchesNote, pageLayoutLine, } from '../messages/commands.js';
@@ -48,7 +49,7 @@ export function formatLayout(data) {
48
49
  ? indexLayoutHeadline(indexSourceText(data.indexSource))
49
50
  : layoutHeadline(data.count, data.elements.length + (data.omitted ?? 0), data.selector))
50
51
  .list(shown.map((element) => layoutLine(element, data.page.viewport)))
51
- .list(more > 0 ? [moreMatchesNote(more, data.omitted ? data.elements.length : undefined)] : [])
52
+ .list(more > 0 ? [moreMatchesNote(more, LAYOUT_ELEMENT_LIMIT)] : [])
52
53
  .build();
53
54
  }
54
55
  //# sourceMappingURL=layout.js.map