browser-debugger-cli 0.14.0 → 0.16.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 (167) hide show
  1. package/.claude/skills/bdg/SKILL.md +3 -2
  2. package/dist/cdp/methodTarget.d.ts +92 -0
  3. package/dist/cdp/methodTarget.js +159 -0
  4. package/dist/cdp/protocol.d.ts +16 -1
  5. package/dist/cdp/protocol.js +21 -0
  6. package/dist/cdp/schema.d.ts +55 -1
  7. package/dist/cdp/schema.js +134 -25
  8. package/dist/cdp/types.d.ts +3 -1
  9. package/dist/commands/cdp.d.ts +38 -1
  10. package/dist/commands/cdp.js +201 -133
  11. package/dist/commands/cleanup.js +21 -4
  12. package/dist/commands/dom/eval.d.ts +2 -1
  13. package/dist/commands/dom/eval.js +6 -21
  14. package/dist/commands/dom/formInteraction.js +8 -4
  15. package/dist/commands/dom/helpers/evalResult.d.ts +36 -0
  16. package/dist/commands/dom/helpers/evalResult.js +59 -0
  17. package/dist/commands/dom/helpers/index.d.ts +4 -4
  18. package/dist/commands/dom/helpers/index.js +3 -3
  19. package/dist/commands/dom/helpers/query.d.ts +2 -2
  20. package/dist/commands/dom/helpers/query.js +2 -2
  21. package/dist/commands/dom/helpers/screenshot.d.ts +21 -26
  22. package/dist/commands/dom/helpers/screenshot.js +50 -668
  23. package/dist/commands/dom/screenshot.js +56 -36
  24. package/dist/commands/helpJson.d.ts +1 -1
  25. package/dist/commands/helpJson.js +3 -3
  26. package/dist/commands/helpTopic.js +10 -4
  27. package/dist/commands/network/har.js +18 -14
  28. package/dist/commands/optionBehaviors.js +24 -9
  29. package/dist/commands/shared/CommandRunner.d.ts +5 -0
  30. package/dist/commands/shared/CommandRunner.js +18 -3
  31. package/dist/commands/shared/interrupt.d.ts +40 -0
  32. package/dist/commands/shared/interrupt.js +73 -0
  33. package/dist/commands/shared/optionTypes.d.ts +3 -0
  34. package/dist/commands/shared/outputFile.d.ts +2 -1
  35. package/dist/commands/shared/outputFile.js +7 -4
  36. package/dist/commands/shared/startHelpers.d.ts +26 -3
  37. package/dist/commands/shared/startHelpers.js +145 -23
  38. package/dist/commands/status.js +3 -1
  39. package/dist/commands/stop.js +2 -1
  40. package/dist/commands/types.d.ts +5 -0
  41. package/dist/connection/cdp.js +1 -16
  42. package/dist/connection/chromeIdentity.d.ts +24 -5
  43. package/dist/connection/chromeIdentity.js +53 -22
  44. package/dist/connection/launcher/flagsBuilder.d.ts +46 -0
  45. package/dist/connection/launcher/flagsBuilder.js +107 -23
  46. package/dist/connection/launcher.d.ts +35 -2
  47. package/dist/connection/launcher.js +99 -12
  48. package/dist/connection/typed-cdp.d.ts +3 -2
  49. package/dist/constants.d.ts +3 -5
  50. package/dist/constants.js +3 -5
  51. package/dist/daemon/SessionController.d.ts +10 -5
  52. package/dist/daemon/SessionController.js +15 -8
  53. package/dist/daemon/ipcServer.js +1 -1
  54. package/dist/daemon/launcher.d.ts +22 -3
  55. package/dist/daemon/launcher.js +45 -8
  56. package/dist/daemon/session/Session.d.ts +5 -1
  57. package/dist/daemon/session/Session.js +9 -8
  58. package/dist/daemon/session/TelemetryStore.d.ts +5 -0
  59. package/dist/daemon/session/TelemetryStore.js +4 -0
  60. package/dist/daemon/session/captureGate.d.ts +59 -0
  61. package/dist/daemon/session/captureGate.js +96 -0
  62. package/dist/daemon/session/chromeConnection.d.ts +16 -1
  63. package/dist/daemon/session/chromeConnection.js +34 -4
  64. package/dist/daemon/session/collectors.d.ts +15 -0
  65. package/dist/daemon/session/collectors.js +39 -2
  66. package/dist/daemon/session/commandRegistry.d.ts +14 -1
  67. package/dist/daemon/session/commandRegistry.js +48 -13
  68. package/dist/daemon/session/downloads.d.ts +32 -0
  69. package/dist/daemon/session/downloads.js +96 -0
  70. package/dist/daemon/session/interactions.d.ts +3 -2
  71. package/dist/daemon/session/interactions.js +7 -2
  72. package/dist/daemon/session/plugins.js +6 -0
  73. package/dist/daemon.js +18520 -17014
  74. package/dist/errors/CommandError.d.ts +2 -0
  75. package/dist/errors/issues.d.ts +1 -1
  76. package/dist/errors/messages.d.ts +81 -0
  77. package/dist/errors/messages.js +198 -6
  78. package/dist/index.js +1446 -1078
  79. package/dist/ipc/client.d.ts +20 -2
  80. package/dist/ipc/client.js +32 -6
  81. package/dist/ipc/protocol/commands.d.ts +36 -2
  82. package/dist/ipc/protocol/commands.js +1 -0
  83. package/dist/ipc/protocol/domTypes.d.ts +24 -1
  84. package/dist/ipc/session/queries.d.ts +3 -0
  85. package/dist/ipc/session/types.d.ts +5 -0
  86. package/dist/ipc/transport/IPCError.d.ts +9 -0
  87. package/dist/ipc/transport/IPCError.js +12 -0
  88. package/dist/ipc/transport/errors.d.ts +2 -1
  89. package/dist/ipc/transport/errors.js +4 -1
  90. package/dist/ipc/transport/index.d.ts +10 -2
  91. package/dist/ipc/transport/index.js +29 -4
  92. package/dist/runtime/dom/actionEffects.d.ts +48 -9
  93. package/dist/runtime/dom/actionEffects.js +269 -34
  94. package/dist/runtime/dom/actionEffectsScripts.d.ts +45 -0
  95. package/dist/runtime/dom/actionEffectsScripts.js +101 -2
  96. package/dist/runtime/dom/captureArea.d.ts +35 -0
  97. package/dist/runtime/dom/captureArea.js +203 -0
  98. package/dist/runtime/dom/elementInfo.d.ts +13 -4
  99. package/dist/runtime/dom/elementInfo.js +12 -3
  100. package/dist/runtime/dom/evalHelpers.d.ts +24 -4
  101. package/dist/runtime/dom/evalHelpers.js +40 -12
  102. package/dist/runtime/dom/formDiscovery.d.ts +1 -1
  103. package/dist/runtime/dom/frames.d.ts +2 -1
  104. package/dist/runtime/dom/frames.js +3 -1
  105. package/dist/runtime/page/bdgWorld.d.ts +9 -0
  106. package/dist/runtime/page/bdgWorld.js +11 -0
  107. package/dist/runtime/page/captureEmulation.d.ts +119 -0
  108. package/dist/runtime/page/captureEmulation.js +189 -0
  109. package/dist/runtime/page/captureScroll.d.ts +24 -0
  110. package/dist/runtime/page/captureScroll.js +124 -0
  111. package/dist/runtime/page/emulation.js +6 -5
  112. package/dist/runtime/page/screenshot.d.ts +41 -0
  113. package/dist/runtime/page/screenshot.js +394 -0
  114. package/dist/runtime/page/userAgent.d.ts +86 -2
  115. package/dist/runtime/page/userAgent.js +154 -33
  116. package/dist/session/paths.d.ts +52 -3
  117. package/dist/session/paths.js +179 -7
  118. package/dist/session/portClaims.d.ts +0 -8
  119. package/dist/session/portClaims.js +1 -22
  120. package/dist/session/sessionList.d.ts +5 -1
  121. package/dist/session/sessionList.js +5 -1
  122. package/dist/telemetry/downloads.d.ts +127 -0
  123. package/dist/telemetry/downloads.js +265 -0
  124. package/dist/telemetry/har/builder.d.ts +12 -1
  125. package/dist/telemetry/har/builder.js +32 -9
  126. package/dist/telemetry/har/sanitize.d.ts +28 -0
  127. package/dist/telemetry/har/sanitize.js +184 -0
  128. package/dist/telemetry/har/sanitizeBody.d.ts +78 -0
  129. package/dist/telemetry/har/sanitizeBody.js +541 -0
  130. package/dist/telemetry/har/types.d.ts +2 -0
  131. package/dist/telemetry/network.d.ts +4 -4
  132. package/dist/telemetry/network.js +38 -4
  133. package/dist/telemetry/networkRetention.d.ts +35 -14
  134. package/dist/telemetry/networkRetention.js +62 -26
  135. package/dist/types.d.ts +9 -14
  136. package/dist/ui/OutputBuilder.d.ts +3 -2
  137. package/dist/ui/OutputBuilder.js +4 -3
  138. package/dist/ui/formatters/cdp.d.ts +32 -9
  139. package/dist/ui/formatters/cdp.js +77 -6
  140. package/dist/ui/formatters/details.js +7 -15
  141. package/dist/ui/formatters/preview.d.ts +2 -0
  142. package/dist/ui/formatters/preview.js +7 -1
  143. package/dist/ui/formatters/sessions.d.ts +3 -2
  144. package/dist/ui/formatters/sessions.js +10 -3
  145. package/dist/ui/formatters/status.js +6 -1
  146. package/dist/ui/formatting.d.ts +7 -0
  147. package/dist/ui/formatting.js +13 -0
  148. package/dist/ui/logging/logger.d.ts +1 -1
  149. package/dist/ui/messages/chrome.d.ts +27 -6
  150. package/dist/ui/messages/chrome.js +78 -12
  151. package/dist/ui/messages/commands.d.ts +71 -3
  152. package/dist/ui/messages/commands.js +98 -3
  153. package/dist/ui/messages/networkMessages.d.ts +50 -5
  154. package/dist/ui/messages/networkMessages.js +50 -6
  155. package/dist/ui/messages/session.d.ts +8 -0
  156. package/dist/ui/messages/session.js +10 -0
  157. package/dist/utils/async.d.ts +3 -2
  158. package/dist/utils/async.js +16 -3
  159. package/dist/utils/atomicFile.d.ts +2 -1
  160. package/dist/utils/atomicFile.js +5 -2
  161. package/dist/utils/directories.d.ts +41 -0
  162. package/dist/utils/directories.js +48 -0
  163. package/dist/utils/http.d.ts +11 -4
  164. package/dist/utils/http.js +5 -3
  165. package/package.json +18 -4
  166. /package/dist/{commands/dom → runtime/page}/screenshotResize.d.ts +0 -0
  167. /package/dist/{commands/dom → runtime/page}/screenshotResize.js +0 -0
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Bounds of a `dom eval --json` result (#478): one eval must not put
3
+ * megabytes into an agent's context.
4
+ */
5
+ /**
6
+ * The `result` of `dom eval --json`, and what was left out of it. A string
7
+ * `result` with `truncatedFrom` while `type` is `object` is the start of
8
+ * the value's JSON text, not a string the script returned.
9
+ */
10
+ export interface BoundedEvalResult {
11
+ /** The value, its first elements, or the start of its (JSON) text */
12
+ result: unknown;
13
+ /** Elements of an array result in the page, set only when it was bounded */
14
+ count?: number;
15
+ /** Elements left out of a listed array result */
16
+ omitted?: number;
17
+ /**
18
+ * Length of the string, or of the JSON text of the copied object or array
19
+ * (which holds at most 1000 entries per list or object), `result` was cut from
20
+ */
21
+ truncatedFrom?: number;
22
+ }
23
+ /**
24
+ * Bound an eval result for JSON output: a string is cut to
25
+ * {@link MAX_VALUE_LENGTH} characters, an array keeps its first
26
+ * {@link EVAL_JSON_ARRAY_LIMIT} elements (with `count` and `omitted`), and
27
+ * an object or array whose JSON is still longer than the cap becomes the
28
+ * start of its JSON text (with `truncatedFrom`), so the output stays valid
29
+ * JSON. Small values are returned as they are.
30
+ *
31
+ * @param value - Evaluated value, as copied from the page
32
+ * @param length - Elements of an array result in the page (its copy may hold fewer)
33
+ * @returns `result`, with what was left out when bounded
34
+ */
35
+ export declare function boundEvalResult(value: unknown, length?: number): BoundedEvalResult;
36
+ //# sourceMappingURL=evalResult.d.ts.map
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Bounds of a `dom eval --json` result (#478): one eval must not put
3
+ * megabytes into an agent's context.
4
+ */
5
+ import { EVAL_JSON_ARRAY_LIMIT, MAX_VALUE_LENGTH } from '../../../constants.js';
6
+ import { capLength } from '../../../utils/strings.js';
7
+ /**
8
+ * Bound an eval result for JSON output: a string is cut to
9
+ * {@link MAX_VALUE_LENGTH} characters, an array keeps its first
10
+ * {@link EVAL_JSON_ARRAY_LIMIT} elements (with `count` and `omitted`), and
11
+ * an object or array whose JSON is still longer than the cap becomes the
12
+ * start of its JSON text (with `truncatedFrom`), so the output stays valid
13
+ * JSON. Small values are returned as they are.
14
+ *
15
+ * @param value - Evaluated value, as copied from the page
16
+ * @param length - Elements of an array result in the page (its copy may hold fewer)
17
+ * @returns `result`, with what was left out when bounded
18
+ */
19
+ export function boundEvalResult(value, length) {
20
+ if (typeof value === 'string') {
21
+ const { text, truncatedFrom } = capLength(value, MAX_VALUE_LENGTH);
22
+ return { result: text, ...(truncatedFrom !== undefined && { truncatedFrom }) };
23
+ }
24
+ if (Array.isArray(value))
25
+ return boundArray(value, length ?? value.length);
26
+ if (value === null || typeof value !== 'object')
27
+ return { result: value };
28
+ const json = JSON.stringify(value);
29
+ return json.length > MAX_VALUE_LENGTH ? jsonStart(json) : { result: value };
30
+ }
31
+ /**
32
+ * Bound an array result: its first {@link EVAL_JSON_ARRAY_LIMIT} elements,
33
+ * or the start of its JSON text when even those are over the cap.
34
+ *
35
+ * @param value - Array result
36
+ * @param count - Elements of the array in the page
37
+ * @returns `result` with `count`, and `omitted` or `truncatedFrom`
38
+ */
39
+ function boundArray(value, count) {
40
+ const listed = value.slice(0, EVAL_JSON_ARRAY_LIMIT);
41
+ const listedJson = JSON.stringify(listed);
42
+ if (listedJson.length > MAX_VALUE_LENGTH) {
43
+ const json = listed.length === value.length ? listedJson : JSON.stringify(value);
44
+ return { ...jsonStart(json), count };
45
+ }
46
+ return listed.length < count
47
+ ? { result: listed, count, omitted: count - listed.length }
48
+ : { result: value };
49
+ }
50
+ /**
51
+ * The first {@link MAX_VALUE_LENGTH} characters of a JSON text.
52
+ *
53
+ * @param json - JSON text of an object or array over the cap
54
+ * @returns Its start, and the length of all of it
55
+ */
56
+ function jsonStart(json) {
57
+ return { result: capLength(json, MAX_VALUE_LENGTH).text, truncatedFrom: json.length };
58
+ }
59
+ //# sourceMappingURL=evalResult.js.map
@@ -3,9 +3,9 @@
3
3
  * so callers can keep importing from `@/commands/dom/helpers.js`.
4
4
  *
5
5
  * - `query.ts` — selector → backend node ids (shadow roots, same-origin iframes), DOM.describeNode
6
- * - `screenshot.ts` — page / element capture, element bounds, scroll helpers
6
+ * - `screenshot.ts` — page / element capture through the daemon, writing the image
7
7
  */
8
- export { documentReadyState, noMatchesError, queryDOMElements, getDomContext, getDOMElements, resolveSelector, resolveBackendNodeIds, selectMatch, assertNodeAttached, pageDocumentId, } from './query.js';
9
- export { capturePageScreenshot, captureElementScreenshot, getElementBounds, } from './screenshot.js';
10
- export type { DomQueryResult, DomGetResult, ScreenshotResult, DomGetOptions, ScreenshotOptions, DomContext, ElementBounds, } from '../../../types.js';
8
+ export { noMatchesError, queryDOMElements, getDomContext, getDOMElements, resolveSelector, resolveBackendNodeIds, selectMatch, assertNodeAttached, pageDocumentId, } from './query.js';
9
+ export { captureScreenshot, screenshotInterrupted } from './screenshot.js';
10
+ export type { DomGetOptions, DomContext } from '../../../types.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -3,8 +3,8 @@
3
3
  * so callers can keep importing from `@/commands/dom/helpers.js`.
4
4
  *
5
5
  * - `query.ts` — selector → backend node ids (shadow roots, same-origin iframes), DOM.describeNode
6
- * - `screenshot.ts` — page / element capture, element bounds, scroll helpers
6
+ * - `screenshot.ts` — page / element capture through the daemon, writing the image
7
7
  */
8
- export { documentReadyState, noMatchesError, queryDOMElements, getDomContext, getDOMElements, resolveSelector, resolveBackendNodeIds, selectMatch, assertNodeAttached, pageDocumentId, } from './query.js';
9
- export { capturePageScreenshot, captureElementScreenshot, getElementBounds, } from './screenshot.js';
8
+ export { noMatchesError, queryDOMElements, getDomContext, getDOMElements, resolveSelector, resolveBackendNodeIds, selectMatch, assertNodeAttached, pageDocumentId, } from './query.js';
9
+ export { captureScreenshot, screenshotInterrupted } from './screenshot.js';
10
10
  //# sourceMappingURL=index.js.map
@@ -91,10 +91,10 @@ export declare function getDOMElements(options: DomGetOptions): Promise<DomGetRe
91
91
  * Resolve a selector to its first match.
92
92
  *
93
93
  * @param selector - CSS selector
94
- * @returns Reference to the first matching node (valid within this command)
94
+ * @returns Backend node id of the first match
95
95
  * @throws CommandError (83) when nothing matches
96
96
  */
97
- export declare function resolveSelector(selector: string): Promise<NodeRef>;
97
+ export declare function resolveSelector(selector: string): Promise<number>;
98
98
  /**
99
99
  * Resolve selectors to backend node ids (first match each).
100
100
  *
@@ -655,7 +655,7 @@ export async function getDOMElements(options) {
655
655
  * Resolve a selector to its first match.
656
656
  *
657
657
  * @param selector - CSS selector
658
- * @returns Reference to the first matching node (valid within this command)
658
+ * @returns Backend node id of the first match
659
659
  * @throws CommandError (83) when nothing matches
660
660
  */
661
661
  export async function resolveSelector(selector) {
@@ -664,7 +664,7 @@ export async function resolveSelector(selector) {
664
664
  const err = await noMatchesError(selector);
665
665
  throw new CommandError(err.message, { suggestion: err.suggestion }, EXIT_CODES.RESOURCE_NOT_FOUND);
666
666
  }
667
- return { backendNodeId };
667
+ return backendNodeId;
668
668
  }
669
669
  /**
670
670
  * Resolve selectors to backend node ids (first match each).
@@ -1,34 +1,29 @@
1
1
  /**
2
- * CDP-relay helpers for screenshot capture.
3
- *
4
- * Covers page, element, and element-bounds operations plus the scroll-into-
5
- * view primitives used by page screenshots with `--scroll`.
2
+ * Screenshot capture for `bdg dom screenshot`: the daemon measures, captures
3
+ * and puts back the page's emulation (`dom_screenshot`); this writes the image
4
+ * it returns.
6
5
  */
7
- import type { ScreenshotResult, ScreenshotOptions, ElementBounds, NodeRef } from '../../../types.js';
6
+ import { type InterruptSignal } from '../../shared/interrupt.js';
7
+ import { CommandError } from '../../../errors/index.js';
8
+ import type { DomScreenshotCommand } from '../../../ipc/protocol/commands.js';
9
+ import type { ScreenshotResult } from '../../../types.js';
8
10
  /**
9
- * Get the bounding box (border box, so padding and border are included) of an
10
- * element via CDP DOM.getBoxModel.
11
+ * The error of a screenshot interrupted by Ctrl-C or SIGTERM.
11
12
  *
12
- * @param ref - Node reference
13
- * @returns Element bounds in CSS pixels
14
- */
15
- export declare function getElementBounds(ref: NodeRef): Promise<ElementBounds>;
16
- /**
17
- * Capture a screenshot of the page. Auto-resizes oversized pages by default
18
- * to keep Claude Vision token cost bounded; falls back to viewport capture
19
- * when the page is taller than the tall-page threshold.
13
+ * @param signal - The signal
14
+ * @returns Command error (exit 130, or 143 for SIGTERM)
20
15
  */
21
- export declare function capturePageScreenshot(outputPath: string, options?: ScreenshotOptions): Promise<ScreenshotResult>;
16
+ export declare function screenshotInterrupted(signal: InterruptSignal): CommandError;
22
17
  /**
23
- * Capture a screenshot of a single element: its border box, grown to include
24
- * content overflowing it ({@link captureArea}). The box model is relative to
25
- * the viewport and the capture clip to the page, so the page scroll is added
26
- * (the reported bounds are page coordinates, like `dom layout`'s).
18
+ * Capture the page (or the element `backendNodeId` names) and write the
19
+ * image.
20
+ *
21
+ * @param outputPath - File to write
22
+ * @param request - What to capture and how
23
+ * @param interrupt - Aborted on Ctrl-C or SIGTERM: the capture is cancelled
24
+ * @returns What was captured, with the file's absolute path
25
+ * @throws CommandError with the daemon's error (Chrome's, when the capture
26
+ * failed) and exit code, or 130/143 when interrupted
27
27
  */
28
- export declare function captureElementScreenshot(outputPath: string, ref: NodeRef, options?: {
29
- format?: 'png' | 'jpeg';
30
- quality?: number;
31
- noResize?: boolean;
32
- padding?: number;
33
- }): Promise<ScreenshotResult>;
28
+ export declare function captureScreenshot(outputPath: string, request: DomScreenshotCommand, interrupt?: AbortSignal): Promise<ScreenshotResult>;
34
29
  //# sourceMappingURL=screenshot.d.ts.map