browser-debugger-cli 0.12.0 → 0.14.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 (224) hide show
  1. package/.claude/skills/bdg/SKILL.md +100 -186
  2. package/README.md +5 -4
  3. package/dist/commands/cdp.d.ts +22 -1
  4. package/dist/commands/cdp.js +100 -43
  5. package/dist/commands/console.d.ts +12 -0
  6. package/dist/commands/console.js +67 -13
  7. package/dist/commands/dom/DomElementResolver.d.ts +3 -1
  8. package/dist/commands/dom/DomElementResolver.js +10 -3
  9. package/dist/commands/dom/a11y.d.ts +1 -1
  10. package/dist/commands/dom/a11y.js +23 -22
  11. package/dist/commands/dom/eval.d.ts +4 -2
  12. package/dist/commands/dom/eval.js +31 -7
  13. package/dist/commands/dom/form.js +10 -9
  14. package/dist/commands/dom/formInteraction.js +9 -8
  15. package/dist/commands/dom/get.js +32 -14
  16. package/dist/commands/dom/helpers/index.d.ts +1 -1
  17. package/dist/commands/dom/helpers/index.js +1 -1
  18. package/dist/commands/dom/helpers/query.d.ts +27 -3
  19. package/dist/commands/dom/helpers/query.js +152 -64
  20. package/dist/commands/dom/helpers/screenshot.js +13 -13
  21. package/dist/commands/dom/index.js +10 -3
  22. package/dist/commands/dom/query.d.ts +20 -2
  23. package/dist/commands/dom/query.js +39 -6
  24. package/dist/commands/dom/screenshot.js +3 -1
  25. package/dist/commands/dom/semanticUtils.d.ts +3 -2
  26. package/dist/commands/dom/semanticUtils.js +40 -9
  27. package/dist/commands/helpJson.d.ts +82 -19
  28. package/dist/commands/helpJson.js +112 -41
  29. package/dist/commands/helpTopic.d.ts +16 -1
  30. package/dist/commands/helpTopic.js +59 -1
  31. package/dist/commands/installSkill.d.ts +15 -5
  32. package/dist/commands/installSkill.js +86 -16
  33. package/dist/commands/network/list.js +65 -12
  34. package/dist/commands/optionBehaviors.d.ts +25 -2
  35. package/dist/commands/optionBehaviors.js +81 -46
  36. package/dist/commands/peek.js +3 -0
  37. package/dist/commands/shared/CommandRunner.js +13 -13
  38. package/dist/commands/shared/daemonErrorHandler.d.ts +5 -2
  39. package/dist/commands/shared/daemonErrorHandler.js +21 -10
  40. package/dist/commands/shared/dataFetcher.d.ts +14 -4
  41. package/dist/commands/shared/dataFetcher.js +20 -4
  42. package/dist/commands/shared/followMode.d.ts +9 -1
  43. package/dist/commands/shared/followMode.js +22 -4
  44. package/dist/commands/shared/handleValidationError.js +3 -3
  45. package/dist/commands/shared/optionTypes.d.ts +17 -3
  46. package/dist/commands/shared/outputFile.js +6 -1
  47. package/dist/commands/shared/startHelpers.js +3 -3
  48. package/dist/commands/start.d.ts +7 -5
  49. package/dist/commands/start.js +65 -21
  50. package/dist/commands/stop.d.ts +11 -0
  51. package/dist/commands/stop.js +24 -1
  52. package/dist/commands.js +1 -1
  53. package/dist/connection/cdp.d.ts +7 -0
  54. package/dist/connection/cdp.js +9 -0
  55. package/dist/connection/chromeIdentity.d.ts +8 -2
  56. package/dist/connection/chromeIdentity.js +85 -13
  57. package/dist/connection/launcher.js +3 -2
  58. package/dist/constants.d.ts +29 -1
  59. package/dist/constants.js +35 -1
  60. package/dist/daemon/SessionController.js +8 -1
  61. package/dist/daemon/launcher.d.ts +3 -2
  62. package/dist/daemon/launcher.js +47 -3
  63. package/dist/daemon/session/Session.d.ts +5 -1
  64. package/dist/daemon/session/Session.js +42 -3
  65. package/dist/daemon/session/TelemetryStore.d.ts +15 -1
  66. package/dist/daemon/session/TelemetryStore.js +19 -1
  67. package/dist/daemon/session/commandRegistry.js +52 -18
  68. package/dist/daemon/session/interactions.d.ts +2 -1
  69. package/dist/daemon/session/interactions.js +13 -1
  70. package/dist/daemon/session/matchedStylesReset.d.ts +26 -0
  71. package/dist/daemon/session/matchedStylesReset.js +46 -0
  72. package/dist/daemon/session/plugins.js +17 -2
  73. package/dist/daemon/session/teardown.js +1 -1
  74. package/dist/daemon/session/triggeredRequests.d.ts +0 -5
  75. package/dist/daemon/session/triggeredRequests.js +13 -7
  76. package/dist/daemon.js +2385 -1229
  77. package/dist/errors/messages.d.ts +62 -11
  78. package/dist/errors/messages.js +119 -22
  79. package/dist/index.js +14995 -9866
  80. package/dist/ipc/client.d.ts +18 -2
  81. package/dist/ipc/client.js +26 -5
  82. package/dist/ipc/protocol/auditTypes.d.ts +8 -2
  83. package/dist/ipc/protocol/commands.d.ts +16 -0
  84. package/dist/ipc/protocol/domTypes.d.ts +12 -0
  85. package/dist/ipc/protocol/inspectTypes.d.ts +7 -2
  86. package/dist/ipc/session/types.d.ts +7 -1
  87. package/dist/program.d.ts +14 -0
  88. package/dist/program.js +53 -0
  89. package/dist/runtime/dom/actionEffects.d.ts +5 -1
  90. package/dist/runtime/dom/actionEffects.js +26 -14
  91. package/dist/runtime/dom/audit.js +3 -2
  92. package/dist/runtime/dom/auditModel.js +6 -1
  93. package/dist/runtime/dom/auditScripts.d.ts +9 -3
  94. package/dist/runtime/dom/auditScripts.js +41 -5
  95. package/dist/runtime/dom/elementGeometry.d.ts +33 -3
  96. package/dist/runtime/dom/elementGeometry.js +44 -19
  97. package/dist/runtime/dom/elementInfo.d.ts +76 -18
  98. package/dist/runtime/dom/elementInfo.js +190 -40
  99. package/dist/runtime/dom/evalHelpers.d.ts +12 -2
  100. package/dist/runtime/dom/evalHelpers.js +67 -7
  101. package/dist/runtime/dom/formDiscovery.d.ts +6 -2
  102. package/dist/runtime/dom/formDiscovery.js +20 -3
  103. package/dist/runtime/dom/formFillHelpers/fill.js +7 -11
  104. package/dist/runtime/dom/formFillHelpers/pressKey.js +2 -2
  105. package/dist/runtime/dom/formFillHelpers/shared.d.ts +16 -10
  106. package/dist/runtime/dom/formFillHelpers/shared.js +19 -52
  107. package/dist/runtime/dom/formSubmitHelpers.js +4 -3
  108. package/dist/runtime/dom/frameLayout.js +1 -0
  109. package/dist/runtime/dom/frameScopedConnection.d.ts +7 -0
  110. package/dist/runtime/dom/frameScopedConnection.js +2 -2
  111. package/dist/runtime/dom/inspect.d.ts +17 -3
  112. package/dist/runtime/dom/inspect.js +45 -32
  113. package/dist/runtime/dom/inspectAllStyles.js +1 -0
  114. package/dist/runtime/dom/inspectHints.d.ts +1 -1
  115. package/dist/runtime/dom/inspectModel.d.ts +5 -4
  116. package/dist/runtime/dom/inspectModel.js +7 -3
  117. package/dist/runtime/dom/inspectPaintModel.d.ts +2 -0
  118. package/dist/runtime/dom/inspectPaintModel.js +3 -1
  119. package/dist/runtime/dom/inspectRules.d.ts +29 -3
  120. package/dist/runtime/dom/inspectRules.js +205 -11
  121. package/dist/runtime/dom/inspectScripts.d.ts +29 -2
  122. package/dist/runtime/dom/inspectScripts.js +49 -10
  123. package/dist/runtime/dom/layout.d.ts +0 -2
  124. package/dist/runtime/dom/layout.js +10 -9
  125. package/dist/runtime/dom/reactEventHelpers.d.ts +17 -4
  126. package/dist/runtime/dom/reactEventHelpers.js +71 -28
  127. package/dist/runtime/dom/targetNode.d.ts +27 -10
  128. package/dist/runtime/dom/targetNode.js +283 -16
  129. package/dist/runtime/dom/wait.js +2 -1
  130. package/dist/runtime/page/bdgWorld.d.ts +57 -0
  131. package/dist/runtime/page/bdgWorld.js +180 -0
  132. package/dist/runtime/page/replacedBuiltins.d.ts +28 -0
  133. package/dist/runtime/page/replacedBuiltins.js +136 -0
  134. package/dist/session/QueryCacheManager.d.ts +4 -1
  135. package/dist/session/QueryCacheManager.js +5 -2
  136. package/dist/session/chrome.d.ts +4 -1
  137. package/dist/session/chrome.js +7 -1
  138. package/dist/session/cleanup/staleSession.d.ts +21 -4
  139. package/dist/session/cleanup/staleSession.js +79 -9
  140. package/dist/session/cleanup/userCommands.d.ts +4 -1
  141. package/dist/session/cleanup/userCommands.js +10 -5
  142. package/dist/session/daemonSocket.d.ts +10 -0
  143. package/dist/session/daemonSocket.js +22 -0
  144. package/dist/session/lastSession.d.ts +6 -3
  145. package/dist/session/lastSession.js +11 -5
  146. package/dist/session/paths.d.ts +3 -1
  147. package/dist/session/paths.js +5 -5
  148. package/dist/session/portClaims.js +4 -3
  149. package/dist/session/sessionList.d.ts +13 -5
  150. package/dist/session/sessionList.js +31 -7
  151. package/dist/telemetry/a11y.d.ts +15 -1
  152. package/dist/telemetry/a11y.js +85 -2
  153. package/dist/telemetry/console.d.ts +2 -1
  154. package/dist/telemetry/console.js +30 -21
  155. package/dist/telemetry/har/builder.js +1 -1
  156. package/dist/telemetry/network.d.ts +13 -16
  157. package/dist/telemetry/network.js +30 -52
  158. package/dist/telemetry/networkRetention.d.ts +83 -0
  159. package/dist/telemetry/networkRetention.js +117 -0
  160. package/dist/telemetry/pageCrash.d.ts +26 -0
  161. package/dist/telemetry/pageCrash.js +53 -0
  162. package/dist/types.d.ts +42 -0
  163. package/dist/ui/OutputBuilder.d.ts +10 -0
  164. package/dist/ui/OutputBuilder.js +12 -0
  165. package/dist/ui/formatters/a11y.d.ts +5 -7
  166. package/dist/ui/formatters/a11y.js +7 -61
  167. package/dist/ui/formatters/audit.js +14 -5
  168. package/dist/ui/formatters/cdp.d.ts +138 -0
  169. package/dist/ui/formatters/cdp.js +131 -0
  170. package/dist/ui/formatters/console/chronological.js +7 -5
  171. package/dist/ui/formatters/console/follow.d.ts +5 -2
  172. package/dist/ui/formatters/console/follow.js +7 -4
  173. package/dist/ui/formatters/console/json.d.ts +4 -7
  174. package/dist/ui/formatters/console/json.js +16 -14
  175. package/dist/ui/formatters/console/shared.d.ts +47 -2
  176. package/dist/ui/formatters/console/shared.js +33 -0
  177. package/dist/ui/formatters/console/summarize.d.ts +9 -2
  178. package/dist/ui/formatters/console/summarize.js +57 -11
  179. package/dist/ui/formatters/console.d.ts +3 -2
  180. package/dist/ui/formatters/console.js +8 -10
  181. package/dist/ui/formatters/details.js +4 -2
  182. package/dist/ui/formatters/dom.d.ts +14 -5
  183. package/dist/ui/formatters/dom.js +30 -13
  184. package/dist/ui/formatters/helpFormatters.js +1 -1
  185. package/dist/ui/formatters/inspect.js +9 -3
  186. package/dist/ui/formatters/installSkill.d.ts +9 -1
  187. package/dist/ui/formatters/installSkill.js +32 -6
  188. package/dist/ui/formatters/layout.js +4 -2
  189. package/dist/ui/formatters/longValues.d.ts +14 -0
  190. package/dist/ui/formatters/longValues.js +23 -0
  191. package/dist/ui/formatters/networkList.d.ts +8 -2
  192. package/dist/ui/formatters/networkList.js +11 -3
  193. package/dist/ui/formatters/preview.d.ts +6 -1
  194. package/dist/ui/formatters/preview.js +67 -15
  195. package/dist/ui/formatters/sessions.d.ts +2 -2
  196. package/dist/ui/formatters/sessions.js +9 -2
  197. package/dist/ui/formatters/status.js +7 -0
  198. package/dist/ui/formatters/triggeredRequests.js +2 -1
  199. package/dist/ui/logging/logger.d.ts +1 -1
  200. package/dist/ui/messages/chrome.d.ts +20 -1
  201. package/dist/ui/messages/chrome.js +29 -3
  202. package/dist/ui/messages/commands.d.ts +153 -12
  203. package/dist/ui/messages/commands.js +198 -15
  204. package/dist/ui/messages/consoleMessages.d.ts +24 -0
  205. package/dist/ui/messages/consoleMessages.js +32 -0
  206. package/dist/ui/messages/networkMessages.d.ts +24 -0
  207. package/dist/ui/messages/networkMessages.js +45 -0
  208. package/dist/ui/messages/preview.d.ts +6 -0
  209. package/dist/ui/messages/preview.js +9 -1
  210. package/dist/ui/messages/session.d.ts +13 -2
  211. package/dist/ui/messages/session.js +22 -3
  212. package/dist/utils/directories.d.ts +34 -0
  213. package/dist/utils/directories.js +88 -0
  214. package/dist/utils/display.d.ts +16 -0
  215. package/dist/utils/display.js +42 -0
  216. package/dist/utils/exitCodes.d.ts +1 -0
  217. package/dist/utils/exitCodes.js +6 -0
  218. package/dist/utils/http.d.ts +9 -2
  219. package/dist/utils/http.js +4 -3
  220. package/dist/utils/process.d.ts +12 -0
  221. package/dist/utils/process.js +25 -0
  222. package/dist/utils/strings.d.ts +19 -0
  223. package/dist/utils/strings.js +16 -0
  224. package/package.json +2 -2
