jumpy-lion 0.1.6-beta.7 → 1.0.0-beta.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 (232) hide show
  1. package/README.md +1 -607
  2. package/browser/fonts/macos-bundle/40-macos-aliases.conf +515 -0
  3. package/browser/fonts/macos-bundle/README.md +24 -0
  4. package/browser/fonts/macos-bundle/install.sh +83 -0
  5. package/dist/browser-controller.d.ts +47 -4
  6. package/dist/browser-controller.d.ts.map +1 -1
  7. package/dist/browser-controller.js +219 -278
  8. package/dist/browser-controller.js.map +1 -1
  9. package/dist/browser-plugin.d.ts +82 -110
  10. package/dist/browser-plugin.d.ts.map +1 -1
  11. package/dist/browser-plugin.js +376 -379
  12. package/dist/browser-plugin.js.map +1 -1
  13. package/dist/browser-process/align-fingerprint-config.d.ts +36 -0
  14. package/dist/browser-process/align-fingerprint-config.d.ts.map +1 -0
  15. package/dist/browser-process/align-fingerprint-config.js +74 -0
  16. package/dist/browser-process/align-fingerprint-config.js.map +1 -0
  17. package/dist/browser-process/anti-detect-browser.d.ts +2 -2
  18. package/dist/browser-process/anti-detect-browser.js +7 -7
  19. package/dist/browser-process/anti-detect-config.d.ts +131 -2
  20. package/dist/browser-process/anti-detect-config.d.ts.map +1 -1
  21. package/dist/browser-process/anti-detect-config.js +337 -127
  22. package/dist/browser-process/anti-detect-config.js.map +1 -1
  23. package/dist/browser-process/browser.d.ts +25 -92
  24. package/dist/browser-process/browser.d.ts.map +1 -1
  25. package/dist/browser-process/browser.js +429 -73
  26. package/dist/browser-process/browser.js.map +1 -1
  27. package/dist/browser-process/fingerprint-config.d.ts +146 -0
  28. package/dist/browser-process/fingerprint-config.d.ts.map +1 -0
  29. package/dist/browser-process/fingerprint-config.js +308 -0
  30. package/dist/browser-process/fingerprint-config.js.map +1 -0
  31. package/dist/browser-process/get-chrome-executable.d.ts +6 -0
  32. package/dist/browser-process/get-chrome-executable.d.ts.map +1 -1
  33. package/dist/browser-process/get-chrome-executable.js +79 -4
  34. package/dist/browser-process/get-chrome-executable.js.map +1 -1
  35. package/dist/browser-process/gpu-family-profiles.d.ts +58 -0
  36. package/dist/browser-process/gpu-family-profiles.d.ts.map +1 -0
  37. package/dist/browser-process/gpu-family-profiles.js +480 -0
  38. package/dist/browser-process/gpu-family-profiles.js.map +1 -0
  39. package/dist/browser-process/launch-options.d.ts +301 -0
  40. package/dist/browser-process/launch-options.d.ts.map +1 -0
  41. package/dist/browser-process/launch-options.js +2 -0
  42. package/dist/browser-process/launch-options.js.map +1 -0
  43. package/dist/browser-process/port-allocator.d.ts +64 -0
  44. package/dist/browser-process/port-allocator.d.ts.map +1 -0
  45. package/dist/browser-process/port-allocator.js +198 -0
  46. package/dist/browser-process/port-allocator.js.map +1 -0
  47. package/dist/browser-process/process.d.ts +85 -0
  48. package/dist/browser-process/process.d.ts.map +1 -1
  49. package/dist/browser-process/process.js +235 -19
  50. package/dist/browser-process/process.js.map +1 -1
  51. package/dist/browser-process/signal-cleanup.d.ts +40 -0
  52. package/dist/browser-process/signal-cleanup.d.ts.map +1 -0
  53. package/dist/browser-process/signal-cleanup.js +105 -0
  54. package/dist/browser-process/signal-cleanup.js.map +1 -0
  55. package/dist/browser-process/widevine-cdm.d.ts +144 -0
  56. package/dist/browser-process/widevine-cdm.d.ts.map +1 -0
  57. package/dist/browser-process/widevine-cdm.js +298 -0
  58. package/dist/browser-process/widevine-cdm.js.map +1 -0
  59. package/dist/browser-profiles/chrome/populate-profile.d.ts.map +1 -1
  60. package/dist/browser-profiles/chrome/populate-profile.js +21 -22
  61. package/dist/browser-profiles/chrome/populate-profile.js.map +1 -1
  62. package/dist/connection/cdp-reconnection.d.ts +50 -0
  63. package/dist/connection/cdp-reconnection.d.ts.map +1 -0
  64. package/dist/connection/cdp-reconnection.js +75 -0
  65. package/dist/connection/cdp-reconnection.js.map +1 -0
  66. package/dist/connection/page-session.d.ts +114 -0
  67. package/dist/connection/page-session.d.ts.map +1 -0
  68. package/dist/connection/page-session.js +237 -0
  69. package/dist/connection/page-session.js.map +1 -0
  70. package/dist/connection/session-client.d.ts +34 -0
  71. package/dist/connection/session-client.d.ts.map +1 -0
  72. package/dist/connection/session-client.js +129 -0
  73. package/dist/connection/session-client.js.map +1 -0
  74. package/dist/crawler.d.ts +9 -88
  75. package/dist/crawler.d.ts.map +1 -1
  76. package/dist/crawler.js +157 -8
  77. package/dist/crawler.js.map +1 -1
  78. package/dist/fingerprinting/fingerprint-injector.d.ts +24 -114
  79. package/dist/fingerprinting/fingerprint-injector.d.ts.map +1 -1
  80. package/dist/fingerprinting/fingerprint-injector.js +305 -611
  81. package/dist/fingerprinting/fingerprint-injector.js.map +1 -1
  82. package/dist/fingerprinting/fingerprint-overrides/datadome-bypass.d.ts +1 -1
  83. package/dist/fingerprinting/fingerprint-overrides/datadome-bypass.d.ts.map +1 -1
  84. package/dist/fingerprinting/fingerprint-overrides/datadome-bypass.js +16 -14
  85. package/dist/fingerprinting/fingerprint-overrides/datadome-bypass.js.map +1 -1
  86. package/dist/fingerprinting/fingerprint-overrides/index.d.ts +6 -2
  87. package/dist/fingerprinting/fingerprint-overrides/index.d.ts.map +1 -1
  88. package/dist/fingerprinting/fingerprint-overrides/index.js +6 -2
  89. package/dist/fingerprinting/fingerprint-overrides/index.js.map +1 -1
  90. package/dist/fingerprinting/fingerprint-overrides/keyboard-humanization.d.ts +1 -1
  91. package/dist/fingerprinting/fingerprint-overrides/keyboard-humanization.js +4 -4
  92. package/dist/fingerprinting/fingerprint-overrides/keyboard-humanization.js.map +1 -1
  93. package/dist/fingerprinting/fingerprint-overrides/locale-spoofing.js +4 -4
  94. package/dist/fingerprinting/fingerprint-overrides/navigator-override.d.ts +18 -0
  95. package/dist/fingerprinting/fingerprint-overrides/navigator-override.d.ts.map +1 -0
  96. package/dist/fingerprinting/fingerprint-overrides/navigator-override.js +136 -0
  97. package/dist/fingerprinting/fingerprint-overrides/navigator-override.js.map +1 -0
  98. package/dist/fingerprinting/fingerprint-overrides/override.d.ts +151 -0
  99. package/dist/fingerprinting/fingerprint-overrides/override.d.ts.map +1 -0
  100. package/dist/fingerprinting/fingerprint-overrides/override.js +14 -0
  101. package/dist/fingerprinting/fingerprint-overrides/override.js.map +1 -0
  102. package/dist/fingerprinting/fingerprint-overrides/platform-consistency.d.ts.map +1 -1
  103. package/dist/fingerprinting/fingerprint-overrides/platform-consistency.js +46 -15
  104. package/dist/fingerprinting/fingerprint-overrides/platform-consistency.js.map +1 -1
  105. package/dist/fingerprinting/fingerprint-overrides/registry.d.ts +43 -0
  106. package/dist/fingerprinting/fingerprint-overrides/registry.d.ts.map +1 -0
  107. package/dist/fingerprinting/fingerprint-overrides/registry.js +342 -0
  108. package/dist/fingerprinting/fingerprint-overrides/registry.js.map +1 -0
  109. package/dist/fingerprinting/fingerprint-overrides/screen-override.d.ts +16 -0
  110. package/dist/fingerprinting/fingerprint-overrides/screen-override.d.ts.map +1 -0
  111. package/dist/fingerprinting/fingerprint-overrides/screen-override.js +175 -0
  112. package/dist/fingerprinting/fingerprint-overrides/screen-override.js.map +1 -0
  113. package/dist/fingerprinting/fingerprint-overrides/scroll-humanization.d.ts +1 -1
  114. package/dist/fingerprinting/fingerprint-overrides/scroll-humanization.js +4 -4
  115. package/dist/fingerprinting/fingerprint-overrides/scroll-humanization.js.map +1 -1
  116. package/dist/fingerprinting/fingerprint-overrides/stealth-script.d.ts.map +1 -1
  117. package/dist/fingerprinting/fingerprint-overrides/stealth-script.js +75 -9
  118. package/dist/fingerprinting/fingerprint-overrides/stealth-script.js.map +1 -1
  119. package/dist/fingerprinting/fingerprint-overrides/ua-ch.d.ts +1 -1
  120. package/dist/fingerprinting/fingerprint-overrides/ua-ch.d.ts.map +1 -1
  121. package/dist/fingerprinting/fingerprint-overrides/ua-ch.js +34 -20
  122. package/dist/fingerprinting/fingerprint-overrides/ua-ch.js.map +1 -1
  123. package/dist/fingerprinting/fingerprint-overrides/webgl-spoofing.d.ts.map +1 -1
  124. package/dist/fingerprinting/fingerprint-overrides/webgl-spoofing.js +25 -6
  125. package/dist/fingerprinting/fingerprint-overrides/webgl-spoofing.js.map +1 -1
  126. package/dist/fingerprinting/fingerprint-overrides/webrtc-spoofing.js +1 -1
  127. package/dist/fingerprinting/hardware-realism.d.ts +83 -0
  128. package/dist/fingerprinting/hardware-realism.d.ts.map +1 -0
  129. package/dist/fingerprinting/hardware-realism.js +156 -0
  130. package/dist/fingerprinting/hardware-realism.js.map +1 -0
  131. package/dist/fingerprinting/injection-planner.d.ts +133 -0
  132. package/dist/fingerprinting/injection-planner.d.ts.map +1 -0
  133. package/dist/fingerprinting/injection-planner.js +497 -0
  134. package/dist/fingerprinting/injection-planner.js.map +1 -0
  135. package/dist/fingerprinting/locale-resolver.d.ts +8 -1
  136. package/dist/fingerprinting/locale-resolver.d.ts.map +1 -1
  137. package/dist/fingerprinting/locale-resolver.js +26 -3
  138. package/dist/fingerprinting/locale-resolver.js.map +1 -1
  139. package/dist/fingerprinting/non-apify-fingerprint-generator.d.ts +4 -4
  140. package/dist/fingerprinting/non-apify-fingerprint-generator.d.ts.map +1 -1
  141. package/dist/fingerprinting/non-apify-fingerprint-generator.js +24 -58
  142. package/dist/fingerprinting/non-apify-fingerprint-generator.js.map +1 -1
  143. package/dist/fingerprinting/non-apify-profiles.json +10515 -8494
  144. package/dist/fingerprinting/os-consistency.d.ts +28 -0
  145. package/dist/fingerprinting/os-consistency.d.ts.map +1 -0
  146. package/dist/fingerprinting/os-consistency.js +45 -0
  147. package/dist/fingerprinting/os-consistency.js.map +1 -0
  148. package/dist/fingerprinting/profile-quality.d.ts +25 -0
  149. package/dist/fingerprinting/profile-quality.d.ts.map +1 -0
  150. package/dist/fingerprinting/profile-quality.js +310 -0
  151. package/dist/fingerprinting/profile-quality.js.map +1 -0
  152. package/dist/fingerprinting/profile-selector.d.ts +102 -0
  153. package/dist/fingerprinting/profile-selector.d.ts.map +1 -0
  154. package/dist/fingerprinting/profile-selector.js +168 -0
  155. package/dist/fingerprinting/profile-selector.js.map +1 -0
  156. package/dist/fingerprinting/ua-alignment.d.ts +83 -0
  157. package/dist/fingerprinting/ua-alignment.d.ts.map +1 -0
  158. package/dist/fingerprinting/ua-alignment.js +197 -0
  159. package/dist/fingerprinting/ua-alignment.js.map +1 -0
  160. package/dist/fingerprinting/ua-ch-brands.d.ts +88 -0
  161. package/dist/fingerprinting/ua-ch-brands.d.ts.map +1 -0
  162. package/dist/fingerprinting/ua-ch-brands.js +174 -0
  163. package/dist/fingerprinting/ua-ch-brands.js.map +1 -0
  164. package/dist/index.d.ts +5 -0
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +6 -0
  167. package/dist/index.js.map +1 -1
  168. package/dist/input/dropdown-selector.d.ts +90 -0
  169. package/dist/input/dropdown-selector.d.ts.map +1 -0
  170. package/dist/input/dropdown-selector.js +394 -0
  171. package/dist/input/dropdown-selector.js.map +1 -0
  172. package/dist/input/element-target.d.ts +152 -0
  173. package/dist/input/element-target.d.ts.map +1 -0
  174. package/dist/input/element-target.js +461 -0
  175. package/dist/input/element-target.js.map +1 -0
  176. package/dist/input/input-emulator.d.ts +85 -0
  177. package/dist/input/input-emulator.d.ts.map +1 -0
  178. package/dist/input/input-emulator.js +325 -0
  179. package/dist/input/input-emulator.js.map +1 -0
  180. package/dist/input/input-transport.d.ts +60 -0
  181. package/dist/input/input-transport.d.ts.map +1 -0
  182. package/dist/input/input-transport.js +28 -0
  183. package/dist/input/input-transport.js.map +1 -0
  184. package/dist/input/recording-transport.d.ts +32 -0
  185. package/dist/input/recording-transport.d.ts.map +1 -0
  186. package/dist/input/recording-transport.js +43 -0
  187. package/dist/input/recording-transport.js.map +1 -0
  188. package/dist/keyboard-layout.d.ts +2 -2
  189. package/dist/keyboard-layout.js +2 -2
  190. package/dist/navigation/page-navigation.d.ts +67 -0
  191. package/dist/navigation/page-navigation.d.ts.map +1 -0
  192. package/dist/navigation/page-navigation.js +122 -0
  193. package/dist/navigation/page-navigation.js.map +1 -0
  194. package/dist/network/network-watch.d.ts +110 -0
  195. package/dist/network/network-watch.d.ts.map +1 -0
  196. package/dist/network/network-watch.js +223 -0
  197. package/dist/network/network-watch.js.map +1 -0
  198. package/dist/page.d.ts +118 -104
  199. package/dist/page.d.ts.map +1 -1
  200. package/dist/page.js +311 -1130
  201. package/dist/page.js.map +1 -1
  202. package/dist/session/inject-hook.d.ts +24 -0
  203. package/dist/session/inject-hook.d.ts.map +1 -0
  204. package/dist/session/inject-hook.js +80 -0
  205. package/dist/session/inject-hook.js.map +1 -0
  206. package/dist/session/save.d.ts +21 -0
  207. package/dist/session/save.d.ts.map +1 -0
  208. package/dist/session/save.js +163 -0
  209. package/dist/session/save.js.map +1 -0
  210. package/dist/session/tar-data-dir.d.ts +18 -0
  211. package/dist/session/tar-data-dir.d.ts.map +1 -0
  212. package/dist/session/tar-data-dir.js +105 -0
  213. package/dist/session/tar-data-dir.js.map +1 -0
  214. package/dist/session/types.d.ts +80 -0
  215. package/dist/session/types.d.ts.map +1 -0
  216. package/dist/session/types.js +29 -0
  217. package/dist/session/types.js.map +1 -0
  218. package/dist/session-profile.d.ts +102 -0
  219. package/dist/session-profile.d.ts.map +1 -0
  220. package/dist/session-profile.js +163 -0
  221. package/dist/session-profile.js.map +1 -0
  222. package/dist/tsconfig.build.tsbuildinfo +1 -1
  223. package/package.json +17 -6
  224. package/scripts/postinstall.cjs +58 -0
  225. package/dist/fingerprinting/custom-fingerprint-injector.d.ts +0 -87
  226. package/dist/fingerprinting/custom-fingerprint-injector.d.ts.map +0 -1
  227. package/dist/fingerprinting/custom-fingerprint-injector.js +0 -342
  228. package/dist/fingerprinting/custom-fingerprint-injector.js.map +0 -1
  229. package/dist/launcher-wrap.d.ts +0 -10
  230. package/dist/launcher-wrap.d.ts.map +0 -1
  231. package/dist/launcher-wrap.js +0 -11
  232. package/dist/launcher-wrap.js.map +0 -1
