captchakraken 5.1.0-beta.55 → 5.2.0-beta.56

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.
package/NOTICE CHANGED
@@ -7,7 +7,18 @@ General Public License, version 3 only (LGPL-3.0-only), which governs
7
7
  everything in this repository that is not listed here.
8
8
 
9
9
  ────────────────────────────────────────────────────────────────────────────
10
- Cursory — mouse trajectory generation
10
+ Myuri — human mouse paths and keystroke timing
11
+ ────────────────────────────────────────────────────────────────────────────
12
+
13
+ myuri https://github.com/JWriter20/Myuri (Python, PyPI: myuri)
14
+ @jwriter20/myuri https://github.com/JWriter20/Myuri (TypeScript, npm: @jwriter20/myuri)
15
+
16
+ Copyright (c) Jake Writer and the Myuri contributors.
17
+ Licensed under the GNU Lesser General Public License, version 3 or later
18
+ (LGPL-3.0-or-later). A copy is available at https://www.gnu.org/licenses/lgpl-3.0.html
19
+
20
+ ────────────────────────────────────────────────────────────────────────────
21
+ Cursory — mouse trajectory generation, installed by Myuri
11
22
  ────────────────────────────────────────────────────────────────────────────
12
23
 
13
24
  cursory https://github.com/Vinyzu/cursory (Python, PyPI: cursory)
@@ -17,20 +28,21 @@ Cursory — mouse trajectory generation
17
28
  Licensed under the GNU Lesser General Public License, version 3 or later
18
29
  (LGPL-3.0-or-later). A copy is available at https://www.gnu.org/licenses/lgpl-3.0.html
19
30
 
20
- HOW WE USE IT, AND WHY THAT MATTERS. Both are ORDINARY INSTALLED
21
- DEPENDENCIES — `cursory` is declared in python/pyproject.toml and `cursory-js`
22
- in js/package.json, and each is resolved by the user's own package manager at
23
- install time. Neither is vendored into this repository, copied into our
24
- sources, or bundled into a build artifact: the TypeScript build is `tsc`, which
25
- leaves `require('cursory-js')` as a runtime import rather than inlining it, and
31
+ HOW WE USE THEM, AND WHY THAT MATTERS. All four are ORDINARY INSTALLED
32
+ DEPENDENCIES — `myuri` is declared in python/pyproject.toml and
33
+ `@jwriter20/myuri` in js/package.json, each brings its cursory port as its own
34
+ dependency, and all are resolved by the user's own package manager at install
35
+ time. None is vendored into this repository, copied into our sources, or
36
+ bundled into a build artifact: the TypeScript build is `tsc`, which leaves
37
+ `require('@jwriter20/myuri')` as a runtime import rather than inlining it, and
26
38
  `js/scripts/copy-python.mjs` copies only our own `python/` tree.
27
39
 
28
40
  That arrangement is the one the LGPL is written for, and it is what lets this
29
- product remain under its own licence. It also means a user may replace either
30
- library with a modified version of their own — reinstall the package, and the
31
- driver picks it up — which is the freedom section 4 of the LGPL requires be
32
- preserved. Do not vendor, inline, or bundle either one without taking legal
41
+ product remain under its own licence. It also means a user may replace any of
42
+ these libraries with a modified version of their own — reinstall the package,
43
+ and the driver picks it up — which is the freedom section 4 of the LGPL requires be
44
+ preserved. Do not vendor, inline, or bundle any of them without taking legal
33
45
  advice first; doing so is the change that would put this obligation somewhere
34
46
  other than where it now sits.
35
47
 
36
- We have not modified either library.
48
+ We have not modified any of them.
@@ -6,22 +6,52 @@
6
6
  *
7
7
  * Pluggable because camoufox's juggler re-humanises every mouse.move() it is handed, and running
8
8
  * both measured 82s against 13s on one GeeTest slider; and a touch widget needs touch events, not
9
- * mousemove. See TRIBAL_KNOWLEDGE.md. The 2026-09 cut removed our drag-overshoot redraw and swipe
10
- * wobble in favour of Cursory's raw recordings; the one-pixel tap wobble stayed because a
11
- * motionless tap is a synthetic one.
9
+ * mousemove. See TRIBAL_KNOWLEDGE.md. Paths and keystrokes are myuri's (recorded human movement on
10
+ * cursory-js); the one-pixel tap wobble is ours, because a motionless tap is a synthetic one.
12
11
  */
13
12
  import type { Page, PlaywrightElementHandle } from './playwright-types.js';
14
- import { HumanizationMode, PauseKind } from './kinds.js';
15
- export type { HumanizationMode, PauseKind } from './kinds.js';
13
+ import type { MyuriSettings, Rng } from '@jwriter20/myuri';
14
+ import { HumanizationMode, PauseKind, Speed } from './kinds.js';
15
+ export type { HumanizationMode, PauseKind, Speed } from './kinds.js';
16
16
  export type Point = [number, number];
17
17
  export declare const gauss: (sigma: number) => number;
18
18
  export declare const MAX_EVENT_GAP_MS = 8;
19
19
  export declare const MAX_EVENT_STEP_PX = 16;
20
20
  export declare const MAX_DEVIATION = 0.15;
21
21
  export declare const MIN_DEVIATION_PX = 3;