@@ -0,0 +1,138 @@
1
+ /**
2
+ * Human-readable output of `bdg cdp`: search results, domain and method
3
+ * lists, method schemas and method results (`--json` prints the data as is).
4
+ */
5
+ import type { ParameterSchema, ReturnSchema } from '../../cdp/schema.js';
6
+ /** Protocol description and flags shared by domains and methods */
7
+ interface ProtocolEntry {
8
+ description?: string | undefined;
9
+ experimental?: boolean | undefined;
10
+ deprecated?: boolean | undefined;
11
+ }
12
+ /** A method in `bdg cdp --search` results */
13
+ interface CdpSearchMethod extends ProtocolEntry {
14
+ name: string;
15
+ domain: string;
16
+ method: string;
17
+ parameterCount: number;
18
+ example?: string | undefined;
19
+ }
20
+ /** `bdg cdp --search <query>` result */
21
+ export interface CdpSearchData {
22
+ query: string;
23
+ count: number;
24
+ methods: CdpSearchMethod[];
25
+ }
26
+ /** A domain in `bdg cdp --list` */
27
+ interface CdpDomainEntry extends ProtocolEntry {
28
+ name: string;
29
+ commands: number;
30
+ events: number;
31
+ dependencies?: string[] | undefined;
32
+ }
33
+ /** `bdg cdp --list` result */
34
+ export interface CdpDomainListData {
35
+ count: number;
36
+ domains: CdpDomainEntry[];
37
+ }
38
+ /** A method in `bdg cdp <Domain> --list` */
39
+ interface CdpDomainMethod extends ProtocolEntry {
40
+ name: string;
41
+ fullName: string;
42
+ parameterCount: number;
43
+ parameters: Pick<ParameterSchema, 'name' | 'type' | 'required'>[];
44
+ returns: Pick<ReturnSchema, 'name' | 'type'>[];
45
+ example?: string | undefined;
46
+ }
47
+ /** `bdg cdp <Domain> --list` result */
48
+ export interface CdpDomainMethodsData {
49
+ domain: string;
50
+ description?: string | undefined;
51
+ count: number;
52
+ methods: CdpDomainMethod[];
53
+ }
54
+ /** `bdg cdp <Domain> --describe` result */
55
+ export interface CdpDomainDescription extends ProtocolEntry {
56
+ type: 'domain';
57
+ domain: string;
58
+ commands: number;
59
+ events: number;
60
+ note?: string | undefined;
61
+ nextStep: string;
62
+ }
63
+ /** A parameter or return value in `bdg cdp <Domain.method> --describe` */
64
+ interface CdpField {
65
+ name: string;
66
+ type: string;
67
+ description?: string | undefined;
68
+ items?: string | undefined;
69
+ }
70
+ /** `bdg cdp <Domain.method> --describe` result */
71
+ export interface CdpMethodDescription extends ProtocolEntry {
72
+ type: 'method';
73
+ name: string;
74
+ domain: string;
75
+ method: string;
76
+ note?: string | undefined;
77
+ parameters: (CdpField & {
78
+ required: boolean;
79
+ enum?: string[] | undefined;
80
+ deprecated?: boolean | undefined;
81
+ })[];
82
+ returns: (CdpField & {
83
+ optional: boolean;
84
+ })[];
85
+ example?: {
86
+ command: string;
87
+ params?: Record<string, unknown> | undefined;
88
+ } | undefined;
89
+ }
90
+ /** `bdg cdp <Domain.method>` result */
91
+ export interface CdpExecuteData {
92
+ method: string;
93
+ result: unknown;
94
+ }
95
+ /**
96
+ * Format `bdg cdp --search <query>`.
97
+ *
98
+ * @param data - Search result
99
+ * @returns Matching methods with their first description sentence
100
+ */
101
+ export declare function formatCdpSearch(data: CdpSearchData): string;
102
+ /**
103
+ * Format `bdg cdp --list`.
104
+ *
105
+ * @param data - All domains
106
+ * @returns One line per domain with its method and event counts
107
+ */
108
+ export declare function formatCdpDomains(data: CdpDomainListData): string;
109
+ /**
110
+ * Format `bdg cdp <Domain> --list`.
111
+ *
112
+ * @param data - The domain's methods
113
+ * @returns One line per method with the first sentence of its description
114
+ */
115
+ export declare function formatCdpDomainMethods(data: CdpDomainMethodsData): string;
116
+ /**
117
+ * Format `bdg cdp <Domain.method> --describe` or `bdg cdp <Domain> --describe`.
118
+ *
119
+ * @param data - Method or domain description
120
+ * @returns Description, parameters (`?` = optional), returns, note and example
121
+ */
122
+ export declare function formatCdpDescription(data: CdpMethodDescription | CdpDomainDescription): string;
123
+ /**
124
+ * Whether a CDP method returned nothing (null, undefined or an empty object).
125
+ *
126
+ * @param result - Method result
127
+ * @returns True for an empty result
128
+ */
129
+ export declare function isEmptyCdpResult(result: unknown): boolean;
130
+ /**
131
+ * Format a CDP method's result: the result object as indented JSON.
132
+ *
133
+ * @param data - Method and its result
134
+ * @returns The result, or a line saying the method returned nothing
135
+ */
136
+ export declare function formatCdpResult(data: CdpExecuteData): string;
137
+ export {};
138
+ //# sourceMappingURL=cdp.d.ts.map
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Human-readable output of `bdg cdp`: search results, domain and method
3
+ * lists, method schemas and method results (`--json` prints the data as is).
4
+ */
5
+ import { joinLines, pluralize } from '../formatting.js';
6
+ /**
7
+ * First sentence (or line) of a protocol description.
8
+ *
9
+ * @param description - Description, possibly multi-line
10
+ * @returns Its first sentence, or an empty string
11
+ */
12
+ function firstSentence(description) {
13
+ const [line = ''] = (description ?? '').split('\n');
14
+ const end = line.indexOf('. ');
15
+ return end === -1 ? line : line.slice(0, end + 1);
16
+ }
17
+ /**
18
+ * `(experimental, deprecated)` tags, or nothing.
19
+ *
20
+ * @param flags - Protocol flags
21
+ * @returns Tag text with a leading space, or an empty string
22
+ */
23
+ function tags(flags) {
24
+ const names = [flags.experimental && 'experimental', flags.deprecated && 'deprecated'].filter(Boolean);
25
+ return names.length > 0 ? ` (${names.join(', ')})` : '';
26
+ }
27
+ /**
28
+ * Rows of a name column padded to one width, then the rest.
29
+ *
30
+ * @param rows - Name and text of each row
31
+ * @returns Indented lines
32
+ */
33
+ function columns(rows) {
34
+ const width = Math.max(0, ...rows.map(([name]) => name.length));
35
+ return rows.map(([name, text]) => ` ${name.padEnd(width)} ${text.trim()}`.trimEnd());
36
+ }
37
+ /**
38
+ * A type as written in the schema, e.g. "array<Cookie>".
39
+ *
40
+ * @param field - Parameter or return value
41
+ * @returns Type text
42
+ */
43
+ function typeText(field) {
44
+ return field.items ? `${field.type}<${field.items}>` : field.type;
45
+ }
46
+ /**
47
+ * Format `bdg cdp --search <query>`.
48
+ *
49
+ * @param data - Search result
50
+ * @returns Matching methods with their first description sentence
51
+ */
52
+ export function formatCdpSearch(data) {
53
+ if (data.count === 0) {
54
+ return joinLines(`No CDP method matches "${data.query}"`, 'List the domains: bdg cdp --list');
55
+ }
56
+ return joinLines(`${pluralize(data.count, 'method')} ${data.count === 1 ? 'matches' : 'match'} "${data.query}":`, ...columns(data.methods.map((m) => [m.name, `${firstSentence(m.description)}${tags(m)}`])), 'Parameters and an example: bdg cdp <Domain.method> --describe');
57
+ }
58
+ /**
59
+ * Format `bdg cdp --list`.
60
+ *
61
+ * @param data - All domains
62
+ * @returns One line per domain with its method and event counts
63
+ */
64
+ export function formatCdpDomains(data) {
65
+ return joinLines(`${pluralize(data.count, 'CDP domain')}:`, ...columns(data.domains.map((d) => [
66
+ d.name,
67
+ `${pluralize(d.commands, 'method')}, ${pluralize(d.events, 'event')}${tags(d)}`,
68
+ ])), 'Methods of a domain: bdg cdp <Domain> --list');
69
+ }
70
+ /**
71
+ * Format `bdg cdp <Domain> --list`.
72
+ *
73
+ * @param data - The domain's methods
74
+ * @returns One line per method with the first sentence of its description
75
+ */
76
+ export function formatCdpDomainMethods(data) {
77
+ return joinLines(`${data.domain}: ${pluralize(data.count, 'method')}`, firstSentence(data.description) || undefined, ...columns(data.methods.map((m) => [m.name, `${firstSentence(m.description)}${tags(m)}`])), `Parameters and an example: bdg cdp ${data.domain}.<method> --describe`);
78
+ }
79
+ /**
80
+ * Lines of a parameter or return value list.
81
+ *
82
+ * @param title - Section title
83
+ * @param fields - Parameters or return values
84
+ * @returns Title and one line per field, or nothing for an empty list
85
+ */
86
+ function fieldSection(title, fields) {
87
+ if (fields.length === 0)
88
+ return [];
89
+ return [
90
+ `${title}:`,
91
+ ...columns(fields.map((f) => [
92
+ `${f.name}${f.optional ? '?' : ''}: ${typeText(f)}`,
93
+ (f.description ?? '').replace(/\s*\n\s*/g, ' '),
94
+ ])),
95
+ ];
96
+ }
97
+ /**
98
+ * Format `bdg cdp <Domain.method> --describe` or `bdg cdp <Domain> --describe`.
99
+ *
100
+ * @param data - Method or domain description
101
+ * @returns Description, parameters (`?` = optional), returns, note and example
102
+ */
103
+ export function formatCdpDescription(data) {
104
+ if (data.type === 'domain') {
105
+ return joinLines(`${data.domain}: ${pluralize(data.commands, 'method')}, ${pluralize(data.events, 'event')}${tags(data)}`, data.description, data.note, data.nextStep);
106
+ }
107
+ return joinLines(`${data.name}${tags(data)}`, data.description, ...fieldSection('Parameters', data.parameters.map((p) => ({ ...p, optional: !p.required }))), ...fieldSection('Returns', data.returns), data.note && `Note: ${data.note}`, data.example && `Example: ${data.example.command}`);
108
+ }
109
+ /**
110
+ * Whether a CDP method returned nothing (null, undefined or an empty object).
111
+ *
112
+ * @param result - Method result
113
+ * @returns True for an empty result
114
+ */
115
+ export function isEmptyCdpResult(result) {
116
+ return (result === null ||
117
+ result === undefined ||
118
+ (typeof result === 'object' && Object.keys(result).length === 0));
119
+ }
120
+ /**
121
+ * Format a CDP method's result: the result object as indented JSON.
122
+ *
123
+ * @param data - Method and its result
124
+ * @returns The result, or a line saying the method returned nothing
125
+ */
126
+ export function formatCdpResult(data) {
127
+ return isEmptyCdpResult(data.result)
128
+ ? `${data.method}: done (no result data)`
129
+ : JSON.stringify(data.result, null, 2);
130
+ }
131
+ //# sourceMappingURL=cdp.js.map
@@ -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
- import { consoleIndexGapNote } from '../../messages/consoleMessages.js';
7
- import { truncateByLength } from '../../../utils/strings.js';
8
+ import { consoleDroppedNote, consoleIndexGapNote } from '../../messages/consoleMessages.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
  *