@@ -0,0 +1,325 @@
1
+ import { log } from 'crawlee';
2
+ import { describeChar, MODIFIER_SHIFT } from '../keyboard-layout.js';
3
+ // --- timing / bitmask constants (moved from page.ts; input-only) ---
4
+ const PRESS_RELEASE_DELAY_MS = 50;
5
+ const HUMAN_KEYBOARD_DELAY_MIN_MS = 45;
6
+ const HUMAN_KEYBOARD_DELAY_MAX_MS = 160;
7
+ const HUMAN_MOUSE_MOVE_DELAY_MIN_MS = 6;
8
+ const HUMAN_MOUSE_MOVE_DELAY_MAX_MS = 18;
9
+ /** Bit values for `MouseEvent.buttons` per the UI Events spec. */
10
+ const MOUSE_BUTTON_BITS = { left: 1, right: 2, middle: 4 };
11
+ const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
12
+ // ── bezierMousePath tuning ──────────────────────────────────────────────────
13
+ /** One path point per ~8 px of travel, clamped to [20, 80] points. */
14
+ const MOUSE_PX_PER_STEP = 8;
15
+ const MOUSE_MIN_STEPS = 20;
16
+ const MOUSE_MAX_STEPS = 80;
17
+ /**
18
+ * How far each control point is pushed sideways off the straight line, as a
19
+ * fraction of total distance. Randomised in [−FRAC, +FRAC] so the curve bows
20
+ * left or right by up to 30% of the distance - never a dead-straight move.
21
+ */
22
+ const MOUSE_CONTROL_BIAS_FRAC = 0.3;
23
+ /** Peak amplitude (px) of the mid-path tremor wobble. */
24
+ const MOUSE_WOBBLE_PEAK_PX = 1.5;
25
+ /** Uniform random in [−magnitude, +magnitude). */
26
+ function randomSymmetric(magnitude) {
27
+ return (Math.random() * 2 - 1) * magnitude;
28
+ }
29
+ /**
30
+ * easeInOutCubic: slow start, fast middle, slow end - matches how an arm
31
+ * accelerates off rest and decelerates onto a target.
32
+ */
33
+ function easeInOutCubic(t) {
34
+ return t < 0.5 ? 4 * t * t * t : 1 - ((-2 * t + 2) ** 3) / 2;
35
+ }
36
+ /** Standard cubic Bézier point: B(t) = u³·p0 + 3u²t·c1 + 3ut²·c2 + t³·p3, u = 1−t. */
37
+ function cubicBezier(p0, c1, c2, p3, t) {
38
+ const u = 1 - t;
39
+ const w0 = u * u * u;
40
+ const w1 = 3 * u * u * t;
41
+ const w2 = 3 * u * t * t;
42
+ const w3 = t * t * t;
43
+ return {
44
+ x: w0 * p0.x + w1 * c1.x + w2 * c2.x + w3 * p3.x,
45
+ y: w0 * p0.y + w1 * c1.y + w2 * c2.y + w3 * p3.y,
46
+ };
47
+ }
48
+ /**
49
+ * Cubic Bézier mouse path from (fromX, fromY) to (toX, toY) in pure TypeScript -
50
+ * NO `Runtime.evaluate` round-trip per move (which is itself a 2026 CDP-detection
51
+ * signal). Two perpendicular-offset control points (±30% distance bias) bow each
52
+ * move unpredictably; eased-in-out timing matches arm motion; sub-pixel wobble
53
+ * (peaking mid-curve, under ±1.5 px) mimics pointer tremor. Returns rounded
54
+ * integer points; the caller dispatches one mouse event per point.
55
+ */
56
+ export function bezierMousePath(fromX, fromY, toX, toY) {
57
+ const from = { x: fromX, y: fromY };
58
+ const to = { x: toX, y: toY };
59
+ const dx = toX - fromX;
60
+ const dy = toY - fromY;
61
+ const dist = Math.hypot(dx, dy);
62
+ if (dist < 1)
63
+ return [{ x: Math.round(toX), y: Math.round(toY) }];
64
+ const steps = Math.max(MOUSE_MIN_STEPS, Math.min(MOUSE_MAX_STEPS, Math.round(dist / MOUSE_PX_PER_STEP)));
65
+ // Unit vector perpendicular to the straight line from→to. Offsetting the
66
+ // control points along this normal is what bends the path sideways.
67
+ const perpX = -dy / dist;
68
+ const perpY = dx / dist;
69
+ // Two control points at 25% and 75% along the straight line, each shoved
70
+ // off the line by a random sideways bias → an organically curved path.
71
+ const bias1 = randomSymmetric(MOUSE_CONTROL_BIAS_FRAC * dist);
72
+ const bias2 = randomSymmetric(MOUSE_CONTROL_BIAS_FRAC * dist);
73
+ const control1 = { x: fromX + dx * 0.25 + perpX * bias1, y: fromY + dy * 0.25 + perpY * bias1 };
74
+ const control2 = { x: fromX + dx * 0.75 + perpX * bias2, y: fromY + dy * 0.75 + perpY * bias2 };
75
+ const path = [];
76
+ for (let i = 1; i <= steps; i++) {
77
+ const progress = i / steps; // 0..1 linear along the path
78
+ const t = easeInOutCubic(progress); // eased curve parameter
79
+ const point = cubicBezier(from, control1, control2, to, t);
80
+ // Hand tremor: largest in the middle of the move (sin peaks at progress
81
+ // 0.5), zero at the endpoints so we still land exactly on the target.
82
+ const wobble = Math.sin(Math.PI * progress) * MOUSE_WOBBLE_PEAK_PX;
83
+ path.push({
84
+ x: Math.round(point.x + randomSymmetric(wobble)),
85
+ y: Math.round(point.y + randomSymmetric(wobble)),
86
+ });
87
+ }
88
+ return path;
89
+ }
90
+ /**
91
+ * True for code points entered through an IME (Korean Hangul, Japanese
92
+ * Hiragana/Katakana, Chinese Han, Fullwidth/Halfwidth forms). These can't go
93
+ * through the rawKeyDown → char → keyUp path; Naver / Japanese IME-aware forms
94
+ * validate the composition event lifecycle, which plain `insertText` skips.
95
+ */
96
+ export function isCjkChar(char) {
97
+ if (!char)
98
+ return false;
99
+ const code = char.codePointAt(0) ?? 0;
100
+ return ((code >= 0x3040 && code <= 0x309F)
101
+ || (code >= 0x30A0 && code <= 0x30FF)
102
+ || (code >= 0x3400 && code <= 0x4DBF)
103
+ || (code >= 0x4E00 && code <= 0x9FFF)
104
+ || (code >= 0xAC00 && code <= 0xD7AF)
105
+ || (code >= 0xF900 && code <= 0xFAFF)
106
+ || (code >= 0xFF00 && code <= 0xFFEF));
107
+ }
108
+ /**
109
+ * Deep module over {@link InputTransport}: turns high-level intents
110
+ * (move, click, type) into humanized sequences of transport events. Owns
111
+ * cursor position, the held-button bitmask, and the CJK composition lifecycle.
112
+ * Coordinate/text level - selector resolution is the caller's job.
113
+ */
114
+ export class InputEmulator {
115
+ constructor(transport, humanization = {}) {
116
+ Object.defineProperty(this, "transport", {
117
+ enumerable: true,
118
+ configurable: true,
119
+ writable: true,
120
+ value: transport
121
+ });
122
+ Object.defineProperty(this, "lastMousePosition", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: { x: 0, y: 0 }
127
+ });
128
+ Object.defineProperty(this, "heldMouseButtons", {
129
+ enumerable: true,
130
+ configurable: true,
131
+ writable: true,
132
+ value: new Set()
133
+ });
134
+ Object.defineProperty(this, "humanization", {
135
+ enumerable: true,
136
+ configurable: true,
137
+ writable: true,
138
+ value: void 0
139
+ });
140
+ this.humanization = {
141
+ mouse: humanization.mouse ?? false,
142
+ keyboard: humanization.keyboard ?? false,
143
+ scroll: humanization.scroll ?? false,
144
+ };
145
+ }
146
+ setHumanization(options) {
147
+ this.humanization = {
148
+ mouse: options?.mouse ?? false,
149
+ keyboard: options?.keyboard ?? false,
150
+ scroll: options?.scroll ?? false,
151
+ };
152
+ }
153
+ /** Current cursor position (copy). */
154
+ get position() {
155
+ return { ...this.lastMousePosition };
156
+ }
157
+ buttonsBitmask() {
158
+ let mask = 0;
159
+ for (const button of this.heldMouseButtons)
160
+ mask += MOUSE_BUTTON_BITS[button];
161
+ return mask;
162
+ }
163
+ /**
164
+ * Move the cursor to (x, y). With mouse humanization on, follows a Bézier
165
+ * path with eased timing; otherwise a single `mouseMoved`.
166
+ */
167
+ async moveTo(x, y) {
168
+ if (!this.humanization.mouse) {
169
+ await this.transport.mouse({
170
+ type: 'mouseMoved',
171
+ x,
172
+ y,
173
+ buttons: this.buttonsBitmask(),
174
+ pointerType: 'mouse',
175
+ });
176
+ this.lastMousePosition = { x, y };
177
+ return;
178
+ }
179
+ const path = bezierMousePath(this.lastMousePosition.x, this.lastMousePosition.y, x, y);
180
+ for (const point of path) {
181
+ await this.transport.mouse({
182
+ type: 'mouseMoved',
183
+ x: point.x,
184
+ y: point.y,
185
+ buttons: this.buttonsBitmask(),
186
+ pointerType: 'mouse',
187
+ });
188
+ await sleep(HUMAN_MOUSE_MOVE_DELAY_MIN_MS
189
+ + Math.floor(Math.random() * (HUMAN_MOUSE_MOVE_DELAY_MAX_MS - HUMAN_MOUSE_MOVE_DELAY_MIN_MS + 1)));
190
+ }
191
+ this.lastMousePosition = { x, y };
192
+ }
193
+ /**
194
+ * Move to (x, y) and perform a human-like click. The held-button set is
195
+ * updated before each dispatch so `event.buttons` is spec-correct on
196
+ * mousedown (button present) and mouseup (button cleared).
197
+ */
198
+ async clickAt(x, y, options) {
199
+ const button = options?.button ?? 'left';
200
+ const clickCount = options?.clickCount ?? 1;
201
+ const delay = options?.delay ?? 0;
202
+ await this.moveTo(x, y);
203
+ if (delay > 0) {
204
+ await sleep(delay);
205
+ }
206
+ else if (this.humanization.mouse) {
207
+ await sleep(40 + Math.floor(Math.random() * 120));
208
+ }
209
+ this.heldMouseButtons.add(button);
210
+ await this.transport.mouse({
211
+ type: 'mousePressed',
212
+ x,
213
+ y,
214
+ button,
215
+ clickCount,
216
+ buttons: this.buttonsBitmask(),
217
+ pointerType: 'mouse',
218
+ });
219
+ await sleep(PRESS_RELEASE_DELAY_MS);
220
+ this.heldMouseButtons.delete(button);
221
+ await this.transport.mouse({
222
+ type: 'mouseReleased',
223
+ x,
224
+ y,
225
+ button,
226
+ clickCount,
227
+ buttons: this.buttonsBitmask(),
228
+ pointerType: 'mouse',
229
+ });
230
+ this.lastMousePosition = { x, y };
231
+ }
232
+ /**
233
+ * Type text at the current focus. ANSI keys go through rawKeyDown → char →
234
+ * keyUp; CJK characters go through the IME composition path; other Unicode
235
+ * falls back to insertText. Keyboard humanization adds a bimodal cadence
236
+ * (mostly fast, occasional "thinking" pauses).
237
+ */
238
+ async typeText(text, options) {
239
+ const delay = options?.delay ?? 0;
240
+ // Iterate CODE POINTS, not UTF-16 code units. Indexing `text[i]` split
241
+ // every astral character (emoji, CJK Ext-B, math alphanumerics) into two
242
+ // lone surrogates: `describeChar` misses them, `isCjkChar` reads the
243
+ // surrogate half and returns false, and each half was shipped through
244
+ // `insertText` separately - producing mojibake instead of the character.
245
+ const chars = Array.from(text);
246
+ for (let i = 0; i < chars.length; i++) {
247
+ await this.typeChar(chars[i]);
248
+ if (i === chars.length - 1)
249
+ continue;
250
+ if (delay > 0) {
251
+ await sleep(delay);
252
+ continue;
253
+ }
254
+ if (!this.humanization.keyboard)
255
+ continue;
256
+ if (Math.random() < 0.08) {
257
+ await sleep(400 + Math.floor(Math.random() * 500));
258
+ continue;
259
+ }
260
+ await sleep(HUMAN_KEYBOARD_DELAY_MIN_MS
261
+ + Math.floor(Math.random() * (HUMAN_KEYBOARD_DELAY_MAX_MS - HUMAN_KEYBOARD_DELAY_MIN_MS + 1)));
262
+ }
263
+ }
264
+ async typeChar(char) {
265
+ const mapping = describeChar(char);
266
+ if (!mapping) {
267
+ if (isCjkChar(char)) {
268
+ await this.typeCjkChar(char);
269
+ }
270
+ else {
271
+ await this.transport.text(char);
272
+ }
273
+ return;
274
+ }
275
+ const { descriptor, shift } = mapping;
276
+ const modifiers = shift ? MODIFIER_SHIFT : 0;
277
+ const text = descriptor.text ?? descriptor.key;
278
+ await this.transport.key({
279
+ type: 'rawKeyDown',
280
+ modifiers,
281
+ key: descriptor.key,
282
+ code: descriptor.code,
283
+ windowsVirtualKeyCode: descriptor.keyCode,
284
+ location: descriptor.location ?? 0,
285
+ });
286
+ await this.transport.key({
287
+ type: 'char',
288
+ modifiers,
289
+ key: descriptor.key,
290
+ code: descriptor.code,
291
+ text,
292
+ unmodifiedText: text,
293
+ windowsVirtualKeyCode: descriptor.keyCode,
294
+ location: descriptor.location ?? 0,
295
+ });
296
+ await this.transport.key({
297
+ type: 'keyUp',
298
+ modifiers,
299
+ key: descriptor.key,
300
+ code: descriptor.code,
301
+ windowsVirtualKeyCode: descriptor.keyCode,
302
+ location: descriptor.location ?? 0,
303
+ });
304
+ }
305
+ /**
306
+ * Type one CJK character through the IME composition path so the page sees a
307
+ * real `compositionstart → compositionupdate → compositionend` sequence
308
+ * (`imeSetComposition` starts it; `text`/insertText commits). Falls back to
309
+ * plain text if composition is unavailable.
310
+ */
311
+ async typeCjkChar(char) {
312
+ try {
313
+ const len = Array.from(char).length;
314
+ await this.transport.ime({ text: char, selectionStart: len, selectionEnd: len });
315
+ await this.transport.text(char);
316
+ }
317
+ catch (err) {
318
+ log.debug('[input] imeSetComposition unavailable, falling back to insertText', {
319
+ err: err.message,
320
+ });
321
+ await this.transport.text(char);
322
+ }
323
+ }
324
+ }
325
+ //# sourceMappingURL=input-emulator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-emulator.js","sourceRoot":"","sources":["../../src/input/input-emulator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAuBrE,sEAAsE;AACtE,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,2BAA2B,GAAG,EAAE,CAAC;AACvC,MAAM,2BAA2B,GAAG,GAAG,CAAC;AACxC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AACxC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AAEzC,kEAAkE;AAClE,MAAM,iBAAiB,GAAgC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AAExF,MAAM,KAAK,GAAG,KAAK,EAAE,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAI5F,+EAA+E;AAC/E,sEAAsE;AACtE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B;;;;GAIG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,yDAAyD;AACzD,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAEjC,kDAAkD;AAClD,SAAS,eAAe,CAAC,SAAiB;IACtC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;AAC/C,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,CA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C,CAAC;YACjF,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,GAAG,CAAC,KAAK,CAAC,mEAAmE,EAAE;gBAC3E,GAAG,EAAG,GAAa,CAAC,OAAO;aAC9B,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;CACJ"}
@@ -0,0 +1,60 @@
1
+ import type CDP from 'chrome-remote-interface';
2
+ /**
3
+ * InputTransport - the narrow seam over raw CDP input dispatch.
4
+ *
5
+ * Four typed primitives, one per CDP `Input.*` call the crawler uses. This is
6
+ * deliberately dumb: it dispatches events and nothing else. All humanization,
7
+ * cursor state, button bitmasks, and IME composition *lifecycle* live above it
8
+ * in {@link InputEmulator}. Keeping the transport this thin is what makes the
9
+ * emulator testable - swap in {@link RecordingTransport} and assert the exact
10
+ * event sequence without a browser.
11
+ */
12
+ export interface MouseEventParams {
13
+ type: 'mousePressed' | 'mouseReleased' | 'mouseMoved' | 'mouseWheel';
14
+ x: number;
15
+ y: number;
16
+ button?: 'left' | 'right' | 'middle' | 'none';
17
+ buttons?: number;
18
+ clickCount?: number;
19
+ pointerType?: 'mouse' | 'pen';
20
+ deltaX?: number;
21
+ deltaY?: number;
22
+ modifiers?: number;
23
+ }
24
+ export interface KeyEventParams {
25
+ type: 'keyDown' | 'keyUp' | 'rawKeyDown' | 'char';
26
+ modifiers?: number;
27
+ key?: string;
28
+ code?: string;
29
+ text?: string;
30
+ unmodifiedText?: string;
31
+ windowsVirtualKeyCode?: number;
32
+ location?: number;
33
+ }
34
+ export interface ImeCompositionParams {
35
+ text: string;
36
+ selectionStart: number;
37
+ selectionEnd: number;
38
+ }
39
+ export interface InputTransport {
40
+ mouse(params: MouseEventParams): Promise<void>;
41
+ key(params: KeyEventParams): Promise<void>;
42
+ /** Commit text directly (CDP `Input.insertText`) - fires beforeinput/input only. */
43
+ text(value: string): Promise<void>;
44
+ /** Set an ongoing IME composition (CDP `Input.imeSetComposition`). */
45
+ ime(params: ImeCompositionParams): Promise<void>;
46
+ }
47
+ /**
48
+ * Production adapter. Reads the live CDP client through a `getClient` accessor
49
+ * rather than pinning one, so a session reconnect (which swaps the underlying
50
+ * client) is invisible here - every dispatch hits the current connection.
51
+ */
52
+ export declare class CdpInputTransport implements InputTransport {
53
+ private readonly getClient;
54
+ constructor(getClient: () => CDP.Client);
55
+ mouse(params: MouseEventParams): Promise<void>;
56
+ key(params: KeyEventParams): Promise<void>;
57
+ text(value: string): Promise<void>;
58
+ ime(params: ImeCompositionParams): Promise<void>;
59
+ }
60
+ //# sourceMappingURL=input-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-transport.d.ts","sourceRoot":"","sources":["../../src/input/input-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,YAAY,GAAG,YAAY,CAAC;IACrE,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,MAAM,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC3B,KAAK,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,oFAAoF;IACpF,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,sEAAsE;IACtE,GAAG,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACxC,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAAT,SAAS,EAAE,MAAM,GAAG,CAAC,MAAM;IAElD,KAAK,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,GAAG,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzD"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Production adapter. Reads the live CDP client through a `getClient` accessor
3
+ * rather than pinning one, so a session reconnect (which swaps the underlying
4
+ * client) is invisible here - every dispatch hits the current connection.
5
+ */
6
+ export class CdpInputTransport {
7
+ constructor(getClient) {
8
+ Object.defineProperty(this, "getClient", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: getClient
13
+ });
14
+ }
15
+ async mouse(params) {
16
+ await this.getClient().Input.dispatchMouseEvent(params);
17
+ }
18
+ async key(params) {
19
+ await this.getClient().Input.dispatchKeyEvent(params);
20
+ }
21
+ async text(value) {
22
+ await this.getClient().Input.insertText({ text: value });
23
+ }
24
+ async ime(params) {
25
+ await this.getClient().Input.imeSetComposition(params);
26
+ }
27
+ }
28
+ //# sourceMappingURL=input-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-transport.js","sourceRoot":"","sources":["../../src/input/input-transport.ts"],"names":[],"mappings":"AAmDA;;;;GAIG;AACH,MAAM,OAAO,iBAAiB;IAC1B,YAA6B,SAA2B;QAA5C;;;;mBAAiB,SAAS;WAAkB;IAAG,CAAC;IAE5D,KAAK,CAAC,KAAK,CAAC,MAAwB;QAChC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,MAAe,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAAsB;QAC5B,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,MAAe,CAAC,CAAC;IACnE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAa;QACpB,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,MAA4B;QAClC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAe,CAAC,CAAC;IACpE,CAAC;CACJ"}
@@ -0,0 +1,32 @@
1
+ import type { ImeCompositionParams, InputTransport, KeyEventParams, MouseEventParams } from './input-transport.js';
2
+ export type RecordedInput = {
3
+ kind: 'mouse';
4
+ params: MouseEventParams;
5
+ } | {
6
+ kind: 'key';
7
+ params: KeyEventParams;
8
+ } | {
9
+ kind: 'text';
10
+ value: string;
11
+ } | {
12
+ kind: 'ime';
13
+ params: ImeCompositionParams;
14
+ };
15
+ /**
16
+ * Test adapter for {@link InputTransport}. Records every dispatched event in
17
+ * order so a test can assert behaviour produced by {@link InputEmulator} -
18
+ * button bitmasks, humanized path shape, the CJK composition lifecycle - with
19
+ * no browser and no CDP connection.
20
+ */
21
+ export declare class RecordingTransport implements InputTransport {
22
+ readonly events: RecordedInput[];
23
+ mouse(params: MouseEventParams): Promise<void>;
24
+ key(params: KeyEventParams): Promise<void>;
25
+ text(value: string): Promise<void>;
26
+ ime(params: ImeCompositionParams): Promise<void>;
27
+ /** Ordered list of event kinds (mouse `type` for mouse/key events). */
28
+ sequence(): string[];
29
+ mouseEvents(): MouseEventParams[];
30
+ clear(): void;
31
+ }
32
+ //# sourceMappingURL=recording-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-transport.d.ts","sourceRoot":"","sources":["../../src/input/recording-transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,MAAM,aAAa,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAA;CAAE,GAC3C;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,GACvC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,oBAAoB,CAAA;CAAE,CAAC;AAEpD;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,cAAc;IACrD,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAM;IAEhC,KAAK,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,GAAG,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,GAAG,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,uEAAuE;IACvE,QAAQ,IAAI,MAAM,EAAE;IAOpB,WAAW,IAAI,gBAAgB,EAAE;IAIjC,KAAK,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Test adapter for {@link InputTransport}. Records every dispatched event in
3
+ * order so a test can assert behaviour produced by {@link InputEmulator} -
4
+ * button bitmasks, humanized path shape, the CJK composition lifecycle - with
5
+ * no browser and no CDP connection.
6
+ */
7
+ export class RecordingTransport {
8
+ constructor() {
9
+ Object.defineProperty(this, "events", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: []
14
+ });
15
+ }
16
+ async mouse(params) {
17
+ this.events.push({ kind: 'mouse', params });
18
+ }
19
+ async key(params) {
20
+ this.events.push({ kind: 'key', params });
21
+ }
22
+ async text(value) {
23
+ this.events.push({ kind: 'text', value });
24
+ }
25
+ async ime(params) {
26
+ this.events.push({ kind: 'ime', params });
27
+ }
28
+ /** Ordered list of event kinds (mouse `type` for mouse/key events). */
29
+ sequence() {
30
+ return this.events.map((e) => {
31
+ if (e.kind === 'mouse' || e.kind === 'key')
32
+ return e.params.type;
33
+ return e.kind;
34
+ });
35
+ }
36
+ mouseEvents() {
37
+ return this.events.flatMap((e) => (e.kind === 'mouse' ? [e.params] : []));
38
+ }
39
+ clear() {
40
+ this.events.length = 0;
41
+ }
42
+ }
43
+ //# sourceMappingURL=recording-transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recording-transport.js","sourceRoot":"","sources":["../../src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ED,KAAK;QACD,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC3B,CAAC;CACJ"}
@@ -3,7 +3,7 @@
3
3
  * with realistic `code` / `key` / `keyCode` / `text` / `modifiers` values.