22
- /** A recorded human movement morphed onto the endpoints, held near the line between them and sampled at least
23
- * once per mouse report; timings are cumulative ms. */
24
- export declare function trajectory(start: Point, end: Point, frequency: number): [Point[], number[]];
22
+ type DeepPartial<T> = {
23
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
24
+ };
25
+ export type HumanizeSettings = DeepPartial<MyuriSettings>;
26
+ /**
27
+ * What each speed changes. `settings` is laid under the caller's `humanizeSettings` (theirs win, key by key);
28
+ * `pauses` scales every wait between gestures. FAST is myuri's recorded human path played 2.5x faster, still a
29
+ * path and still one event per mouse report. On a three-icon Yidun board it took the mouse from 1.9-3.3s to 1.0-1.2s.
30
+ */
31
+ export declare const SPEEDS: Readonly<Record<Speed, {
32
+ settings: HumanizeSettings;
33
+ pauses: number;
34
+ }>>;
35
+ /**
36
+ * One person's hand: myuri's profile for a seed, and the random stream every path and keystroke draws from.
37
+ * The seed draws the person (each speed within myuri's `variation` of the value set), so one solver moves like
38
+ * one person throughout. An unknown settings key throws here, at construction, not mid-solve.
39
+ */
40
+ export declare class Motion {
41
+ readonly speed: Speed;
42
+ readonly seed: number;
43
+ readonly settings: MyuriSettings;
44
+ readonly pauseScale: number;
45
+ readonly rng: Rng;
46
+ constructor(settings?: HumanizeSettings | null, seed?: number, speed?: Speed);
47
+ }
48
+ /** myuri's human movement from `start` to `end`, held near the line between them and sampled at least once per
49
+ * mouse report; timings are cumulative ms. */
50
+ export declare function trajectory(start: Point, end: Point, motion?: Motion): [Point[], number[]];
51
+ /** `config.speed`, else CAPTCHA_SPEED, else human. */
52
+ export declare function resolveSpeed(config?: {
53
+ speed?: Speed | string;
54
+ }): Speed;
25
55
  /** Every inter-gesture wait the driver takes, named, so each device supplies its own table. */
26
56
  export declare const PAUSE_KINDS: readonly PauseKind[];
27
57
  /** How often a held press looks at the widget, in ms: a frame hash per look, so not every frame. */
