captchakraken 4.1.1 → 5.0.0-beta.41

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 (34) hide show
  1. package/README.md +0 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/kinds.d.ts +2 -0
  4. package/dist/kinds.js +2 -0
  5. package/dist/playwright-types.d.ts +2 -0
  6. package/dist/selectors.d.ts +19 -10
  7. package/dist/selectors.js +7 -18
  8. package/dist/solver.d.ts +52 -2
  9. package/dist/solver.js +213 -21
  10. package/package.json +2 -2
  11. package/python/AGENTS.md +5 -4
  12. package/python/README.md +3 -6
  13. package/python/pyproject.toml +6 -9
  14. package/python/src/captchakraken/__init__.py +1 -1
  15. package/python/src/captchakraken/captchakraken.config.json +53 -8
  16. package/python/src/captchakraken/cli.py +2 -47
  17. package/python/src/captchakraken/config.py +0 -4
  18. package/python/src/captchakraken/kinds.py +2 -0
  19. package/python/src/captchakraken/models.json +15 -14
  20. package/python/src/captchakraken/page_solver.py +191 -24
  21. package/python/src/captchakraken/pointer/__init__.py +7 -9
  22. package/python/src/captchakraken/pointer/elements.py +1 -1
  23. package/python/src/captchakraken/pointer/server.py +13 -17
  24. package/python/src/captchakraken/pointer/service.py +35 -324
  25. package/python/src/captchakraken/prompts.py +3 -4
  26. package/python/src/captchakraken/selectors.py +15 -16
  27. package/python/src/captchakraken/selfhost.py +9 -16
  28. package/python/src/captchakraken/server_manager.py +0 -4
  29. package/python/src/captchakraken/solver.py +4 -25
  30. package/python/src/captchakraken/tool_calls/find_checkbox.py +150 -13
  31. package/python/src/captchakraken/tool_calls/find_grid.py +6 -132
  32. package/python/src/captchakraken/tool_calls/slide_tracker.py +10 -1
  33. package/python/src/captchakraken/updater.py +57 -27
  34. package/python/src/captchakraken/pointer/detector.py +0 -333
package/README.md CHANGED
@@ -158,7 +158,6 @@ Full details, including writing your own humanizer:
158
158
  | `CAPTCHA_BASE_MODEL` | Merged v2 weights vLLM loads | `CaptchaKraken/MidnightV2-4B-q4` |
159
159
  | `CAPTCHA_LORA_ADAPTER` | Model repository (HF id or path) | `CaptchaKraken/MidnightV2-4B-q4` |
160
160
  | `CAPTCHA_LORA_NAME` | Served model name sent as `model` | `captcha-pointer` |
161
- | `CAPTCHA_POINTER_DETECTOR` | CNN element detector | set by `captchakraken fetch` |
162
161
  | `CAPTCHA_KRAKEN_AUTOSTART` | `0` never auto-starts a local server | `1` |
163
162
  | `CAPTCHA_KRAKEN_PYTHON` | Interpreter used for the bundled engine | the package's venv, else `python3` |
164
163
  | `CAPTCHA_KRAKEN_SKIP_PYTHON_SETUP` | `1` skips the `postinstall` bootstrap | unset |
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { fromPuppeteer } from './puppeteer-adapter';
5
5
  export type { Page, PlaywrightPage, PlaywrightFrame, PlaywrightElementHandle, PlaywrightLocator, PlaywrightScope } from './playwright-types';
6
6
  export type { CaptchaKrakenConfig } from './types';
7
7
  export { DEFAULT_CONFIG_PATH, SelectorConfigError, loadConfig } from './selectors';
8
- export type { CustomSelectors, DetectorModel, SelectorConfig, SelectorConfigFile, VendorSelectors } from './selectors';
8
+ export type { CustomSelectors, SelectorConfig, SelectorConfigFile, VendorSelectors } from './selectors';
9
9
  export { HumanizationMode, PromptFamily, Vendor } from './kinds';
10
10
  export type { SolveResult, SolveStepEvent, Vector } from './types';
11
11
  export type { RoundVerdict } from './verdicts';
package/dist/kinds.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare const Vendor: {
21
21
  readonly DINGXIANG: "dingxiang";
22
22
  readonly FUNCAPTCHA: "funcaptcha";
23
23
  readonly PROTON: "proton";
24
+ readonly DATADOME: "datadome";
25
+ readonly CYBERSIARA: "cybersiara";
24
26
  readonly UNKNOWN: "unknown";
25
27
  };
26
28
  export type Vendor = (typeof Vendor)[keyof typeof Vendor];
package/dist/kinds.js CHANGED
@@ -25,6 +25,8 @@ exports.Vendor = {
25
25
  DINGXIANG: 'dingxiang',
26
26
  FUNCAPTCHA: 'funcaptcha',
27
27
  PROTON: 'proton',
28
+ DATADOME: 'datadome',
29
+ CYBERSIARA: 'cybersiara',
28
30
  UNKNOWN: 'unknown',
29
31
  };
30
32
  exports.ActionKind = { CLICK: 'click', DRAG: 'drag', TYPE: 'type', WAIT: 'wait', DONE: 'done', HOLD: 'hold', REFRESH: 'refresh', SLIDE: 'slide' };
