captchakraken 4.2.0 → 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 (33) hide show
  1. package/README.md +0 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/kinds.d.ts +1 -0
  4. package/dist/kinds.js +1 -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 +42 -3
  9. package/dist/solver.js +162 -38
  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 +35 -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 +1 -0
  19. package/python/src/captchakraken/models.json +15 -14
  20. package/python/src/captchakraken/page_solver.py +138 -39
  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/updater.py +57 -27
  33. 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
@@ -22,6 +22,7 @@ export declare const Vendor: {
22
22
  readonly FUNCAPTCHA: "funcaptcha";
23
23
  readonly PROTON: "proton";
24
24
  readonly DATADOME: "datadome";
25
+ readonly CYBERSIARA: "cybersiara";
25
26
  readonly UNKNOWN: "unknown";
26
27
  };
27
28
  export type Vendor = (typeof Vendor)[keyof typeof Vendor];
package/dist/kinds.js CHANGED
@@ -26,6 +26,7 @@ exports.Vendor = {
26
26
  FUNCAPTCHA: 'funcaptcha',
27
27
  PROTON: 'proton',
28
28
  DATADOME: 'datadome',
29
+ CYBERSIARA: 'cybersiara',
29
30
  UNKNOWN: 'unknown',
30
31
  };
31
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
@@ -187,13 +187,19 @@ export declare class CaptchaKrakenSolver {
187
187
  * shows "Verifying…" before its box, so an empty capture is looked at again until `detectionTimeoutMs`.
188
188
  */
189
189
  private findCheckboxOnScreen;
190
- /** 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. */
191
191
  private checkboxOnScreen;
192
192
  /**
193
193
  * A clicked checkbox passes or opens a challenge, and both show in the DOM.
194
194
  * Without this wait the next round found the same checkbox still up and clicked it again.
195
195
  */
196
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
+ */
197
203
  private getVerifyButton;
198
204
  /** Any element at `selector` carrying a non-blank value; response fields are hidden, so no visibility filter. */
199
205
  private hasValue;
@@ -261,6 +267,14 @@ export declare class CaptchaKrakenSolver {
261
267
  * GRID_LOAD_CAP_FACTOR times that, or the solve's deadline.
262
268
  */
263
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;
264
278
  private getGridBoxes;
265
279
  private bboxToCell;
266
280
  private cellCenterPage;
@@ -395,12 +409,37 @@ export declare class CaptchaKrakenSolver {
395
409
  private executeDrag;
396
410
  private findControl;
397
411
  /**
398
- * The track of the first of the vendor's own slider handles that is visible with its centre outside the widget
399
- * element's box. It is looked for in the widget, then in its parent and grandparent: Yidun's `.yidun_slider` is in
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
400
416
  * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
401
417
  * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
402
418
  * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
403
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;
404
443
  private trackOutside;
405
444
  /**
406
445
  * The text box inside the widget, else a vendor-named one in its enclosing fieldset/form, never the page: the generic
package/dist/solver.js CHANGED
@@ -212,6 +212,8 @@ function isClosedTargetError(message) {
212
212
  }
213
213
  /** How often a page that has not drawn its widget yet is looked at again. */
214
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;
215
217
  // Frame-diff thresholds; two screens of one board differ by ~0.0056, a different board by ~0.77.
216
218
  const NOT_THIS_BOARD_DIFF = 0.5;
217
219
  // Tighter than staleFrameDiffThreshold (0.02), which was blind to GeeTest svg; 0.001 is the noise floor.
@@ -764,8 +766,6 @@ class CaptchaKrakenSolver {
764
766
  ...(this.solveWidgetHost ? { CAPTCHA_KRAKEN_WIDGET_HOST: this.solveWidgetHost } : {}),
765
767
  // This driver warns about a legacy model name itself, once; the engine it starts per round stays quiet.
766
768
  CAPTCHA_KRAKEN_MODEL_WARNING: '0',
767
- // The config's detector choice; the caller's own environment variable still wins, as it does in Python.
768
- ...(process.env.CAPTCHA_KRAKEN_DETECTOR_MODEL ? {} : { CAPTCHA_KRAKEN_DETECTOR_MODEL: this.sel.config.detector }),
769
769
  };
770
770
  }
771
771
  /** Fire the optional onStep observer with a fresh screenshot; best-effort, never fails the solve. */
@@ -817,20 +817,9 @@ class CaptchaKrakenSolver {
817
817
  // gate on every dynamic round, on the family with the tightest per-board budget.
818
818
  const painted = puzzleSource === kinds_1.Vendor.RECAPTCHA ? null
819
819
  : await this.ph(kinds_1.Phase.BOARD_PAINT, () => this.waitForBoardPainted(captchaElement));
820
- // Only the DOM can tell a typed captcha from a click puzzle; hCaptcha and reCAPTCHA never type.
821
- const answerBox = VENDORS_WITH_BESPOKE_HANDLING.has(puzzleSource) ? null : await this.answerBox(scope, widget.at);
822
- const textMode = answerBox !== null;
823
- if (textMode) {
824
- console.log('Widget has a text box; solving as a distorted-text captcha.');
825
- captchaElement = withAnswerBox(captchaElement, answerBox);
826
- }
827
- else if (!VENDORS_WITH_BESPOKE_HANDLING.has(puzzleSource)) {
828
- const track = await this.trackOutside(scope, puzzleSource, captchaElement, widget.at);
829
- if (track) {
830
- console.log('The slider track sits outside the widget; photographing the two as one.');
831
- captchaElement = withAnswerBox(captchaElement, track, SLIDER_TRACK_MAX_GROWTH);
832
- }
833
- }
820
+ const framed = await this.framed(widget, frame, scope);
821
+ captchaElement = framed.element;
822
+ const textMode = framed.answerBox !== null;
834
823
  // A reCAPTCHA board is read by its grid below, not filmed.
835
824
  const filmable = puzzleSource !== kinds_1.Vendor.RECAPTCHA && !textMode;
836
825
  if (filmable && !this.knownAnimated)
@@ -863,7 +852,7 @@ class CaptchaKrakenSolver {
863
852
  isAnimated = probing = true;
864
853
  }
865
854
  let establishedGridSize = null;
866
- // 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.
867
856
  if (puzzleSource === kinds_1.Vendor.RECAPTCHA && frameRole === kinds_1.FrameRole.CHALLENGE) {
868
857
  await this.ph(kinds_1.Phase.GRID_LOAD, () => this.waitForGridCellsLoaded(captchaElement));
869
858
  const grid = await this.getGridBoxes(captchaElement);
@@ -902,6 +891,7 @@ class CaptchaKrakenSolver {
902
891
  let performedAction = false;
903
892
  let slid = false;
904
893
  let answered = false;
894
+ let typed = false;
905
895
  let allTokenUsage = [];
906
896
  let burstDir = null;
907
897
  try {
@@ -1116,7 +1106,7 @@ class CaptchaKrakenSolver {
1116
1106
  }
1117
1107
  else if (action.action === kinds_1.ActionKind.TYPE) {
1118
1108
  if (await this.executeType(page, scope, action, widget.at)) {
1119
- performedAction = answered = true;
1109
+ performedAction = answered = typed = true;
1120
1110
  await this.emitStep(captchaElement, kinds_1.SolveStage.TYPE, 'typed the code', puzzleSource, frameRole, attempt, { action });
1121
1111
  }
1122
1112
  }
@@ -1139,7 +1129,8 @@ class CaptchaKrakenSolver {
1139
1129
  // Verify/Skip. FunCaptcha is the exception: its answer is the click itself — an arrow pages, Submit (which the
1140
1130
  // model clicks on the match) submits — so the generic fallback submits page one right after an arrow turned it.
1141
1131
  const submits = slid ? this.submittedOnBoard : answered || !performedAction;
1142
- 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;
1143
1134
  if (verifyButton) {
1144
1135
  console.log(`Clicking Verify to submit (${puzzleSource}).`);
1145
1136
  await this.moveAndClick(page, verifyButton);
@@ -1215,7 +1206,7 @@ class CaptchaKrakenSolver {
1215
1206
  await delay(DETECTION_POLL_MS);
1216
1207
  }
1217
1208
  }
1218
- /** 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. */
1219
1210
  async checkboxOnScreen(el) {
1220
1211
  const box = await el.boundingBox();
1221
1212
  if (!box)
@@ -1251,8 +1242,18 @@ class CaptchaKrakenSolver {
1251
1242
  }
1252
1243
  });
1253
1244
  }
1254
- getVerifyButton(scope) {
1255
- 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;
1256
1257
  }
1257
1258
  /** Any element at `selector` carrying a non-blank value; response fields are hidden, so no visibility filter. */
1258
1259
  async hasValue(scopes, selector) {
@@ -1657,8 +1658,11 @@ class CaptchaKrakenSolver {
1657
1658
  if (frames.length < 2)
1658
1659
  return undefined;
1659
1660
  const late = Date.now() - start >= timeout;
1660
- const res = await this.runCvTool('grid-cell-states', { a: frames[0], b: frames[1] }, ['grid-cell-states', frames[0], frames[1]]);
1661
- 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)
1662
1666
  return late ? false : undefined;
1663
1667
  if (!Array.isArray(res.loaded) || !res.loaded.length || !Array.isArray(res.changing) || res.changing.length)
1664
1668
  return undefined;
@@ -1668,11 +1672,45 @@ class CaptchaKrakenSolver {
1668
1672
  console.log('[captchakraken] [recaptcha-grid] the board never finished loading; asking about it as it stands');
1669
1673
  return verdict === true;
1670
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
+ }
1671
1709
  async getGridBoxes(captchaElement) {
1672
1710
  const f = tmp('findgrid');
1673
1711
  try {
1674
1712
  await this.shot(captchaElement, f);
1675
- const res = await this.runCvTool('find-grid', { image: f }, ['find-grid', f]);
1713
+ const res = await this.domGrid(captchaElement, f);
1676
1714
  const dims = readPngDimensions(f);
1677
1715
  if (!Array.isArray(res) || (res.length !== 9 && res.length !== 16) || !dims)
1678
1716
  return null;
@@ -2924,30 +2962,116 @@ class CaptchaKrakenSolver {
2924
2962
  return first ? handleOf(first) : null;
2925
2963
  }
2926
2964
  /**
2927
- * The track of the first of the vendor's own slider handles that is visible with its centre outside the widget
2928
- * element's box. It is looked for in the widget, then in its parent and grandparent: Yidun's `.yidun_slider` is in
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
2929
2969
  * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
2930
2970
  * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
2931
2971
  * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
2932
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
+ }
2933
3052
  async trackOutside(scope, vendor, el, at) {
2934
- const own = this.sel.selectors[vendor]?.sliderHandle;
2935
- if (!own?.length)
3053
+ const mine = this.sel.selectors[vendor];
3054
+ const kinds = [[mine?.bar, true], [mine?.sliderHandle, false]].filter(([s]) => s?.length);
3055
+ if (!kinds.length)
2936
3056
  return null;
2937
3057
  // Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
2938
3058
  try {
2939
3059
  const a = await el.boundingBox();
2940
3060
  if (!a)
2941
3061
  return null;
2942
- for (const where of [scope, ...(at ? [1, 2].map((k) => at.locator(`xpath=ancestor::*[${k}]`)) : [])]) {
2943
- for (const found of await visible(where, own)) {
2944
- const b = await (await handleOf(found))?.boundingBox();
2945
- if (!b)
2946
- continue;
2947
- const cx = b.x + b.width / 2, cy = b.y + b.height / 2;
2948
- if (cx >= a.x && cx <= a.x + a.width && cy >= a.y && cy <= a.y + a.height)
2949
- continue;
2950
- return (await handleOf(found.locator('xpath=..'))) ?? handleOf(found);
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
+ }
2951
3075
  }
2952
3076
  }
2953
3077
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "captchakraken",
3
- "version": "4.2.0",
4
- "description": "Captcha solver for Playwright and Puppeteer. Finds the captcha, reads it with the v2 pointer model, and clicks, drags, slides or types through to a token \u2014 reCAPTCHA, GeeTest, NetEase Yidun, Tencent, Lemin, Prosopo, Turnstile and distorted text. Hosted API or self-hosted.",
3
+ "version": "5.0.0-beta.41",
4
+ "description": "Captcha solver for Playwright and Puppeteer. Finds the captcha, reads it with the v2 pointer model, and clicks, drags, slides or types through to a token — reCAPTCHA, GeeTest, NetEase Yidun, Tencent, Lemin, Prosopo, Turnstile and distorted text. Hosted API or self-hosted.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
package/python/AGENTS.md CHANGED
@@ -64,8 +64,8 @@ captchakraken path/to/captcha.png # prints a JSON click plan
64
64
 
65
65
  Other CLI modes, all printing JSON: `captchakraken server start|stop|status|run`
66
66
  manages a local vLLM server, `captchakraken fetch` updates weights and the
67
- serving stack together, and the detector tool calls (`find-grid`, `find-checkbox`,
68
- `get-numbered-grid`, `detect-selected`, …) are exposed one per subcommand. The
67
+ serving stack together, and the pixel tool calls (`find-checkbox`,
68
+ `grid-cell-states-fixed`) are exposed one per subcommand. The
69
69
  module docstring of `captchakraken/cli.py` lists every mode with its arguments.
70
70
 
71
71
  ## 4. Errors
@@ -92,8 +92,9 @@ succeed.
92
92
 
93
93
  ## 5. If you drive the model yourself
94
94
 
95
- Grid screenshots must be sent with **cell numbers drawn on them** — the client
96
- runs `find_grid`, renders the numbered overlay, and sends that image, because
95
+ Grid screenshots sent to a chat model must have **cell numbers drawn on them** —
96
+ the client reads the cell boxes from the reCAPTCHA challenge frame's tiles,
97
+ renders the numbered overlay, and sends that image, because
97
98
  the model reads those labels and was never trained to invent a numbering.
98
99
  Without the overlay reCAPTCHA 4×4 scores zero without erroring. Image area is
99
100
  also clamped into the `pixel_budget` the model declares in
package/python/README.md CHANGED
@@ -95,7 +95,7 @@ captchakraken server start | stop | status | run
95
95
  ## Usage
96
96
 
97
97
  ```bash
98
- # Solve an image/video: classify → find_grid → plan. Prints the click actions.
98
+ # Solve an image/video: classify → plan. Prints the click actions.
99
99
  captchakraken path/to/captcha.png
100
100
  captchakraken path/to/captcha.png --puzzle-source recaptcha
101
101
  ```
@@ -107,8 +107,8 @@ solver = CaptchaSolver() # connects to / auto-starts a local vLLM
107
107
  actions = solver.solve("captcha.png")
108
108
  ```
109
109
 
110
- Element-detector tool subcommands (CPU only, no planner model): `find-grid`, `find-checkbox`,
111
- `detect-selected`, `grid-cell-states`, and a persistent `serve` worker the browser driver polls.
110
+ Pixel tool subcommands (CPU only, no model): `find-checkbox`, `grid-cell-states-fixed`
111
+ (takes the grid boxes as JSON), and a persistent `serve` worker the browser driver polls.
112
112
 
113
113
  ## Configuration (model-agnostic)
114
114
 
@@ -123,9 +123,6 @@ Everything model-specific lives in `captchakraken.config` and is env-overridable
123
123
  | `CAPTCHA_LORA_ADAPTER` | Captcha adapter (HF id or path) | `CaptchaKraken/CaptchaKraken-Lora-v1.2` |
124
124
  | `CAPTCHA_LORA_NAME` | Served adapter name the client requests | `captcha-v12` |
125
125
  | `CAPTCHA_KRAKEN_AUTOSTART` | `0` disables local auto-start | `1` |
126
- | `CAPTCHA_KRAKEN_DETECTOR` | A local element-detector `.onnx` to run instead of downloading the released one | the released weights, fetched once |
127
- | `CAPTCHA_KRAKEN_DETECTOR_MODEL` | Which released detector runs: `lite` (MobileNetV3, about 100 ms a board on one vCPU), `standard` (ResNet-18), or `auto`; overrides `detector` in `captchakraken.config.json` | the config's `detector`, shipped as `auto`: `lite` on two usable CPUs or fewer (a container's CPU quota included), else one board is timed and `standard` runs when it fits in 200 ms |
128
- | `HF_TOKEN` | A Hugging Face token, sent only when downloading the detector weights from a private copy of their repo | unset: the download sends no credential |
129
126
  | `CAPTCHA_HUMANIZATION` | How gestures are performed: `mouse`, `mobile` or `none` | `mouse` |
130
127
 
131
128
  **How it moves** is a choice of input device, not a realism dial. `mobile`