@@ -54,7 +84,8 @@ export declare abstract class BaseHumanizer implements Humanizer {
54
84
  abstract readonly hovers: boolean;
55
85
  protected abstract readonly pauses: PauseTable;
56
86
  at: Point;
57
- constructor(start?: Point);
87
+ readonly motion: Motion;
88
+ constructor(start?: Point, motion?: Motion);
58
89
  reset(_page: Page): Promise<void>;
59
90
  abstract move(page: Page, to: Point): Promise<void>;
60
91
  /**
@@ -77,11 +108,11 @@ export declare class MouseHumanizer extends BaseHumanizer {
77
108
  readonly name: HumanizationMode;
78
109
  readonly hovers = true;
79
110
  protected readonly pauses: PauseTable;
80
- private frequency;
81
111
  private viewportCache;
82
112
  /** Undefined until the first move of a solve measures it. */
83
113
  private browserDrawsPath;
84
- constructor(start?: Point, frequency?: number);
114
+ /** A number in place of `motion` is the pre-5.2.0 `frequency`, accepted and ignored: myuri samples at the recording's own rate. */
115
+ constructor(start?: Point, motion?: Motion | number);
85
116
  reset(_page: Page): Promise<void>;
86
117
  /** The window to keep the cursor inside; null under camoufox, which reports no viewport and whose window we ask instead. */
87
118
  private viewport;
@@ -98,7 +129,10 @@ export declare class MouseHumanizer extends BaseHumanizer {
98
129
  move(page: Page, to: Point): Promise<void>;
99
130
  press(page: Page): Promise<void>;
100
131
  release(page: Page): Promise<void>;
101
- /** Per character with a humanised pause, not type(text, {delay}): a constant inter-key delay is itself a signal these vendors score. */
132
+ /**
133
+ * myuri's keystrokes, not type(text, {delay}): a constant inter-key delay is itself a signal these vendors score.
134
+ * Each key is pressed and released at its planned time, rollover and the odd corrected typo included.
135
+ */
102
136
  typeText(page: Page, _field: PlaywrightElementHandle, text: string): Promise<boolean>;
103
137
  }
104
138
  /** `[x, y, dtMs]`: dt is the wait before that sample. */
@@ -177,12 +211,12 @@ export declare class MobileHumanizer extends BaseHumanizer {
177
211
  private backend;
178
212
  private driver;
179
213
  private transform;
180
- private frequency;
181
214
  private down;
182
215
  constructor(start?: Point, options?: {
183
216
  backend?: TouchBackend;
184
217
  driver?: any;
185
218
  transform?: TouchTransform;
219
+ motion?: Motion; /** Ignored since 5.2.0. */
186
220
  frequency?: number;
187
221
  });
188
222
  /** A solve that ended mid-gesture leaves a pointer down in the session's input state; lift it before the next one. */
@@ -220,6 +254,8 @@ export interface HumanizerOptions {
220
254
  x: number;
221
255
  y: number;
222
256
  };
257
+ speed?: Speed;
258
+ humanizeSettings?: HumanizeSettings;
223
259
  }
224
260
  /**
225
261
  * `config.humanizer`, else `config.humanization`, else CAPTCHA_HUMANIZATION, else mouse. The env var loses
package/dist/humanize.js CHANGED
@@ -7,17 +7,17 @@
7
7
  *
8
8
  * Pluggable because camoufox's juggler re-humanises every mouse.move() it is handed, and running
9
9
  * both measured 82s against 13s on one GeeTest slider; and a touch widget needs touch events, not
10
- * mousemove. See TRIBAL_KNOWLEDGE.md. The 2026-09 cut removed our drag-overshoot redraw and swipe
11
- * wobble in favour of Cursory's raw recordings; the one-pixel tap wobble stayed because a
12
- * motionless tap is a synthetic one.
10
+ * mousemove. See TRIBAL_KNOWLEDGE.md. Paths and keystrokes are myuri's (recorded human movement on
11
+ * cursory-js); the one-pixel tap wobble is ours, because a motionless tap is a synthetic one.
13
12
  */
14
13
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.MODES = exports.NullHumanizer = exports.MobileHumanizer = exports.TouchscreenTouchBackend = exports.AppiumTouchBackend = exports.CdpTouchBackend = exports.MouseHumanizer = exports.BROWSER_PATH_MS = exports.BaseHumanizer = exports.HOLD_POLL_MS = exports.PAUSE_KINDS = exports.MIN_DEVIATION_PX = exports.MAX_DEVIATION = exports.MAX_EVENT_STEP_PX = exports.MAX_EVENT_GAP_MS = exports.gauss = void 0;
14
+ exports.MODES = exports.NullHumanizer = exports.MobileHumanizer = exports.TouchscreenTouchBackend = exports.AppiumTouchBackend = exports.CdpTouchBackend = exports.MouseHumanizer = exports.BROWSER_PATH_MS = exports.BaseHumanizer = exports.HOLD_POLL_MS = exports.PAUSE_KINDS = exports.Motion = exports.SPEEDS = exports.MIN_DEVIATION_PX = exports.MAX_DEVIATION = exports.MAX_EVENT_STEP_PX = exports.MAX_EVENT_GAP_MS = exports.gauss = void 0;
16
15
  exports.trajectory = trajectory;
16
+ exports.resolveSpeed = resolveSpeed;
17
17
  exports.hold = hold;
18
18
  exports.touchBackendFor = touchBackendFor;
19
19
  exports.resolveHumanizer = resolveHumanizer;
20
- const cursory_js_1 = require("cursory-js");
20
+ const myuri_1 = require("@jwriter20/myuri");
21
21
  const kinds_js_1 = require("./kinds.js");
22
22
  const delay = (ms) => new Promise((r) => setTimeout(r, Math.max(0, ms)));
23
23
  const log = (m) => console.log(`[captchakraken] ${m}`);
@@ -32,12 +32,13 @@ const gauss = (sigma) => {
32
32
  };
33
33
  exports.gauss = gauss;
34
34
  const closedError = (e) => /Target closed|Session closed/.test(e instanceof Error ? e.message : String(e));
35
- // What one mouse event may cover. cursory's samples are up to 250 ms and 560 px apart, which the page sees as a
35
+ // What one mouse event may cover. myuri plays one sample per recorded report, but a recording's reports can be
36
+ // 70 ms and 230 px apart, which the page sees as a
36
37
  // cursor that vanishes and reappears: a teleport. A real mouse reports every 8 ms (125 Hz).
37
38
  exports.MAX_EVENT_GAP_MS = 8;
38
39
  exports.MAX_EVENT_STEP_PX = 16;
39
40
  // How far a reach may swing off the straight line between its endpoints: a fraction of its length, at least a few
40
- // pixels. cursory morphs a long recorded movement onto any pair of points, so a 5 px move swung 61 px wide and a
41
+ // pixels. cursory (under myuri) morphs a long recorded movement onto any pair of points, so a 5 px move swung 61 px wide and a
41
42
  // 140 px one 300 px.
42
43
  exports.MAX_DEVIATION = 0.15;
43
44
  exports.MIN_DEVIATION_PX = 3;
@@ -73,12 +74,64 @@ function densify(points, timings) {
73
74
  }
74
75
  return [outP, outT];
75
76
  }