@@ -44,6 +44,8 @@ export interface PlaywrightScope {
44
44
  export interface PlaywrightFrame extends PlaywrightScope {
45
45
  /** Optional: its HOSTNAME alone is sent as X-CK-Widget-Host, the host the widget was served from. */
46
46
  url?(): string;
47
+ /** Optional: the frames nested in this one (Playwright and Puppeteer both have it), searched for a vendor's `board`. */
48
+ childFrames?(): PlaywrightFrame[];
47
49
  waitForSelector(selector: string, options?: {
48
50
  state?: 'attached' | 'detached' | 'visible' | 'hidden';
49
51
  timeout?: number;
@@ -25,6 +25,11 @@ export interface VendorSelectors {
25
25
  readonly fresh?: string;
26
26
  /** Inside the challenge frame: the pictures a board is made of; the driver waits for each to have painted. */
27
27
  readonly images?: readonly string[];
28
+ /**
29
+ * Inside the challenge frame: the tiles of the board's grid, in reading order. Where each one is placed is read from
30
+ * the DOM, to click it and to watch it reload.
31
+ */
32
+ readonly tiles?: readonly string[];
28
33
  /** Inside the widget: the vendor's own submit control, tried after the generic text probes. */
29
34
  readonly submit?: readonly string[];
30
35
  /** Inside the challenge frame: verdict banners and what each means. */
@@ -37,6 +42,16 @@ export interface VendorSelectors {
37
42
  readonly textInput?: readonly string[];
38
43
  /** Inside the widget: the knob a slide must start on; a drag from the piece moves nothing. */
39
44
  readonly sliderHandle?: readonly string[];
45
+ /**
46
+ * Beside the widget (a sibling of it, or of its parent): a strip the vendor draws outside the widget element that
47
+ * every board carries, such as Yidun's prompt and slider bar. The shot takes it in.
48
+ */
49
+ readonly bar?: readonly string[];
50
+ /**
51
+ * Inside the widget's frame or a frame nested in it: the board itself, when the widget frame pads it (Proton's
52
+ * 682x600 frame around its 370x534 `.protonCaptchaContainer`). The shot is this element.
53
+ */
54
+ readonly board?: readonly string[];
40
55
  /** Inside the widget: the piece, measured to steer the slide and dragged directly when there is no track. */
41
56
  readonly piece?: readonly string[];
42
57
  /** Inside the widget: the control that deals a new puzzle, pressed when the model answers `refresh`. */
@@ -52,7 +67,8 @@ export interface SelectorConfigFile {
52
67
  readonly custom?: Record<string, unknown> | null;
53
68
  readonly vendors?: Record<string, Record<string, unknown>>;
54
69
  readonly generic?: Record<string, readonly string[]>;
55
- readonly detector?: DetectorModel;
70
+ /** Left from the element detector the client no longer has: still accepted, and ignored. */
71
+ readonly detector?: string;
56
72
  readonly [comment: `_${string}`]: unknown;
57
73
  }
58
74
  /** A selector config the solver cannot use; the message names the file and the key. */
@@ -64,16 +80,7 @@ export interface SelectorConfig {
64
80
  readonly custom: CustomSelectors | null;
65
81
  readonly vendors: ReadonlyArray<readonly [Vendor, VendorSelectors]>;
66
82
  readonly generic: Readonly<Record<GenericKey, readonly string[]>>;
67
- /** Which element detector the engine runs: see `DETECTOR_MODELS`. */
68
- readonly detector: DetectorModel;
69
83
  }
70
- /**
71
- * The element detector's weights: `lite` keeps a board near 100 ms on one vCPU, `standard` is the larger network, and
72
- * `auto` takes `lite` on a machine of two CPUs or fewer, else times one board and takes `standard` when it fits.
73
- * `CAPTCHA_KRAKEN_DETECTOR_MODEL` in the environment overrides the config.
74
- */
75
- export declare const DETECTOR_MODELS: readonly ["auto", "standard", "lite"];
76
- export type DetectorModel = (typeof DETECTOR_MODELS)[number];
77
84
  declare const GENERIC: readonly ["submit_text", "text_input", "slider_handle", "piece"];
78
85
  type GenericKey = (typeof GENERIC)[number];
79
86
  /**
@@ -119,6 +126,8 @@ export declare class SelectorTable {
119
126
  /** A real Verify/Next/Submit/Skip/Confirm first; the vendor-named controls are fallbacks. */
120
127
  readonly submit: readonly string[];
121
128
  readonly textInputVendor: readonly string[];
129
+ /** The vendor-named submit controls alone: the only ones looked for outside the widget, after a typed answer. */
130
+ readonly submitVendor: readonly string[];
122
131
  /**
123
132
  * Vendor-named first, generic last: the driver takes the first visible match, and a generic selector reached before
124
133
  * the vendor's own is how a captcha's answer ends up in a login form's username box.
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.DETECTOR_MODELS = 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.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
@@ -22,17 +22,11 @@ class SelectorConfigError extends Error {
22
22
  }
23
23
  }
24
24
  exports.SelectorConfigError = SelectorConfigError;
25
- /**
26
- * The element detector's weights: `lite` keeps a board near 100 ms on one vCPU, `standard` is the larger network, and
27
- * `auto` takes `lite` on a machine of two CPUs or fewer, else times one board and takes `standard` when it fits.
28
- * `CAPTCHA_KRAKEN_DETECTOR_MODEL` in the environment overrides the config.
29
- */
30
- exports.DETECTOR_MODELS = ['auto', 'standard', 'lite'];
31
25
  const GENERIC = ['submit_text', 'text_input', 'slider_handle', 'piece'];
32
26
  // The file is spelled as the Python port's fields; these three are camelCase here.
33
27
  const CAMEL = { text_input: 'textInput', slider_handle: 'sliderHandle', hold_completes: 'holdCompletes' };
34
28
  const FIELDS = ['hosts', 'challenge', 'checkbox', 'enclave', 'widget', 'response', 'checked', 'box', 'accepted', 'fresh',
35
- 'images', 'submit', 'banners', 'blocked', 'passive', 'text_input', 'slider_handle', 'piece', 'refresh', 'hold_completes'];
29
+ 'images', 'tiles', 'submit', 'banners', 'blocked', 'passive', 'text_input', 'slider_handle', 'bar', 'board', 'piece', 'refresh', 'hold_completes'];
36
30
  const ONE = new Set(['response', 'checked', 'accepted', 'fresh']);
37
31
  const BANNERS = new Set(Object.values(kinds_1.RecaptchaBanner));
38
32
  const VENDOR_VALUES = new Set(Object.values(kinds_1.Vendor));
@@ -96,16 +90,10 @@ function parse(name, doc, base) {
96
90
  if (!isObject(doc))
97
91
  throw new SelectorConfigError(`${name}: the top level must be an object`);
98
92
  for (const key of Object.keys(doc)) {
93
+ // `detector` chose an element detector the client no longer has; a config written for one still loads.
99
94
  if (!key.startsWith('_') && !['detector', 'custom', 'vendors', 'generic'].includes(key)) {
100
- throw new SelectorConfigError(`${name}: ${key}: not a config key (detector, custom, vendors, generic)`);
101
- }
102
- }
103
- let detector = base?.detector ?? 'auto';
104
- if ('detector' in doc) {
105
- if (!exports.DETECTOR_MODELS.includes(doc.detector)) {
106
- throw new SelectorConfigError(`${name}: detector: ${JSON.stringify(doc.detector)} is not one of ${exports.DETECTOR_MODELS.join(', ')}`);
95
+ throw new SelectorConfigError(`${name}: ${key}: not a config key (custom, vendors, generic)`);
107
96
  }
108
- detector = doc.detector;
109
97
  }
110
98
  let custom = base?.custom ?? null;
111
99
  if ('custom' in doc)
@@ -142,7 +130,7 @@ function parse(name, doc, base) {
142
130
  const absent = GENERIC.filter((k) => !generic[k]);
143
131
  if (absent.length)
144
132
  throw new SelectorConfigError(`${name}: generic: missing ${JSON.stringify(absent)}`);
145
- return { custom, vendors: [...vendors], generic: generic, detector };
133
+ return { custom, vendors: [...vendors], generic: generic };
146
134
  }
147
135
  function read(file) {
148
136
  let text;
@@ -211,7 +199,8 @@ class SelectorTable {
211
199
  this.enclave = every('enclave');
212
200
  this.response = this.vendors.flatMap(([, s]) => s.response ?? []);
213
201
  this.accepted = this.vendors.flatMap(([, s]) => s.accepted ?? []);
214
- this.submit = [...loaded.generic.submit_text.map(exports.submitByText), ...every('submit')];
202
+ this.submitVendor = every('submit');
203
+ this.submit = [...loaded.generic.submit_text.map(exports.submitByText), ...this.submitVendor];
215
204
  this.textInputVendor = every('textInput');
216
205
  this.textInput = [...this.textInputVendor, ...loaded.generic.text_input];
217
206
  this.sliderHandle = [...every('sliderHandle'), ...loaded.generic.slider_handle];
package/dist/solver.d.ts CHANGED
@@ -16,13 +16,16 @@ export interface Widget {
16
16
  }
17
17
  /**
18
18
  * A typed captcha's image and its text box, photographed and pointed into as one element.
19
+ * The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
20
+ * float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and on
21
+ * the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
19
22
  *
20
23
  * BotDetect's widget element is a 280x50 strip holding only the image; its text box is a sibling. Every training
21
24
  * board and every real capture of a typed captcha shows the box under the image, and on the bare strip the pointer
22
25
  * read the image as a click puzzle or doubled a glyph. The answer's points are taken in this union's frame, so
23
26
  * `boundingBox` is the union everywhere the round reads it; everything else is the element's own.
24
27
  */
25
- export declare function withAnswerBox(el: ElementHandle, box: ElementHandle): ElementHandle;
28
+ export declare function withAnswerBox(el: ElementHandle, box: ElementHandle, maxGrowth?: number): ElementHandle;
26
29
  /** An allow-list of what needs nothing: the other direction raises instead of clicking at the origin. */
27
30
  export declare function answerNeedsElementBox(actions: ReadonlyArray<{
28
31
  action?: string;
@@ -184,13 +187,19 @@ export declare class CaptchaKrakenSolver {
184
187
  * shows "Verifying…" before its box, so an empty capture is looked at again until `detectionTimeoutMs`.
185
188
  */
186
189
  private findCheckboxOnScreen;
187
- /** One capture and the element detector, no model: a point inside the tick box, or null when none is drawn. */
190
+ /** One capture and plain pixel arithmetic, no model: a point inside the tick box, or null when none is drawn. */
188
191
  private checkboxOnScreen;
189
192
  /**
190
193
  * A clicked checkbox passes or opens a challenge, and both show in the DOM.
191
194
  * Without this wait the next round found the same checkbox still up and clicked it again.
192
195
  */
193
196
  private awaitWhatTheCheckboxOpened;
197
+ /**
198
+ * The widget's Verify, else, after a typed answer, the vendor-named submit beside its text box. BotDetect's Validate
199
+ * sits in the widget's fieldset, outside the 280x50 `.BDC_CaptchaDiv`, like `#captchaCode` (see `answerBox`):
200
+ * without it the code was typed and never sent (live 0/9, 2026-11-13). Only vendor-named selectors widen, so a
201
+ * login form's own Submit is never pressed.
202
+ */
194
203
  private getVerifyButton;
195
204
  /** Any element at `selector` carrying a non-blank value; response fields are hidden, so no visibility filter. */
196
205
  private hasValue;
@@ -258,6 +267,14 @@ export declare class CaptchaKrakenSolver {
258
267
  * GRID_LOAD_CAP_FACTOR times that, or the solve's deadline.
259
268
  */
260
269
  private waitForGridCellsLoaded;
270
+ /**
271
+ * The board's tiles as [x0, y0, x1, y1] pixels of `shotPath`, a screenshot of `captchaElement`, in reading order.
272
+ *
273
+ * Read from the vendor's own markup, not the picture: a tile is where the challenge frame placed it. Tile and
274
+ * iframe boxes are both in page pixels, so a tile less the iframe's corner, scaled, lands on the screenshot.
275
+ * Null when the vendor names no tiles or the frame shows fewer than four.
276
+ */
277
+ private domGrid;
261
278
  private getGridBoxes;
262
279
  private bboxToCell;
263
280
  private cellCenterPage;
@@ -391,6 +408,39 @@ export declare class CaptchaKrakenSolver {
391
408
  private executeRefresh;
392
409
  private executeDrag;
393
410
  private findControl;
411
+ /**
412
+ * The vendor's own `bar`, else the track of its first slider handle, visible with its centre outside the widget
413
+ * element's box. The bar is what Yidun's click modes need: `.yidun_control` holds the 请依次点击 prompt that names the
414
+ * marks and their order, and on the bare `.yidun_panel` the pointer was shown neither (live 0/6 on 2026-11-13). The
415
+ * handle's track covers vendors that name only a handle. Either is looked for in the widget, then in its parent and grandparent: Yidun's `.yidun_slider` is in
416
+ * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
417
+ * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
418
+ * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
419
+ */
420
+ /**
421
+ * The element whose screenshot the model is shown for `widget`, and the text box when it is typed. This is the whole
422
+ * of what the client PHOTOGRAPHS, kept in one place so the capture gate can check it without solving: the widget,
423
+ * else the board its frame pads (Proton), widened by a text box beside it (BotDetect) or by the vendor's bar or
424
+ * slider track outside it (Yidun).
425
+ */
426
+ private framed;
427
+ /**
428
+ * The widget on `page` and the element the solver would photograph for it, without solving anything. For release
429
+ * gates: whether the client finds a vendor's widget, by its selectors and URL markers, and frames the whole board,
430
+ * is checkable on a live page at no inference cost. A checkbox widget is returned with its own element.
431
+ */
432
+ capture(page: Page): Promise<{
433
+ widget: Widget;
434
+ element: ElementHandle;
435
+ } | null>;
436
+ /**
437
+ * The vendor's own `board`, found in the widget's frame or a frame nested in it, or null. Proton's widget frame is
438
+ * 682x600 with its 370x534 `.protonCaptchaContainer` centred two frames down; the pointer trained on that container,
439
+ * and shown the padded frame it repeated one answer until the solve gave up (live 0/2 on 2026-11-13). The board is
440
+ * drawn a moment after the frame, so it is waited for briefly.
441
+ */
442
+ private boardInside;
443
+ private trackOutside;
394
444
  /**
395
445
  * The text box inside the widget, else a vendor-named one in its enclosing fieldset/form, never the page: the generic
396
446
  * tail outside the widget is how a captcha's answer lands in a login form's username box. The widening exists for
package/dist/solver.js CHANGED
@@ -133,15 +133,23 @@ const HANDLE_TIMEOUT_MS = 1000;
133
133
  * times the image's area. A vendor-named box found in the enclosing form can be a whole login form away.
134
134
  */
135
135
  const ANSWER_BOX_MAX_GROWTH = 4;
136
+ /**
137
+ * A slider's handle widens the shot only when it sits just outside the picture: the union may be at most this many
138
+ * times the picture's area. Yidun's bar is 40px under a 175px panel (x1.23).
139
+ */
140
+ const SLIDER_TRACK_MAX_GROWTH = 2;
136
141
  /**
137
142
  * A typed captcha's image and its text box, photographed and pointed into as one element.
143
+ * The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
144
+ * float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and on
145
+ * the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
138
146
  *
139
147
  * BotDetect's widget element is a 280x50 strip holding only the image; its text box is a sibling. Every training
140
148
  * board and every real capture of a typed captcha shows the box under the image, and on the bare strip the pointer
141
149
  * read the image as a click puzzle or doubled a glyph. The answer's points are taken in this union's frame, so
142
150
  * `boundingBox` is the union everywhere the round reads it; everything else is the element's own.
143
151
  */
144
- function withAnswerBox(el, box) {
152
+ function withAnswerBox(el, box, maxGrowth = ANSWER_BOX_MAX_GROWTH) {
145
153
  const union = async () => {
146
154
  const a = await el.boundingBox();
147
155
  const b = a ? await box.boundingBox() : null;
@@ -149,7 +157,7 @@ function withAnswerBox(el, box) {
149
157
  return a;
150
158
  const x0 = Math.min(a.x, b.x), y0 = Math.min(a.y, b.y);
151
159
  const x1 = Math.max(a.x + a.width, b.x + b.width), y1 = Math.max(a.y + a.height, b.y + b.height);
152
- if ((x1 - x0) * (y1 - y0) > ANSWER_BOX_MAX_GROWTH * Math.max(a.width * a.height, 1))
160
+ if ((x1 - x0) * (y1 - y0) > maxGrowth * Math.max(a.width * a.height, 1))
153
161
  return a;
154
162
  return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
155
163
  };
@@ -179,6 +187,17 @@ const SLIDE_MAX_CORRECTIONS = 3;
179
187
  // The nudge that shows the tracker what the handle moves: enough to separate the part from still ground, little
180
188
  // enough that a piece resting against the board's edge stays on it. Mirrors page_solver.py SLIDE_PROBE_PX.
181
189
  const SLIDE_PROBE_PX = 8;
190
+ // A part that moves less than this while the handle travels more than half a probe has reached the end of its track:
191
+ // pushing on only carries the pointer away from the handle. Mirrors page_solver.py SLIDE_STALL_PX.
192
+ const SLIDE_STALL_PX = 1;
193
+ const slideOffset = (s) => (Array.isArray(s) ? [s[0], s[1]] : [s, 0]);
194
+ /** Did the handle travel while the part stayed put? Each side is the travel and the part's point of one look. */
195
+ const slideStalled = (before, now, k) => {
196
+ const [ax, ay] = slideOffset(before[0]);
197
+ const [bx, by] = slideOffset(now[0]);
198
+ const moved = Math.hypot(now[1][0] - before[1][0], now[1][1] - before[1][1]);
199
+ return Math.hypot(bx - ax, by - ay) > (SLIDE_PROBE_PX / 2) * k && moved < SLIDE_STALL_PX * k;
200
+ };
182
201
  /** An allow-list of what needs nothing: the other direction raises instead of clicking at the origin. */
183
202
  function answerNeedsElementBox(actions) {
184
203
  return actions.some((a) => a?.action !== kinds_1.ActionKind.DONE);
@@ -193,6 +212,8 @@ function isClosedTargetError(message) {
193
212
  }
194
213
  /** How often a page that has not drawn its widget yet is looked at again. */
195
214
  const DETECTION_POLL_MS = 250;
215
+ /** How long a widget frame is given to draw the board inside it (`board`) before the frame itself is shot. */
216
+ const BOARD_INSIDE_WAIT_MS = 3000;
196
217
  // Frame-diff thresholds; two screens of one board differ by ~0.0056, a different board by ~0.77.
197
218
  const NOT_THIS_BOARD_DIFF = 0.5;
198
219
  // Tighter than staleFrameDiffThreshold (0.02), which was blind to GeeTest svg; 0.001 is the noise floor.
@@ -745,8 +766,6 @@ class CaptchaKrakenSolver {
745
766
  ...(this.solveWidgetHost ? { CAPTCHA_KRAKEN_WIDGET_HOST: this.solveWidgetHost } : {}),
746
767
  // This driver warns about a legacy model name itself, once; the engine it starts per round stays quiet.
747
768
  CAPTCHA_KRAKEN_MODEL_WARNING: '0',
748
- // The config's detector choice; the caller's own environment variable still wins, as it does in Python.
749
- ...(process.env.CAPTCHA_KRAKEN_DETECTOR_MODEL ? {} : { CAPTCHA_KRAKEN_DETECTOR_MODEL: this.sel.config.detector }),
750
769
  };
751
770
  }
752
771
  /** Fire the optional onStep observer with a fresh screenshot; best-effort, never fails the solve. */
@@ -798,13 +817,9 @@ class CaptchaKrakenSolver {
798
817
  // gate on every dynamic round, on the family with the tightest per-board budget.
799
818
  const painted = puzzleSource === kinds_1.Vendor.RECAPTCHA ? null
800
819
  : await this.ph(kinds_1.Phase.BOARD_PAINT, () => this.waitForBoardPainted(captchaElement));
801
- // Only the DOM can tell a typed captcha from a click puzzle; hCaptcha and reCAPTCHA never type.
802
- const answerBox = VENDORS_WITH_BESPOKE_HANDLING.has(puzzleSource) ? null : await this.answerBox(scope, widget.at);
803
- const textMode = answerBox !== null;
804
- if (textMode) {
805
- console.log('Widget has a text box; solving as a distorted-text captcha.');
806
- captchaElement = withAnswerBox(captchaElement, answerBox);
807
- }
820
+ const framed = await this.framed(widget, frame, scope);
821
+ captchaElement = framed.element;
822
+ const textMode = framed.answerBox !== null;
808
823
  // A reCAPTCHA board is read by its grid below, not filmed.
809
824
  const filmable = puzzleSource !== kinds_1.Vendor.RECAPTCHA && !textMode;
810
825
  if (filmable && !this.knownAnimated)
@@ -837,7 +852,7 @@ class CaptchaKrakenSolver {
837
852
  isAnimated = probing = true;
838
853
  }
839
854
  let establishedGridSize = null;
840
- // The challenge frame only: on the anchor this wasted an 8s grid-load timeout plus a find-grid subprocess.
855
+ // The challenge frame only: on the anchor this wasted an 8s grid-load timeout.
841
856
  if (puzzleSource === kinds_1.Vendor.RECAPTCHA && frameRole === kinds_1.FrameRole.CHALLENGE) {
842
857
  await this.ph(kinds_1.Phase.GRID_LOAD, () => this.waitForGridCellsLoaded(captchaElement));
843
858
  const grid = await this.getGridBoxes(captchaElement);
@@ -876,6 +891,7 @@ class CaptchaKrakenSolver {
876
891
  let performedAction = false;
877
892
  let slid = false;
878
893
  let answered = false;
894
+ let typed = false;
879
895
  let allTokenUsage = [];
880
896
  let burstDir = null;
881
897
  try {
@@ -1090,7 +1106,7 @@ class CaptchaKrakenSolver {
1090
1106
  }
1091
1107
  else if (action.action === kinds_1.ActionKind.TYPE) {
1092
1108
  if (await this.executeType(page, scope, action, widget.at)) {
1093
- performedAction = answered = true;
1109
+ performedAction = answered = typed = true;
1094
1110
  await this.emitStep(captchaElement, kinds_1.SolveStage.TYPE, 'typed the code', puzzleSource, frameRole, attempt, { action });
1095
1111
  }
1096
1112
  }
@@ -1113,7 +1129,8 @@ class CaptchaKrakenSolver {
1113
1129
  // Verify/Skip. FunCaptcha is the exception: its answer is the click itself — an arrow pages, Submit (which the
1114
1130
  // model clicks on the match) submits — so the generic fallback submits page one right after an arrow turned it.
1115
1131
  const submits = slid ? this.submittedOnBoard : answered || !performedAction;
1116
- const verifyButton = submits && puzzleSource !== kinds_1.Vendor.FUNCAPTCHA ? await this.getVerifyButton(scope) : null;
1132
+ const verifyButton = submits && puzzleSource !== kinds_1.Vendor.FUNCAPTCHA
1133
+ ? await this.getVerifyButton(scope, typed ? widget.at : null) : null;
1117
1134
  if (verifyButton) {
1118
1135
  console.log(`Clicking Verify to submit (${puzzleSource}).`);
1119
1136
  await this.moveAndClick(page, verifyButton);
@@ -1189,7 +1206,7 @@ class CaptchaKrakenSolver {
1189
1206
  await delay(DETECTION_POLL_MS);
1190
1207
  }
1191
1208
  }
1192
- /** One capture and the element detector, no model: a point inside the tick box, or null when none is drawn. */
1209
+ /** One capture and plain pixel arithmetic, no model: a point inside the tick box, or null when none is drawn. */
1193
1210
  async checkboxOnScreen(el) {
1194
1211
  const box = await el.boundingBox();
1195
1212
  if (!box)
@@ -1225,8 +1242,18 @@ class CaptchaKrakenSolver {
1225
1242
  }
1226
1243
  });
1227
1244
  }
1228
- getVerifyButton(scope) {
1229
- return this.findControl(scope, this.sel.submit);
1245
+ /**
1246
+ * The widget's Verify, else, after a typed answer, the vendor-named submit beside its text box. BotDetect's Validate
1247
+ * sits in the widget's fieldset, outside the 280x50 `.BDC_CaptchaDiv`, like `#captchaCode` (see `answerBox`):
1248
+ * without it the code was typed and never sent (live 0/9, 2026-11-13). Only vendor-named selectors widen, so a
1249
+ * login form's own Submit is never pressed.
1250
+ */
1251
+ async getVerifyButton(scope, typedAt) {
1252
+ const inside = await this.findControl(scope, this.sel.submit);
1253
+ if (inside !== null || !typedAt)
1254
+ return inside;
1255
+ const around = await Promise.all(['ancestor::fieldset[1]', 'ancestor::form[1]'].map((axis) => this.findControl(typedAt.locator(`xpath=${axis}`), this.sel.submitVendor)));
1256
+ return around.find((h) => h !== null) ?? null;
1230
1257
  }
1231
1258
  /** Any element at `selector` carrying a non-blank value; response fields are hidden, so no visibility filter. */
1232
1259
  async hasValue(scopes, selector) {
@@ -1631,8 +1658,11 @@ class CaptchaKrakenSolver {
1631
1658
  if (frames.length < 2)
1632
1659
  return undefined;
1633
1660
  const late = Date.now() - start >= timeout;
1634
- const res = await this.runCvTool('grid-cell-states', { a: frames[0], b: frames[1] }, ['grid-cell-states', frames[0], frames[1]]);
1635
- if (!res || res.grid === null)
1661
+ const boxes = await this.domGrid(captchaElement, frames[1]);
1662
+ if (!boxes)
1663
+ return late ? false : undefined;
1664
+ const res = await this.runCvTool('grid-cell-states-fixed', { a: frames[0], b: frames[1], grid_boxes: boxes }, ['grid-cell-states-fixed', frames[0], frames[1], JSON.stringify(boxes)]);
1665
+ if (!res)
1636
1666
  return late ? false : undefined;
1637
1667
  if (!Array.isArray(res.loaded) || !res.loaded.length || !Array.isArray(res.changing) || res.changing.length)
1638
1668
  return undefined;
@@ -1642,11 +1672,45 @@ class CaptchaKrakenSolver {
1642
1672
  console.log('[captchakraken] [recaptcha-grid] the board never finished loading; asking about it as it stands');
1643
1673
  return verdict === true;
1644
1674
  }
1675
+ /**
1676
+ * The board's tiles as [x0, y0, x1, y1] pixels of `shotPath`, a screenshot of `captchaElement`, in reading order.
1677
+ *
1678
+ * Read from the vendor's own markup, not the picture: a tile is where the challenge frame placed it. Tile and
1679
+ * iframe boxes are both in page pixels, so a tile less the iframe's corner, scaled, lands on the screenshot.
1680
+ * Null when the vendor names no tiles or the frame shows fewer than four.
1681
+ */
1682
+ async domGrid(captchaElement, shotPath) {
1683
+ const tiles = this.sel.selectors[kinds_1.Vendor.RECAPTCHA].tiles ?? [];
1684
+ const dims = readPngDimensions(shotPath);
1685
+ if (!tiles.length || !dims)
1686
+ return null;
1687
+ try {
1688
+ const frame = await captchaElement.contentFrame();
1689
+ const box = await captchaElement.boundingBox();
1690
+ if (!frame || !box || box.width <= 0 || box.height <= 0)
1691
+ return null;
1692
+ const sx = dims.width / box.width;
1693
+ const sy = dims.height / box.height;
1694
+ const boxes = [];
1695
+ for (const tile of await frame.locator(tiles.join(',')).all()) {
1696
+ const r = await (await tile.elementHandle({ timeout: 1000 }))?.boundingBox();
1697
+ if (!r || r.width <= 0 || r.height <= 0)
1698
+ continue;
1699
+ const x0 = r.x - box.x;
1700
+ const y0 = r.y - box.y;
1701
+ boxes.push([Math.round(x0 * sx), Math.round(y0 * sy), Math.round((x0 + r.width) * sx), Math.round((y0 + r.height) * sy)]);
1702
+ }
1703
+ return boxes.length >= 4 ? boxes : null;
1704
+ }
1705
+ catch {
1706
+ return null;
1707
+ }
1708
+ }
1645
1709
  async getGridBoxes(captchaElement) {
1646
1710
  const f = tmp('findgrid');
1647
1711
  try {
1648
1712
  await this.shot(captchaElement, f);
1649
- const res = await this.runCvTool('find-grid', { image: f }, ['find-grid', f]);
1713
+ const res = await this.domGrid(captchaElement, f);
1650
1714
  const dims = readPngDimensions(f);
1651
1715
  if (!Array.isArray(res) || (res.length !== 9 && res.length !== 16) || !dims)
1652
1716
  return null;
@@ -2897,6 +2961,125 @@ class CaptchaKrakenSolver {
2897
2961
  const [first] = await visible(scope, selectors);
2898
2962
  return first ? handleOf(first) : null;
2899
2963
  }
2964
+ /**
2965
+ * The vendor's own `bar`, else the track of its first slider handle, visible with its centre outside the widget
2966
+ * element's box. The bar is what Yidun's click modes need: `.yidun_control` holds the 请依次点击 prompt that names the
2967
+ * marks and their order, and on the bare `.yidun_panel` the pointer was shown neither (live 0/6 on 2026-11-13). The
2968
+ * handle's track covers vendors that name only a handle. Either is looked for in the widget, then in its parent and grandparent: Yidun's `.yidun_slider` is in
2969
+ * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
2970
+ * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
2971
+ * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
2972
+ */
2973
+ /**
2974
+ * The element whose screenshot the model is shown for `widget`, and the text box when it is typed. This is the whole
2975
+ * of what the client PHOTOGRAPHS, kept in one place so the capture gate can check it without solving: the widget,
2976
+ * else the board its frame pads (Proton), widened by a text box beside it (BotDetect) or by the vendor's bar or
2977
+ * slider track outside it (Yidun).
2978
+ */
2979
+ async framed(widget, frame, scope) {
2980
+ const puzzleSource = widget.vendor;
2981
+ let element = widget.el;
2982
+ // A widget frame that pads its board (Proton) is photographed by the board inside it.
2983
+ const board = await this.boardInside(frame, puzzleSource);
2984
+ if (board) {
2985
+ console.log('The widget frame pads its board; photographing the board itself.');
2986
+ element = board;
2987
+ }
2988
+ // Only the DOM can tell a typed captcha from a click puzzle; hCaptcha and reCAPTCHA never type.
2989
+ const answerBox = VENDORS_WITH_BESPOKE_HANDLING.has(puzzleSource) ? null : await this.answerBox(scope, widget.at);
2990
+ if (answerBox) {
2991
+ console.log('Widget has a text box; solving as a distorted-text captcha.');
2992
+ element = withAnswerBox(element, answerBox);
2993
+ }
2994
+ else if (!VENDORS_WITH_BESPOKE_HANDLING.has(puzzleSource)) {
2995
+ const track = await this.trackOutside(scope, puzzleSource, element, widget.at);
2996
+ if (track) {
2997
+ console.log('The vendor bar or slider track sits outside the widget; photographing the two as one.');
2998
+ element = withAnswerBox(element, track, SLIDER_TRACK_MAX_GROWTH);
2999
+ }
3000
+ }
3001
+ return { element, answerBox };
3002
+ }
3003
+ /**
3004
+ * The widget on `page` and the element the solver would photograph for it, without solving anything. For release
3005
+ * gates: whether the client finds a vendor's widget, by its selectors and URL markers, and frames the whole board,
3006
+ * is checkable on a live page at no inference cost. A checkbox widget is returned with its own element.
3007
+ */
3008
+ async capture(page) {
3009
+ const widget = await this.detectCaptcha(page);
3010
+ if (!widget)
3011
+ return null;
3012
+ if (widget.role === kinds_1.FrameRole.CHECKBOX)
3013
+ return { widget, element: widget.el };
3014
+ const frame = await widget.el.contentFrame();
3015
+ if (widget.vendor !== kinds_1.Vendor.RECAPTCHA)
3016
+ await this.waitForBoardPainted(widget.el);
3017
+ const { element } = await this.framed(widget, frame, frame ?? widget.at);
3018
+ return { widget, element };
3019
+ }
3020
+ /**
3021
+ * The vendor's own `board`, found in the widget's frame or a frame nested in it, or null. Proton's widget frame is
3022
+ * 682x600 with its 370x534 `.protonCaptchaContainer` centred two frames down; the pointer trained on that container,
3023
+ * and shown the padded frame it repeated one answer until the solve gave up (live 0/2 on 2026-11-13). The board is
3024
+ * drawn a moment after the frame, so it is waited for briefly.
3025
+ */
3026
+ async boardInside(frame, vendor) {
3027
+ const own = this.sel.selectors[vendor]?.board;
3028
+ if (!own?.length || !frame)
3029
+ return null;
3030
+ const deadline = Date.now() + BOARD_INSIDE_WAIT_MS;
3031
+ for (;;) {
3032
+ try {
3033
+ const frames = [frame];
3034
+ while (frames.length) {
3035
+ const where = frames.shift();
3036
+ for (const found of await visible(where, own)) {
3037
+ const handle = await handleOf(found);
3038
+ if (handle && (await handle.boundingBox()))
3039
+ return handle;
3040
+ }
3041
+ frames.push(...(where.childFrames?.() ?? []));
3042
+ }
3043
+ }
3044
+ catch {
3045
+ return null;
3046
+ }
3047
+ if (Date.now() >= deadline)
3048
+ return null;
3049
+ await delay(DETECTION_POLL_MS);
3050
+ }
3051
+ }
3052
+ async trackOutside(scope, vendor, el, at) {
3053
+ const mine = this.sel.selectors[vendor];
3054
+ const kinds = [[mine?.bar, true], [mine?.sliderHandle, false]].filter(([s]) => s?.length);
3055
+ if (!kinds.length)
3056
+ return null;
3057
+ // Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
3058
+ try {
3059
+ const a = await el.boundingBox();
3060
+ if (!a)
3061
+ return null;
3062
+ for (const [own, isBar] of kinds) {
3063
+ for (const where of [scope, ...(at ? [1, 2].map((k) => at.locator(`xpath=ancestor::*[${k}]`)) : [])]) {
3064
+ for (const found of await visible(where, own)) {
3065
+ const b = await (await handleOf(found))?.boundingBox();
3066
+ if (!b)
3067
+ continue;
3068
+ const cx = b.x + b.width / 2, cy = b.y + b.height / 2;
3069
+ if (cx >= a.x && cx <= a.x + a.width && cy >= a.y && cy <= a.y + a.height)
3070
+ continue;
3071
+ if (isBar)
3072
+ return handleOf(found);
3073
+ return (await handleOf(found.locator('xpath=..'))) ?? handleOf(found);
3074
+ }
3075
+ }
3076
+ }
3077
+ }
3078
+ catch {
3079
+ return null;
3080
+ }
3081
+ return null;
3082
+ }
2900
3083
  /**
2901
3084
  * The text box inside the widget, else a vendor-named one in its enclosing fieldset/form, never the page: the generic
2902
3085
  * tail outside the widget is how a captcha's answer lands in a login form's username box. The widening exists for
@@ -2988,19 +3171,28 @@ class CaptchaKrakenSolver {
2988
3171
  let look = probed;
2989
3172
  let s = probe * k;
2990
3173
  const history = [];
3174
+ let last = null;
2991
3175
  for (let moves = 0;; moves++) {
2992
3176
  const reply = await this.slideStep({ ...ask, current: look, s, history });
2993
3177
  if (!reply)
2994
3178
  break;
2995
3179
  if (look !== probed)
2996
3180
  history.push(reply.observation);
3181
+ const pos = [reply.pos[0], reply.pos[1]];
3182
+ if (last && slideStalled(last, [s, pos], k)) {
3183
+ console.warn('[slide] the part stopped following the handle; releasing at the end of its track');
3184
+ const [bx, by] = slideOffset(last[0]);
3185
+ await this.performSmoothMove(page, press[0] + bx / k, press[1] + by / k);
3186
+ break;
3187
+ }
3188
+ last = [s, pos];
2997
3189
  if (reply.done || moves >= SLIDE_MAX_CORRECTIONS) {
2998
3190
  if (reply.error > ask.tol)
2999
3191
  console.warn(`[slide] releasing ${(reply.error / k).toFixed(1)}px off target`);
3000
3192
  break;
3001
3193
  }
3002
3194
  s = reply.next;
3003
- const [dx, dy] = Array.isArray(s) ? s : [s, 0];
3195
+ const [dx, dy] = slideOffset(s);
3004
3196
  await this.performSmoothMove(page, press[0] + dx / k, press[1] + dy / k);
3005
3197
  await this.human.pause(kinds_1.PauseKind.PROBE);
3006
3198
  await this.shot(element, current, timeout);