@@ -22,6 +22,8 @@ export function formatConsoleChronological(messages, options) {
22
22
  : `Console Messages (last ${displayMessages.length} of ${messages.length})${headerSuffix}`;
23
23
  fmt.text(header);
24
24
  fmt.separator('━', 50);
25
+ if (options.dropped)
26
+ fmt.text(consoleDroppedNote(options.dropped));
25
27
  if (displayMessages.length === 0) {
26
28
  fmt.text('No console messages');
27
29
  return fmt.build();
@@ -44,8 +46,8 @@ export function formatConsoleChronological(messages, options) {
44
46
  }
45
47
  lastNavigationId = msg.navigationId;
46
48
  }
47
- const truncatedText = truncateByLength(msg.text, MAX_LIST_TEXT_LENGTH);
48
- 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}`);
49
51
  const source = formatSourceLocation(msg.stackTrace);
50
52
  if (source) {
51
53
  fmt.text(`${sourceIndent}→ ${source}`);
@@ -5,14 +5,17 @@
5
5
  import type { ConsoleMessage } from '../../../types.js';
6
6
  /**
7
7
  * Lines of the console stream: the new messages since the last poll, with
8
- * the stream header the first time and a separator after a navigation.
8
+ * a rule the first time (the stream banner is on stderr) and a separator
9
+ * after a navigation. Texts are cut like `console --list` cuts them.
9
10
  *
10
11
  * @param messages - New messages
11
- * @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
12
14
  * @returns Text to print (empty when there is nothing new)
13
15
  */
14
16
  export declare function formatConsoleFollowLines(messages: ConsoleMessage[], options?: {
15
17
  header?: boolean;
16
18
  navigationId?: number;
19
+ full?: boolean | undefined;
17
20
  }): string;
18
21
  //# sourceMappingURL=follow.d.ts.map
@@ -2,20 +2,23 @@
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
- * the stream header the first time and a separator after a navigation.
11
+ * a rule the first time (the stream banner is on stderr) and a separator
12
+ * after a navigation. Texts are cut like `console --list` cuts them.
10
13
  *
11
14
  * @param messages - New messages
12
- * @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
13
17
  * @returns Text to print (empty when there is nothing new)
14
18
  */
15
19
  export function formatConsoleFollowLines(messages, options = {}) {
16
20
  const fmt = new OutputFormatter();
17
21
  if (options.header) {
18
- fmt.text('Streaming console... (Ctrl+C to stop)');
19
22
  fmt.separator('━', 40);
20
23
  if (messages.length === 0)
21
24
  fmt.text('Waiting for messages...');
@@ -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}`);
@@ -6,16 +6,13 @@
6
6
  import type { ConsoleMessage } from '../../../types.js';