76
- /** A recorded human movement morphed onto the endpoints, held near the line between them and sampled at least
77
- * once per mouse report; timings are cumulative ms. */
78
- function trajectory(start, end, frequency) {
79
- const { points, timings } = (0, cursory_js_1.generateTrajectory)(start, end, { frequency });
77
+ /**
78
+ * What each speed changes. `settings` is laid under the caller's `humanizeSettings` (theirs win, key by key);
79
+ * `pauses` scales every wait between gestures. FAST is myuri's recorded human path played 2.5x faster, still a
80
+ * path and still one event per mouse report. On a three-icon Yidun board it took the mouse from 1.9-3.3s to 1.0-1.2s.
81
+ */
82
+ exports.SPEEDS = {
83
+ [kinds_js_1.Speed.HUMAN]: { settings: {}, pauses: 1 },
84
+ [kinds_js_1.Speed.FAST]: { settings: { mouse: { speedFactor: 2.5 }, typing: { wpm: 110 } }, pauses: 0.5 },
85
+ };
86
+ const isPlain = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
87
+ function merge(under, over) {
88
+ const out = structuredClone(under);
89
+ for (const [k, v] of Object.entries(over))
90
+ out[k] = isPlain(v) && isPlain(out[k]) ? merge(out[k], v) : v;
91
+ return out;
92
+ }
93
+ /**
94
+ * One person's hand: myuri's profile for a seed, and the random stream every path and keystroke draws from.
95
+ * The seed draws the person (each speed within myuri's `variation` of the value set), so one solver moves like
96
+ * one person throughout. An unknown settings key throws here, at construction, not mid-solve.
97
+ */
98
+ class Motion {
99
+ constructor(settings, seed, speed = kinds_js_1.Speed.HUMAN) {
100
+ if (settings != null && !isPlain(settings))
101
+ throw new Error(`humanizeSettings must be an object of myuri settings, not ${typeof settings}`);
102
+ if (!(0, kinds_js_1.isOneOf)(kinds_js_1.Speed, speed))
103
+ throw new Error(`unknown speed '${speed}'; expected one of ${Object.values(kinds_js_1.Speed).join(', ')}`);
104
+ this.speed = speed;
105
+ this.seed = seed ?? (0, myuri_1.generateRandomSeed)();
106
+ const merged = merge(exports.SPEEDS[speed].settings, (settings ?? {}));
107
+ try {
108
+ this.settings = (0, myuri_1.generateProfile)(this.seed, merged);
109
+ }
110
+ catch (e) {
111
+ throw new Error(`humanizeSettings: ${e instanceof Error ? e.message : e}. See https://github.com/JWriter20/Myuri#settings for every key`);
112
+ }
113
+ this.pauseScale = exports.SPEEDS[speed].pauses;
114
+ this.rng = (0, myuri_1.makeRng)(this.seed);
115
+ }
116
+ }
117
+ exports.Motion = Motion;
118
+ /** myuri's human movement from `start` to `end`, held near the line between them and sampled at least once per
119
+ * mouse report; timings are cumulative ms. */
120
+ function trajectory(start, end, motion = new Motion()) {
80
121
  const s = [Number(start[0]), Number(start[1])], e = [Number(end[0]), Number(end[1])];
81
- return densify(tame(points.map((q) => [Number(q[0]), Number(q[1])]), s, e), timings.map(Number));
122
+ if (samePoint(s, e))
123
+ return [[e], [0]];
124
+ const planned = (0, myuri_1.planMove)({ x: s[0], y: s[1] }, { x: e[0], y: e[1] }, motion.rng, { settings: motion.settings });
125
+ const points = tame([s, ...planned.map((q) => [Number(q.x), Number(q.y)])], s, e);
126
+ points[points.length - 1] = e;
127
+ return densify(points, [0, ...planned.map((q) => Number(q.t))]);
128
+ }
129
+ /** `config.speed`, else CAPTCHA_SPEED, else human. */
130
+ function resolveSpeed(config = {}) {
131
+ const raw = (config.speed || process.env.CAPTCHA_SPEED || kinds_js_1.Speed.HUMAN).toString().trim().toLowerCase();
132
+ if (!(0, kinds_js_1.isOneOf)(kinds_js_1.Speed, raw))
133
+ throw new Error(`unknown speed '${raw}'; expected one of ${Object.values(kinds_js_1.Speed).join(', ')}`);
134
+ return raw;
82
135
  }
83
136
  /** Every inter-gesture wait the driver takes, named, so each device supplies its own table. */
84
137
  exports.PAUSE_KINDS = Object.values(kinds_js_1.PauseKind);
@@ -110,8 +163,9 @@ async function hold(human, page, to, done, maxMs) {
110
163
  }
111
164
  }