4
4
  *
5
5
  * Without these, CDP-driven key events arrive at the page with `event.code === ''`
6
- * and `event.keyCode === 0` — a one-line bot signal that anti-bot SDKs check on
6
+ * and `event.keyCode === 0` - a one-line bot signal that anti-bot SDKs check on
7
7
  * every keystroke.
8
8
  *
9
9
  * Modeled on Puppeteer's USKeyboardLayout (Apache-2). Trimmed to printable ASCII
@@ -33,7 +33,7 @@ interface CharMapping {
33
33
  }
34
34
  /**
35
35
  * Look up the CDP key descriptor for a single character. Returns null for
36
- * characters outside the US ANSI printable set (Unicode, emoji, IME chars) —
36
+ * characters outside the US ANSI printable set (Unicode, emoji, IME chars) -
37
37
  * callers should fall back to `Input.insertText` for those.
38
38
  *
39
39
  * Newlines map to Enter, tabs map to Tab.
@@ -3,7 +3,7 @@
3
3
  * with realistic `code` / `key` / `keyCode` / `text` / `modifiers` values.
4
4
  *
5
5
  * Without these, CDP-driven key events arrive at the page with `event.code === ''`
6
- * and `event.keyCode === 0` — a one-line bot signal that anti-bot SDKs check on
6
+ * and `event.keyCode === 0` - a one-line bot signal that anti-bot SDKs check on
7
7
  * every keystroke.
8
8
  *
9
9
  * Modeled on Puppeteer's USKeyboardLayout (Apache-2). Trimmed to printable ASCII
@@ -123,7 +123,7 @@ const SPECIAL_KEYS = {
123
123
  };
124
124
  /**
125
125
  * Look up the CDP key descriptor for a single character. Returns null for
126
- * characters outside the US ANSI printable set (Unicode, emoji, IME chars) —
126
+ * characters outside the US ANSI printable set (Unicode, emoji, IME chars) -
127
127
  * callers should fall back to `Input.insertText` for those.
128
128
  *
129
129
  * Newlines map to Enter, tabs map to Tab.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * PageNavigation - the deep module beside NetworkWatch/ElementTarget that owns
3
+ * the navigation + load-wait protocol: enable Page, fire navigate/reload, race
4
+ * `domContentEventFired` / `loadEventFired` against a timeout, then reconcile
5
+ * the landed URL via `getNavigationHistory` (NOT `Runtime.evaluate`, which is a
6
+ * CDP detection vector). It also caches the last reconciled URL so `url()` can
7
+ * answer without re-hitting CDP.
8
+ *
9
+ * Talks to the page only through the narrow `NavigationPort`, so the whole
10
+ * protocol is unit-testable with a scripted port - no `new CdpPage(...)` and no
11
+ * fake CDP client. `CdpPage.goto` / `reload` / `url` are thin delegates and the
12
+ * `loadedUrl` state lives here, not on the god object.
13
+ *
14
+ * The URL reconcile prefers `getNavigationHistory` (Page domain only) and falls
15
+ * back to `evaluateUrl` (Runtime) only when history is unavailable.
16
+ */
17
+ export interface GotoOptions {
18
+ waitUntil?: 'domcontentloaded' | 'load';
19
+ timeout?: number;
20
+ }
21
+ export interface NavigationHistory {
22
+ currentIndex: number;
23
+ entries: {
24
+ url: string;
25
+ }[];
26
+ }
27
+ /**
28
+ * The narrow seam over the page's CDP surface that navigation needs. The
29
+ * production adapter wraps the live CDP client (read through the PageSession
30
+ * accessor so a reconnect swap is picked up); the test adapter is scripted.
31
+ */
32
+ export interface NavigationPort {
33
+ /** Lazily enable the Page domain (a CDP detection-surface concern owned by the page). */
34
+ enablePage(): Promise<void>;
35
+ navigate(url: string): Promise<void>;
36
+ reload(): Promise<void>;
37
+ /** Subscribe to the DOMContentLoaded event; returns an unsubscribe fn the caller MUST invoke. */
38
+ onDomContent(handler: () => void): () => void;
39
+ /** Subscribe to the load event; returns an unsubscribe fn the caller MUST invoke. */
40
+ onLoad(handler: () => void): () => void;
41
+ navigationHistory(): Promise<NavigationHistory>;
42
+ /** Runtime fallback for the current URL when navigation history is unavailable. */
43
+ evaluateUrl(): Promise<string>;
44
+ }
45
+ export declare class PageNavigation {
46
+ private readonly port;
47
+ private loadedUrl;
48
+ constructor(port: NavigationPort);
49
+ /** Last reconciled URL, or - before any navigation - the live URL from CDP. */
50
+ url(): Promise<string>;
51
+ /** Navigate to `url`, wait for the requested load milestone, reconcile the landed URL. */
52
+ goto(url: string, options?: GotoOptions): Promise<void>;
53
+ /** Reload the current page, wait for the requested load milestone, reconcile the landed URL. */
54
+ reload(options?: GotoOptions): Promise<void>;
55
+ /**
56
+ * Race the requested load event against the timeout. Resolves when the
57
+ * event fires; rejects with `timeoutMessage` once the timeout elapses.
58
+ */
59
+ private waitForLoad;
60
+ /**
61
+ * Resolve the current URL without activating the Runtime domain when
62
+ * possible: `getNavigationHistory` needs only the Page domain. Falls back
63
+ * to a Runtime evaluation only when history is empty or unavailable.
64
+ */
65
+ private currentUrl;
66
+ }
67
+ //# sourceMappingURL=page-navigation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-navigation.d.ts","sourceRoot":"","sources":["../../src/navigation/page-navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,WAAW;IACxB,SAAS,CAAC,EAAE,kBAAkB,GAAG,MAAM,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9B;AAED;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC3B,yFAAyF;IACzF,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,iGAAiG;IACjG,YAAY,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9C,qFAAqF;IACrF,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IACxC,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAChD,mFAAmF;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