7
7
  import { type ConsoleFormatOptions, type ConsoleJsonOutput } from './shared.js';
8
8
  /**
9
- * Build the rich JSON output shape (summary + deduped errors/warnings, plus
10
- * the full message list when --list is requested).
9
+ * Build the rich JSON output shape (summary + the newest deduped
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, } 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 {
@@ -25,28 +25,30 @@ function toJsonError(dedup, includeStackTrace) {
25
25
  };
26
26
  }
27
27
  /**
28
- * Build the rich JSON output shape (summary + deduped errors/warnings, plus
29
- * the full message list when --list is requested).
28
+ * Build the rich JSON output shape (summary + the newest deduped
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.
33
35
  */
34
36
  export function buildConsoleJsonOutput(messages, options) {
35
37
  const { grouped, summary } = analyzeMessages(messages);
38
+ const errors = newestGroups(grouped.errors, options.groupLimit);
39
+ const warnings = newestGroups(grouped.warnings, options.groupLimit);
36
40
  const output = {
37
41
  summary,
38
- errors: grouped.errors.map((d) => toJsonError(d, true)),
39
- warnings: grouped.warnings.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)),
44
+ ...(errors.more > 0 && { moreErrors: errors.more }),
45
+ ...(warnings.more > 0 && { moreWarnings: warnings.more }),
46
+ ...(options.dropped && { dropped: options.dropped }),
47
+ ...(options.pageCrashedAt !== undefined && { pageCrashedAt: options.pageCrashedAt }),
40
48
  };