112
165
  class BaseHumanizer {
113
- constructor(start = [0, 0]) {
166
+ constructor(start = [0, 0], motion) {
114
167
  this.at = [Number(start[0]), Number(start[1])];
168
+ this.motion = motion ?? new Motion();
115
169
  }
116
170
  async reset(_page) { }
117
171
  /**
@@ -124,7 +178,7 @@ class BaseHumanizer {
124
178
  /** An unknown kind waits nothing, so adding a pause site cannot break a custom humanizer written against an older release. */
125
179
  pauseMs(kind) {
126
180
  const range = this.pauses[kind];
127
- return range ? uniform(range[0], range[1]) : 0;
181
+ return range ? uniform(range[0], range[1]) * this.motion.pauseScale : 0;
128
182
  }
129
183
  async pause(kind) {
130
184
  await delay(this.pauseMs(kind));
@@ -148,15 +202,15 @@ exports.BaseHumanizer = BaseHumanizer;
148
202
  /** How much longer than the bare round trip a step takes when the browser re-draws it as a path of its own. */
149
203
  exports.BROWSER_PATH_MS = 100;
150
204
  class MouseHumanizer extends BaseHumanizer {
151
- constructor(start = [0, 0], frequency = 60) {
152
- super(start);
205
+ /** A number in place of `motion` is the pre-5.2.0 `frequency`, accepted and ignored: myuri samples at the recording's own rate. */
206
+ constructor(start = [0, 0], motion) {
207
+ super(start, motion instanceof Motion ? motion : undefined);
153
208
  this.name = kinds_js_1.HumanizationMode.MOUSE;
154
209
  this.hovers = true;
155
210
  this.pauses = {
156
211
  tap: [20, 50], between: [80, 160], grab: [50, 100], drop: [50, 100],
157
212
  probe: [40, 80], settle: [90, 210], key: [45, 135],
158
213
  };
159
- this.frequency = frequency;
160
214
  }
161
215
  async reset(_page) {
162
216
  this.viewportCache = undefined;
@@ -233,7 +287,7 @@ class MouseHumanizer extends BaseHumanizer {
233
287
  this.browserDrawsPath ?? (this.browserDrawsPath = await this.measureBrowserPath(page, to));
234
288
  if (this.browserDrawsPath)
235
289
  return this.drift(page, await this.clamp(page, to));
236
- const [points, timings] = trajectory(this.at, to, this.frequency);
290
+ const [points, timings] = trajectory(this.at, to, this.motion);
237
291
  const startTime = Date.now();
238
292
  for (let i = 0; i < points.length; i++) {
239
293
  const [cx, cy] = await this.clamp(page, points[i]);
@@ -254,22 +308,31 @@ class MouseHumanizer extends BaseHumanizer {
254
308
  }
255
309
  async press(page) { await page.mouse.down(); }
256
310
  async release(page) { await page.mouse.up(); }
257
- /** Per character with a humanised pause, not type(text, {delay}): a constant inter-key delay is itself a signal these vendors score. */
311
+ /**
312
+ * myuri's keystrokes, not type(text, {delay}): a constant inter-key delay is itself a signal these vendors score.
313
+ * Each key is pressed and released at its planned time, rollover and the odd corrected typo included.
314
+ */
258
315
  async typeText(page, _field, text) {
259
316
  // Clear first: a retry round arrives with the previous attempt still in the box, and typing would append.
260
317
  try {
261
318
  await page.keyboard.press('Control+A');
262
319
  }
263
- catch { /* the type below still replaces on most */ }
264
- for (const ch of text) {
320
+ catch { /* the keys below still replace on most */ }
321
+ const typing = this.motion.settings.typing;
322
+ const steps = (0, myuri_1.planType)(text, this.motion.rng, { wpm: typing.wpm, mistakeMultiplier: typing.mistakeMultiplier, pauses: typing.pauses });
323
+ const start = Date.now();
324
+ for (const [t, kind, key] of steps) {
325
+ await delay(start + t - Date.now());
265
326
  try {
266
- await page.keyboard.type(ch);
327
+ if (kind === 'insert')
328
+ await page.keyboard.insertText(key);
329
+ else
330
+ await page.keyboard[kind](key);
267
331
  }
268
332
  catch (e) {
269
333
  log(`could not type into the captcha field: ${e}`);
270
334
  return false;
271
335
  }
272
- await this.pause(kinds_js_1.PauseKind.KEY);
273
336
  }
274
337
  return true;
275
338
  }
@@ -431,7 +494,7 @@ async function touchBackendFor(page, driver, transform) {
431
494
  /** A finger on glass: no hover, touch events only, slower and more variable pauses. */
432
495
  class MobileHumanizer extends BaseHumanizer {
433
496
  constructor(start = [0, 0], options = {}) {
434
- super(start);
497
+ super(start, options.motion);
435
498
  this.name = kinds_js_1.HumanizationMode.MOBILE;
436
499
  this.hovers = false;
437
500
  // tap: measured human touch dwell clusters at 60-120ms. key: a soft keyboard is ~3x slower than a physical one.
@@ -443,7 +506,6 @@ class MobileHumanizer extends BaseHumanizer {
443
506
  this.backend = options.backend ?? null;
444
507
  this.driver = options.driver;
445
508
  this.transform = options.transform;
446
- this.frequency = options.frequency ?? 90;
447
509
  }
448
510
  /** A solve that ended mid-gesture leaves a pointer down in the session's input state; lift it before the next one. */
449
511
  async reset(page) {
@@ -463,7 +525,7 @@ class MobileHumanizer extends BaseHumanizer {
463
525
  async move(page, to) {
464
526
  const dest = [Number(to[0]), Number(to[1])];
465
527
  if (this.down) {
466
- const [points, timings] = trajectory(this.at, dest, this.frequency);
528
+ const [points, timings] = trajectory(this.at, dest, this.motion);
467
529
  await (await this.touch(page)).move(points.map(([x, y], i) => [x, y, timings[i] - (i ? timings[i - 1] : 0)]));
468
530
  }
469
531
  this.at = dest;
@@ -586,9 +648,10 @@ function resolveHumanizer(config = {}) {
586
648
  }
587
649
  const p = config.startingMousePosition;
588
650
  const start = p ? [p.x, p.y] : [0, 0];
651
+ const motion = new Motion(config.humanizeSettings, undefined, resolveSpeed(config));
589
652
  if (raw === kinds_js_1.HumanizationMode.MOBILE)
590
- return new MobileHumanizer(start, { driver: config.touchDriver, transform: config.touchTransform });
653
+ return new MobileHumanizer(start, { driver: config.touchDriver, transform: config.touchTransform, motion });
591
654
  if (raw === kinds_js_1.HumanizationMode.NONE)
592
- return new NullHumanizer(start);
593
- return new MouseHumanizer(start);
655
+ return new NullHumanizer(start, motion);
656
+ return new MouseHumanizer(start, motion);
594
657
  }
package/dist/index.d.ts CHANGED
@@ -12,6 +12,6 @@ export type { RoundVerdict } from './verdicts';
12
12
  export { ErrorCode, FrameRole, Outcome, SolveStage, Verdict } from './kinds';
13
13
  export { CaptchaKrakenAPIError } from './errors';
14
14
  export type { CaptchaKrakenErrorCode } from './errors';
15
- export { MobileHumanizer, MouseHumanizer, NullHumanizer } from './humanize';
16
- export type { Humanizer, Point, TouchBackend, TouchTransform } from './humanize';
17
- export { PauseKind } from './kinds';
15
+ export { MobileHumanizer, Motion, MouseHumanizer, NullHumanizer } from './humanize';
16
+ export type { HumanizeSettings, Humanizer, Point, TouchBackend, TouchTransform } from './humanize';
17
+ export { PauseKind, Speed } from './kinds';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  // The published surface: what a caller constructs, configures, receives or implements. Everything else is internal
3
3
  // and can change in any release; add a name here only when a caller needs to write it.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.PauseKind = exports.NullHumanizer = exports.MouseHumanizer = exports.MobileHumanizer = exports.CaptchaKrakenAPIError = exports.Verdict = exports.SolveStage = exports.Outcome = exports.FrameRole = exports.ErrorCode = exports.Vendor = exports.PromptFamily = exports.HumanizationMode = exports.loadConfig = exports.SelectorConfigError = exports.DEFAULT_CONFIG_PATH = exports.fromPuppeteer = exports.watchPage = exports.CaptchaKrakenSolver = void 0;
5
+ exports.Speed = exports.PauseKind = exports.NullHumanizer = exports.MouseHumanizer = exports.Motion = exports.MobileHumanizer = exports.CaptchaKrakenAPIError = exports.Verdict = exports.SolveStage = exports.Outcome = exports.FrameRole = exports.ErrorCode = exports.Vendor = exports.PromptFamily = exports.HumanizationMode = exports.loadConfig = exports.SelectorConfigError = exports.DEFAULT_CONFIG_PATH = exports.fromPuppeteer = exports.watchPage = exports.CaptchaKrakenSolver = void 0;
6
6
  // Solving
7
7
  var solver_1 = require("./solver");
8
8
  Object.defineProperty(exports, "CaptchaKrakenSolver", { enumerable: true, get: function () { return solver_1.CaptchaKrakenSolver; } });
@@ -29,7 +29,9 @@ Object.defineProperty(exports, "CaptchaKrakenAPIError", { enumerable: true, get:
29
29
  // Humanizers: the built-in three, and what one of your own implements
30
30
  var humanize_1 = require("./humanize");
31
31
  Object.defineProperty(exports, "MobileHumanizer", { enumerable: true, get: function () { return humanize_1.MobileHumanizer; } });
32
+ Object.defineProperty(exports, "Motion", { enumerable: true, get: function () { return humanize_1.Motion; } });
32
33
  Object.defineProperty(exports, "MouseHumanizer", { enumerable: true, get: function () { return humanize_1.MouseHumanizer; } });
33
34
  Object.defineProperty(exports, "NullHumanizer", { enumerable: true, get: function () { return humanize_1.NullHumanizer; } });
34
35
  var kinds_3 = require("./kinds");
35
36
  Object.defineProperty(exports, "PauseKind", { enumerable: true, get: function () { return kinds_3.PauseKind; } });
37
+ Object.defineProperty(exports, "Speed", { enumerable: true, get: function () { return kinds_3.Speed; } });
package/dist/kinds.d.ts CHANGED
@@ -80,6 +80,12 @@ export declare const HumanizationMode: {
80
80
  readonly NONE: "none";
81
81
  };
82
82
  export type HumanizationMode = (typeof HumanizationMode)[keyof typeof HumanizationMode];
83
+ /** How fast the hand goes. HUMAN is an ordinary person; FAST is one who has done this captcha a hundred times. */
84
+ export declare const Speed: {
85
+ readonly HUMAN: "human";
86
+ readonly FAST: "fast";
87
+ };
88
+ export type Speed = (typeof Speed)[keyof typeof Speed];
83
89
  export declare const PauseKind: {
84
90
  readonly TAP: "tap";
85
91
  readonly BETWEEN: "between";
package/dist/kinds.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * `as const` objects rather than `enum`: a literal off the wire (`'click'`) type-checks against them, an `enum` would not.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ErrorCode = exports.FrameRole = exports.SolveStage = exports.Phase = exports.Verdict = exports.Outcome = exports.PauseKind = exports.HumanizationMode = exports.PromptFamily = exports.RecaptchaBanner = exports.KeyframeMode = exports.PaintVerdict = exports.SettleVerdict = exports.RetryMode = exports.ActionKind = exports.Vendor = void 0;
7
+ exports.ErrorCode = exports.FrameRole = exports.SolveStage = exports.Phase = exports.Verdict = exports.Outcome = exports.PauseKind = exports.Speed = exports.HumanizationMode = exports.PromptFamily = exports.RecaptchaBanner = exports.KeyframeMode = exports.PaintVerdict = exports.SettleVerdict = exports.RetryMode = exports.ActionKind = exports.Vendor = void 0;
8
8
  exports.isOneOf = isOneOf;
9
9
  /** `puzzleSource` everywhere. UNKNOWN must stay permissive: the CLI, scripts and the offline grader report it. */
10
10
  exports.Vendor = {
@@ -39,6 +39,8 @@ exports.RecaptchaBanner = { SELECT_MORE: 'select-more', DYNAMIC_MORE: 'dynamic-m
39
39
  /** One expert per family; `pixel` is spelled to match ckgate's prompt markers. */
40
40
  exports.PromptFamily = { PIXEL: 'pixel', GRID: 'grid', VIDEO: 'video', TEXT: 'text' };
41
41
  exports.HumanizationMode = { MOUSE: 'mouse', MOBILE: 'mobile', NONE: 'none' };
42
+ /** How fast the hand goes. HUMAN is an ordinary person; FAST is one who has done this captcha a hundred times. */
43
+ exports.Speed = { HUMAN: 'human', FAST: 'fast' };
42
44
  exports.PauseKind = { TAP: 'tap', BETWEEN: 'between', GRAB: 'grab', DROP: 'drop', PROBE: 'probe', SETTLE: 'settle', KEY: 'key' };
43
45
  exports.Outcome = { SOLVED: 'solved', FAILED: 'failed' };
44
46
  /** What the vendor's own server answered a round: BLOCKED is a refusal to serve at all, not a wrong answer. */
@@ -87,7 +87,7 @@ export interface PlaywrightPage extends PlaywrightScope {
87
87
  clickCount?: number;
88
88
  }): Promise<void>;
89
89
  };
90
- /** `type` is called per character by the humanizer; a constant `delay` would itself be a signal. */
90
+ /** The humanizer presses and releases each key at a planned time; a constant `delay` would itself be a signal. */
91
91
  keyboard: {
92
92
  type(text: string, options?: {
93
93
  delay?: number;
@@ -95,6 +95,9 @@ export interface PlaywrightPage extends PlaywrightScope {
95
95
  press(key: string, options?: {
96
96
  delay?: number;
97
97
  }): Promise<void>;
98
+ down(key: string): Promise<void>;
99
+ up(key: string): Promise<void>;
100
+ insertText(text: string): Promise<void>;
98
101
  };
99
102
  waitForTimeout(timeout: number): Promise<void>;
100
103
  waitForSelector(selector: string, options?: {
@@ -108,9 +111,15 @@ export interface PlaywrightPage extends PlaywrightScope {
108
111
  animations?: 'disabled' | 'allow';
109
112
  style?: string;
110
113
  scale?: 'css' | 'device';
114
+ clip?: {
115
+ x: number;
116
+ y: number;
117
+ width: number;
118
+ height: number;
119
+ };
111
120
  }): Promise<Buffer>;
112
121
  /** Optional: the mouse humanizer asks the window for its size when `viewportSize()` is null (camoufox). */
113
- evaluate?<R>(pageFunction: () => R): Promise<R>;
122
+ evaluate?<R>(pageFunction: (() => R) | string): Promise<R>;
114
123
  context?(): {
115
124
  newCDPSession(page: PlaywrightPage): Promise<any>;
116
125
  };
@@ -31,13 +31,20 @@ interface PuppeteerPage {
31
31
  press(key: string, options?: any): Promise<void>;
32
32
  down(key: string, options?: any): Promise<void>;
33
33
  up(key: string): Promise<void>;
34
+ sendCharacter(char: string): Promise<void>;
34
35
  };
35
36
  waitForSelector(selector: string, options?: any): Promise<PuppeteerElementHandle | null>;
36
37
  viewport(): ViewportSize | null;
37
38
  screenshot(options?: {
38
39
  type?: 'png';
40
+ clip?: {
41
+ x: number;
42
+ y: number;
43
+ width: number;
44
+ height: number;
45
+ };
39
46
  }): Promise<Uint8Array>;
40
- evaluate<R>(pageFunction: () => R): Promise<R>;
47
+ evaluate<R>(pageFunction: (() => R) | string): Promise<R>;
41
48
  $$(selector: string): Promise<PuppeteerElementHandle[]>;
42
49
  isClosed(): boolean;
43
50
  evaluate(pageFunction: () => any): Promise<any>;
@@ -106,12 +106,16 @@ function fromPuppeteer(page) {
106
106
  for (const mod of parts.reverse())
107
107
  await page.keyboard.up(mod);
108
108
  },
109
+ down: (key) => page.keyboard.down(key),
110
+ up: (key) => page.keyboard.up(key),
111
+ insertText: (text) => page.keyboard.sendCharacter(text),
109
112
  },
110
113
  waitForTimeout: (timeout) => new Promise((resolve) => setTimeout(resolve, timeout)),
111
114
  waitForSelector: async (selector, options) => wrapHandle(await page.waitForSelector(selector, toPuppeteerSelectorOptions(options))),
112
115
  viewportSize: () => page.viewport(),
113
116
  // Puppeteer has no `animations` option, and its own timeout; the capture is PNG either way.
114
- screenshot: async ({ style } = {}) => styled(async () => page.frames().map((frame) => ({ frame })), style, async () => Buffer.from(await page.screenshot({ type: 'png' }))),
117
+ // A clip is only asked of Firefox (see drawsClipsOffscreen), which Puppeteer can drive too.
118
+ screenshot: async ({ style, clip } = {}) => styled(async () => page.frames().map((frame) => ({ frame })), style, async () => Buffer.from(await page.screenshot({ type: 'png', ...(clip ? { clip } : {}) }))),
115
119
  evaluate: (pageFunction) => page.evaluate(pageFunction),
116
120
  locator: (selector) => locatorOver(() => page.$$(selector)),
117
121
  // Forwarded explicitly: without it the watcher polls a dead page forever.
@@ -134,8 +134,18 @@ export declare class SelectorTable {
134
134
  /** Every host-page selector with what it names, in detection order: open challenges, then checkboxes, then inline widgets. */
135
135
  readonly widgetProbes: ReadonlyArray<WidgetProbe>;
136
136
  readonly enclave: readonly string[];
137
+ /**
138
+ * The frames a widget may sit inside: a vendor's enclave, or any frame no vendor serves (a block page, a modal, an
139
+ * embed). A vendor's own frame is its widget, read through the probes, never searched as a page.
140
+ */
141
+ readonly frames: readonly string[];
137
142
  readonly response: readonly string[];
138
143
  readonly accepted: readonly string[];
144
+ /**
145
+ * Anything of a vendor's a document can hold. A frame walked into that holds none of it (an ad, a login button) is
146
+ * passed through to the frames inside it, but no probe is read in it: every probe costs a round trip per frame.
147
+ */
148
+ readonly markers: string;
139
149
  /** A real Verify/Next/Submit/Skip/Confirm first; the vendor-named controls are fallbacks. */
140
150
  readonly submit: readonly string[];
141
151
  readonly textInputVendor: readonly string[];
@@ -158,6 +168,7 @@ export declare const DEFAULT_TABLE: SelectorTable;
158
168
  export declare const VENDORS: readonly (readonly [Vendor, VendorSelectors])[];
159
169
  export declare const WIDGET_PROBES: readonly WidgetProbe[];
160
170
  export declare const ENCLAVE_SELECTORS: readonly string[];
171
+ export declare const FRAME_SELECTORS: readonly string[];
161
172
  export declare const RESPONSE_SELECTORS: readonly string[];
162
173
  export declare const ACCEPTED_SELECTORS: readonly string[];
163
174
  export declare const SUBMIT_SELECTORS: readonly string[];
package/dist/selectors.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PIECE_SELECTORS = exports.REFRESH_SELECTORS = exports.SLIDER_HANDLE_SELECTORS = exports.TEXT_INPUT_SELECTORS = exports.TEXT_INPUT_VENDOR_SELECTORS = exports.SUBMIT_SELECTORS = exports.ACCEPTED_SELECTORS = exports.RESPONSE_SELECTORS = exports.ENCLAVE_SELECTORS = exports.WIDGET_PROBES = exports.VENDORS = exports.DEFAULT_TABLE = exports.SelectorTable = exports.submitByText = exports.SELECTORS = exports.DEFAULT_CONFIG = exports.DEFAULT_CONFIG_PATH = exports.SelectorConfigError = void 0;
6
+ exports.PIECE_SELECTORS = exports.REFRESH_SELECTORS = exports.SLIDER_HANDLE_SELECTORS = exports.TEXT_INPUT_SELECTORS = exports.TEXT_INPUT_VENDOR_SELECTORS = exports.SUBMIT_SELECTORS = exports.ACCEPTED_SELECTORS = exports.RESPONSE_SELECTORS = exports.FRAME_SELECTORS = exports.ENCLAVE_SELECTORS = exports.WIDGET_PROBES = exports.VENDORS = exports.DEFAULT_TABLE = exports.SelectorTable = exports.submitByText = exports.SELECTORS = exports.DEFAULT_CONFIG = exports.DEFAULT_CONFIG_PATH = exports.SelectorConfigError = void 0;
7
7
  exports.loadConfig = loadConfig;
8
8
  /**
9
9
  * Every selector the driver knows, keyed by vendor, read from `captchakraken.config.json` at the repository root. The
@@ -197,8 +197,14 @@ class SelectorTable {
197
197
  const every = (key) => this.vendors.flatMap(([, s]) => s[key] ?? []);
198
198
  this.widgetProbes = DETECTED_BY.flatMap(([role, key]) => this.vendors.flatMap(([vendor, s]) => (s[key] ?? []).map((selector) => ({ vendor, role, selector }))));
199
199
  this.enclave = every('enclave');
200
+ this.frames = [...this.enclave, `iframe${this.vendors.flatMap(([, s]) => s.hosts).map((h) => `:not([src*="${h}"])`).join('')}`];
200
201
  this.response = this.vendors.flatMap(([, s]) => s.response ?? []);
201
202
  this.accepted = this.vendors.flatMap(([, s]) => s.accepted ?? []);
203
+ this.markers = [...new Set([
204
+ ...this.widgetProbes.map((p) => p.selector), ...this.response, ...this.accepted, ...this.enclave,
205
+ ...this.vendors.flatMap(([, s]) => s.passive ?? []),
206
+ ...this.vendors.flatMap(([, s]) => s.hosts.map((h) => `iframe[src*="${h}"]`)),
207
+ ])].join(', ');
202
208
  this.submitVendor = every('submit');
203
209
  this.submit = [...loaded.generic.submit_text.map(exports.submitByText), ...this.submitVendor];
204
210
  this.textInputVendor = every('textInput');
@@ -215,6 +221,7 @@ exports.DEFAULT_TABLE = new SelectorTable(undefined, exports.DEFAULT_CONFIG);
215
221
  exports.VENDORS = exports.DEFAULT_TABLE.vendors;
216
222
  exports.WIDGET_PROBES = exports.DEFAULT_TABLE.widgetProbes;
217
223
  exports.ENCLAVE_SELECTORS = exports.DEFAULT_TABLE.enclave;
224
+ exports.FRAME_SELECTORS = exports.DEFAULT_TABLE.frames;
218
225
  exports.RESPONSE_SELECTORS = exports.DEFAULT_TABLE.response;
219
226
  exports.ACCEPTED_SELECTORS = exports.DEFAULT_TABLE.accepted;
220
227
  exports.SUBMIT_SELECTORS = exports.DEFAULT_TABLE.submit;