@crouton-kit/capture 1.4.1 → 1.4.10

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 (111) hide show
  1. package/README.md +178 -0
  2. package/bin/capture +31299 -7322
  3. package/package.json +3 -1
  4. package/src/capture.ts +21 -18
  5. package/src/cdp/args.ts +269 -49
  6. package/src/cdp/bridge/server.ts +6 -5
  7. package/src/cdp/bridge/spawn.ts +41 -97
  8. package/src/cdp/commands/bridge-serve.ts +11 -21
  9. package/src/cdp/commands/cdp.ts +44 -22
  10. package/src/cdp/commands/heap/census.ts +61 -0
  11. package/src/cdp/commands/heap/common.ts +77 -0
  12. package/src/cdp/commands/heap/diff.ts +92 -0
  13. package/src/cdp/commands/heap/index.ts +38 -0
  14. package/src/cdp/commands/heap/objects.ts +42 -0
  15. package/src/cdp/commands/heap/retainers.ts +52 -0
  16. package/src/cdp/commands/heap/snapshot.ts +94 -0
  17. package/src/cdp/commands/lib.ts +9 -17
  18. package/src/cdp/commands/lighthouse.ts +414 -0
  19. package/src/cdp/commands/measure/census.ts +2 -1
  20. package/src/cdp/commands/measure/check.ts +70 -16
  21. package/src/cdp/commands/measure/diff.ts +1 -2
  22. package/src/cdp/commands/measure/explain.ts +44 -7
  23. package/src/cdp/commands/measure/index.ts +24 -32
  24. package/src/cdp/commands/measure/map-ax.ts +2 -1
  25. package/src/cdp/commands/measure/map-focus.ts +2 -1
  26. package/src/cdp/commands/measure/map-layers.ts +5 -3
  27. package/src/cdp/commands/measure/map-scroll.ts +2 -1
  28. package/src/cdp/commands/measure/snap.ts +5 -4
  29. package/src/cdp/commands/measure/sweep.ts +16 -11
  30. package/src/cdp/commands/measure/text.ts +147 -0
  31. package/src/cdp/commands/motion/index.ts +10 -18
  32. package/src/cdp/commands/motion/jank.ts +13 -22
  33. package/src/cdp/commands/motion/mask.ts +10 -9
  34. package/src/cdp/commands/motion/rec.ts +230 -28
  35. package/src/cdp/commands/motion/timeline.ts +1 -1
  36. package/src/cdp/commands/page/click.ts +18 -8
  37. package/src/cdp/commands/page/elements.ts +43 -11
  38. package/src/cdp/commands/page/exec.ts +53 -18
  39. package/src/cdp/commands/page/index.ts +20 -20
  40. package/src/cdp/commands/page/inspect.ts +338 -0
  41. package/src/cdp/commands/page/navigate.ts +83 -38
  42. package/src/cdp/commands/page/repeat.ts +176 -0
  43. package/src/cdp/commands/page/scroll.ts +11 -6
  44. package/src/cdp/commands/page/shot.ts +68 -33
  45. package/src/cdp/commands/page/type.ts +7 -3
  46. package/src/cdp/commands/perf/index.ts +32 -0
  47. package/src/cdp/commands/perf/insights.ts +214 -0
  48. package/src/cdp/commands/perf/trace.ts +235 -0
  49. package/src/cdp/commands/perf/vitals.ts +76 -0
  50. package/src/cdp/commands/session/collectors.ts +54 -0
  51. package/src/cdp/commands/stub.ts +10 -0
  52. package/src/cdp/commands/tab/close.ts +2 -2
  53. package/src/cdp/commands/tab/index.ts +16 -23
  54. package/src/cdp/commands/tab/launch.ts +1 -1
  55. package/src/cdp/commands/tab/mock/index.ts +24 -0
  56. package/src/cdp/commands/tab/mock/lifecycle.ts +88 -0
  57. package/src/cdp/commands/tab/mock/start.ts +65 -0
  58. package/src/cdp/commands/tab/mock/stop.ts +39 -0
  59. package/src/cdp/commands/tab/network.ts +22 -13
  60. package/src/cdp/commands/tab/reset.ts +11 -12
  61. package/src/cdp/connection.ts +19 -39
  62. package/src/cdp/detect.ts +27 -7
  63. package/src/cdp/dispatch.ts +25 -4
  64. package/src/cdp/domains.ts +2 -2
  65. package/src/cdp/har-recorder.ts +0 -1
  66. package/src/cdp/heap-snapshot.ts +647 -0
  67. package/src/cdp/host/client.ts +22 -0
  68. package/src/cdp/host/collector.ts +74 -0
  69. package/src/cdp/host/collectors/heap.ts +79 -0
  70. package/src/cdp/host/collectors/intercept.ts +247 -0
  71. package/src/cdp/{recorder-bridge.ts → host/collectors/motion.ts} +388 -473
  72. package/src/cdp/host/collectors/trace.ts +108 -0
  73. package/src/cdp/host/core.ts +217 -0
  74. package/src/cdp/host/handle.ts +47 -0
  75. package/src/cdp/host/held-client.ts +91 -0
  76. package/src/cdp/host/kinds.ts +97 -0
  77. package/src/cdp/host/lifecycle.ts +123 -0
  78. package/src/cdp/host/server.ts +88 -0
  79. package/src/cdp/leaf-grammar.ts +2 -2
  80. package/src/cdp/measure/check.ts +181 -16
  81. package/src/cdp/measure/collectors/hittest.ts +16 -10
  82. package/src/cdp/measure/collectors/scroll.ts +15 -7
  83. package/src/cdp/measure/collectors/style-provenance.ts +11 -0
  84. package/src/cdp/measure/collectors/styles.ts +4 -4
  85. package/src/cdp/measure/explain.ts +14 -2
  86. package/src/cdp/measure/map-layers.ts +52 -8
  87. package/src/cdp/measure/snapshot.ts +5 -3
  88. package/src/cdp/measure/sweep.ts +29 -6
  89. package/src/cdp/measure/text.ts +227 -0
  90. package/src/cdp/motion/jank.ts +29 -83
  91. package/src/cdp/motion/mask.ts +18 -9
  92. package/src/cdp/motion/recorder.ts +86 -731
  93. package/src/cdp/scope-lock.ts +9 -9
  94. package/src/cdp/screenshot.ts +51 -21
  95. package/src/cdp/timing.ts +5 -5
  96. package/src/cdp/trace-analysis.ts +320 -0
  97. package/src/cdp/types.ts +31 -1
  98. package/src/cdp.ts +4 -6
  99. package/src/har-manager.ts +2 -4
  100. package/src/interact.ts +78 -25
  101. package/src/output/artifact.ts +49 -5
  102. package/src/output/render.ts +60 -9
  103. package/src/output/selection.ts +6 -0
  104. package/src/session/artifacts.ts +122 -12
  105. package/src/session/commands.ts +348 -113
  106. package/src/session/coordinator.ts +0 -93
  107. package/src/session/har-redact.ts +29 -23
  108. package/src/session-context.ts +13 -9
  109. package/src/cdp/bridge/protocol.ts +0 -224
  110. package/src/cdp/recorder-client.ts +0 -326
  111. package/src/cdp/tab-lock.ts +0 -132
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crouton-kit/capture",
3
- "version": "1.4.1",
3
+ "version": "1.4.10",
4
4
  "description": "Browser automation and UI validation via CDP — session-based screenshots, HAR, a11y, click/type, and JS exec",