41
- if (options.list)
42
- output.messages = lastMessages(messages, options.last);
49
+ if (options.list) {
50
+ output.messages = lastMessages(messages, options.last).map((message) => capMessageText(message, options.full));
51
+ }
43
52
  return output;
44
53
  }
45
- /**
46
- * Format console output as a JSON string. Thin wrapper around
47
- * buildConsoleJsonOutput for callers that want a serialized payload.
48
- */
49
- export function formatConsoleJson(messages, options) {
50
- return JSON.stringify(buildConsoleJsonOutput(messages, options), null, 2);
51
- }
52
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) */
@@ -57,7 +55,29 @@ export interface ConsoleFormatOptions {
57
55
  level?: ConsoleLevel | undefined;
58
56
  /** Messages between the first and last listed index that the filters left out */
59
57
  skipped?: ConsoleSkipped | undefined;
58
+ /** Distinct errors and warnings listed, the newest (0 = all; default {@link DEFAULT_GROUP_LIMIT}) */
59
+ groupLimit?: number | undefined;
60
+ /** Oldest messages the session dropped at its limit */
61
+ dropped?: number | undefined;
62
+ /** When the page crashed (epoch ms), while it is not loaded again */
63
+ pageCrashedAt?: number | undefined;
64
+ /** Print message texts whole (`--full`) */
65
+ full?: boolean | undefined;
60
66
  }
67
+ /** Distinct errors and warnings the summary lists without `--last` */
68
+ export declare const DEFAULT_GROUP_LIMIT = 50;
69
+ /**
70
+ * The newest distinct messages of a level, and how many earlier ones are not
71
+ * listed.
72
+ *
73
+ * @param groups - Distinct messages, in order of first appearance
74
+ * @param limit - How many to keep (0 = all; undefined: {@link DEFAULT_GROUP_LIMIT})
75
+ * @returns Groups to list and the count left out
76
+ */
77
+ export declare function newestGroups(groups: DeduplicatedMessage[], limit: number | undefined): {
78
+ shown: DeduplicatedMessage[];
79
+ more: number;
80
+ };
61
81
  /**
62
82
  * Messages the page and level filters left out between the first and last
63
83
  * listed index (session indices then skip numbers).
@@ -75,6 +95,8 @@ export interface JsonErrorEntry {
75
95
  count: number;
76
96
  level: string;
77
97
  text: string;
98
+ /** Original length of `text` when it was cut (`--full` keeps it whole) */
99
+ truncatedFrom?: number;
78
100
  /** Position in the session's message list (what `details console <n>` takes) */
79
101
  index?: number;
80
102
  /** Where it came from; no line/column for a resource URL (e.g. a failed load) */