5
5
  "bin": {
6
6
  "capture": "./bin/capture"
@@ -44,6 +44,8 @@
44
44
  "zod": "^4.3.5"
45
45
  },
46
46
  "dependencies": {
47
+ "@paulirish/trace_engine": "0.0.65",
48
+ "lighthouse": "13.4.1",
47
49
  "pixelmatch": "7.2.0",
48
50
  "pngjs": "7.0.0",
49
51
  "ws": "^8.19.0"
package/src/capture.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * capture — browser automation and UI measurement over CDP.
3
3
  *
4
- * Root router: seven visible roots (session, page, tab, measure, motion,
5
- * cdp, lib) plus the hidden `__bridge-serve` and `__log-tail-serve`
4
+ * Root router: ten visible roots (session, page, tab, measure, motion, perf,
5
+ * heap, lighthouse, cdp, lib) plus the hidden `__bridge-serve` and `__log-tail-serve`
6
6
  * internals, all dispatched below. Root help is assembled from each branch's exported
7
7
  * `COMMAND_BLOCK` — the parent walks its children, it never hardcodes a
8
8
  * child's description. An unknown first token is a structured
@@ -19,11 +19,14 @@ import { COMMAND_BLOCK as PAGE_BLOCK } from './cdp/commands/page/index.js';
19
19
  import { COMMAND_BLOCK as TAB_BLOCK } from './cdp/commands/tab/index.js';
20
20
  import { COMMAND_BLOCK as MEASURE_BLOCK } from './cdp/commands/measure/index.js';
21
21
  import { COMMAND_BLOCK as MOTION_BLOCK } from './cdp/commands/motion/index.js';
22
+ import { COMMAND_BLOCK as PERF_BLOCK } from './cdp/commands/perf/index.js';
23
+ import { COMMAND_BLOCK as HEAP_BLOCK } from './cdp/commands/heap/index.js';
24
+ import { COMMAND_BLOCK as LIGHTHOUSE_BLOCK } from './cdp/commands/lighthouse.js';
22
25
  import { COMMAND_BLOCK as CDP_BLOCK } from './cdp/commands/cdp.js';
23
26
  import { COMMAND_BLOCK as LIB_BLOCK } from './cdp/commands/lib.js';
24
27
 
25
- /** The seven visible root children, in help order. */
26
- const ROOTS = ['session', 'page', 'tab', 'measure', 'motion', 'cdp', 'lib'] as const;
28
+ /** The ten visible root children, in help order. */
29
+ const ROOTS = ['session', 'page', 'tab', 'measure', 'motion', 'perf', 'heap', 'lighthouse', 'cdp', 'lib'] as const;
27
30
 
28
31
  /**
29
32
  * Guessable former/legacy tokens with one unambiguous current destination —
@@ -35,6 +38,9 @@ const ROOTS = ['session', 'page', 'tab', 'measure', 'motion', 'cdp', 'lib'] as c
35
38
  */
36
39
  const GUESSABLE_HINTS: Readonly<Record<string, string>> = {
37
40
  screenshot: 'page shot',
41
+ trace: 'perf trace',
42
+ memory: 'heap census',
43
+ mock: 'tab mock start',
38
44
  };
39
45
 
40
46
  const ROOT_BLOCKS = [
@@ -43,6 +49,9 @@ const ROOT_BLOCKS = [
43
49
  TAB_BLOCK,
44
50
  MEASURE_BLOCK,
45
51
  MOTION_BLOCK,
52
+ PERF_BLOCK,
53
+ HEAP_BLOCK,
54
+ LIGHTHOUSE_BLOCK,
46
55
  CDP_BLOCK,
47
56
  LIB_BLOCK,
48
57
  ] as const;
@@ -52,17 +61,11 @@ function rootHelp(): string {
52
61
 
53
62
  ${ROOT_BLOCKS.join('\n\n')}
54
63
 
55
- I/O contract: flags and positionals on input; one rendered prose block on
56
- stdout. --json mirrors the same result as JSON, but the rendered block is
57
- the contract. stderr carries in-flight diagnostics only.
58
-
59
- A CDP-enabled browser must be running; \`capture tab list\` is the probe, and
60
- \`capture tab launch\` starts one capture owns and reaps when nothing is (never
61
- hand-roll a detached browser — nothing reaps that). Capture never signals a
62
- browser it did not start, so attaching to your own with --port is unchanged.
63
- CDP_PORT / CDP_TARGET pin the browser + tab for target-selecting commands —
64
- precedence: explicit flag > active session > env. \`session start\` adopts only an
65
- explicit --target.`;
64
+ Selecting a noun: session, page, and tab address the live browser context; measure, motion, perf, and heap each own a distinct recorded substrate; lighthouse, cdp, and lib are respectively third-party audit, raw protocol, and local-library surfaces. Use a substrate noun when its recorded artifact is the source of the facts you need.
65
+
66
+ I/O contract: flags and positionals on input; one rendered prose block on stdout. --json mirrors the same result as JSON, but the rendered block is the contract. stderr carries in-flight diagnostics only. --artifact-dir <path> selects the root for a session bundle (\`session start\`) or a sessionless artifact-producing leaf's one-shot bundle; leaf help states when it writes one. --out always names one caller-owned file, never a bundle directory.
67
+
68
+ A CDP-enabled browser must be running; \`capture tab list\` is the probe, and \`capture tab launch\` starts one capture owns and reaps when nothing is (never hand-roll a detached browser — nothing reaps that). Capture never signals a browser it did not start, so attaching to your own with --port is unchanged. CDP_PORT / CDP_TARGET pin the browser + tab for target-selecting commands — precedence: explicit flag > active session > env. \`session start\` adopts only an explicit --target.`;
66
69
  }
67
70
 
68
71
  function printVersion(): void {
@@ -90,7 +93,7 @@ async function main(): Promise<void> {
90
93
  return;
91
94
  }
92
95
 
93
- if (command === undefined || command === '-h') {
96
+ if (command === undefined || command === '-h' || command === '--help') {
94
97
  console.log(rootHelp());
95
98
  return;
96
99
  }
@@ -111,8 +114,8 @@ async function main(): Promise<void> {
111
114
  'invocation',
112
115
  'unknown_command',
113
116
  hint
114
- ? `Unknown command ${command}; did you mean \`capture ${hint}\`? Expected one of the seven roots: session, page, tab, measure, motion, cdp, lib.`
115
- : `Unknown command ${command}; expected one of the seven roots: session, page, tab, measure, motion, cdp, lib.`,
117
+ ? `Unknown command ${command}; did you mean \`capture ${hint}\`? Expected one of the ten roots: session, page, tab, measure, motion, perf, heap, lighthouse, cdp, lib.`
118
+ : `Unknown command ${command}; expected one of the ten roots: session, page, tab, measure, motion, perf, heap, lighthouse, cdp, lib.`,
116
119
  );
117
120
  }
118
121