@@ -90,8 +112,18 @@ export interface JsonErrorEntry {
90
112
  */
91
113
  export interface ConsoleJsonOutput {
92
114
  summary: ConsoleSummary;
115
+ /** The newest distinct errors (see `moreErrors`) */
93
116
  errors: JsonErrorEntry[];
117
+ /** The newest distinct warnings (see `moreWarnings`) */
94
118
  warnings: Omit<JsonErrorEntry, 'stackTrace'>[];
119
+ /** Earlier distinct errors not in `errors` (`--last 0` lists all) */
120
+ moreErrors?: number;
121
+ /** Earlier distinct warnings not in `warnings` */
122
+ moreWarnings?: number;
123
+ /** Oldest messages the session dropped at its limit (10000 are kept) */
124
+ dropped?: number;
125
+ /** When the page crashed (epoch ms), while it is not loaded again */
126
+ pageCrashedAt?: number;
95
127
  messages?: ConsoleMessage[];
96
128
  }
97
129
  /**
@@ -145,4 +177,17 @@ export declare function formatSectionHeader(label: string, unique: number, total
145
177
  * @returns Location text
146
178
  */
147
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;
148
193
  //# sourceMappingURL=shared.d.ts.map
@@ -1,6 +1,24 @@
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';
6
+ /** Distinct errors and warnings the summary lists without `--last` */
7
+ export const DEFAULT_GROUP_LIMIT = 50;
8
+ /**
9
+ * The newest distinct messages of a level, and how many earlier ones are not
10
+ * listed.
11
+ *
12
+ * @param groups - Distinct messages, in order of first appearance
13
+ * @param limit - How many to keep (0 = all; undefined: {@link DEFAULT_GROUP_LIMIT})
14
+ * @returns Groups to list and the count left out
15
+ */
16
+ export function newestGroups(groups, limit) {
17
+ const keep = limit ?? DEFAULT_GROUP_LIMIT;
18
+ if (keep === 0 || groups.length <= keep)
19
+ return { shown: groups, more: 0 };
20
+ return { shown: groups.slice(-keep), more: groups.length - keep };
21
+ }
4
22
  /**
5
23
  * Mapping from console message types to level categories.
6
24
  * Exported for use by console command filtering.
@@ -155,4 +173,19 @@ export function formatFramePosition(frame) {
155
173
  ? frame.url
156
174
  : `${frame.url}:${frame.lineNumber + 1}:${frame.columnNumber + 1}`;
157
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
+ }
158
191
  //# sourceMappingURL=shared.js.map
@@ -3,8 +3,15 @@
3
3
  * and shows info/debug/other as count-only footer entries.
4
4
  */
5
5
  import type { ConsoleMessage } from '../../../types.js';
6
+ import { type ConsoleFormatOptions } from './shared.js';
6
7
  /**
7
- * Format console output as smart summary (default mode).
8
+ * Format console output as smart summary (default mode): the newest distinct
9
+ * errors and warnings, counts of the rest, and a note when the session
10
+ * dropped its oldest messages.
11
+ *
12
+ * @param messages - Messages to summarise
13
+ * @param options - Distinct messages listed, messages dropped and `--full`
14
+ * @returns Summary
8
15
  */
9
- export declare function formatConsoleSummary(messages: ConsoleMessage[]): string;
16
+ export declare function formatConsoleSummary(messages: ConsoleMessage[], options?: Pick<ConsoleFormatOptions, 'groupLimit' | 'dropped' | 'full'>): string;
10
17
  //# sourceMappingURL=summarize.d.ts.map