captchakraken 5.0.0-beta.47 → 5.0.0-beta.48

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.
@@ -16,6 +16,8 @@ export interface PlaywrightElementHandle {
16
16
  style?: string;
17
17
  }): Promise<Buffer>;
18
18
  contentFrame(): Promise<PlaywrightFrame | null>;
19
+ /** The frame the element lives in. Optional: an adapter without it never moves the solve into a nested board frame. */
20
+ ownerFrame?(): Promise<PlaywrightFrame | null>;
19
21
  boundingBox(): Promise<BoundingBoxRect | null>;
20
22
  scrollIntoViewIfNeeded(options?: {
21
23
  timeout?: number;
package/dist/solver.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Browser page driver. Finds the widget, photographs it, asks the bundled Python engine what to do,
3
3
  * and performs the answer. Mirrors python/src/captchakraken/page_solver.py.
4
4
  */
5
- import { PlaywrightPage as Page, PlaywrightElementHandle as ElementHandle, PlaywrightLocator as Locator } from './playwright-types';
5
+ import { PlaywrightPage as Page, PlaywrightElementHandle as ElementHandle, PlaywrightFrame as Frame, PlaywrightLocator as Locator } from './playwright-types';
6
6
  import { CaptchaWatcher, WatchOptions } from './watcher';
7
7
  import { PhaseBudget } from './timing';
8
8
  import { CaptchaKrakenConfig, SolveResult } from './types';
@@ -26,6 +26,12 @@ export interface Widget {
26
26
  * `boundingBox` is the union everywhere the round reads it; everything else is the element's own.
27
27
  */
28
28
  export declare function withAnswerBox(el: ElementHandle, box: ElementHandle, maxGrowth?: number): ElementHandle;
29
+ /**
30
+ * The frame that holds the photographed board, when it is not the widget's own frame, else null. Proton draws its
31
+ * board, its Next and its pieces a frame below the padded widget frame. Its Verify was looked for in the widget frame,
32
+ * never found, and the dragged answer was never submitted (fixture 0/4 on 2026-11-14).
33
+ */
34
+ export declare const boardFrame: (element: ElementHandle, frame: Frame | null) => Promise<Frame | null>;
29
35
  /** One read of a `band` strip: how far its picture sits right of where it started (background offset plus box), its rows, and the width its picture repeats at. */
30
36
  export interface BandRead {
31
37
  x: number;
@@ -430,6 +436,15 @@ export declare class CaptchaKrakenSolver {
430
436
  /** Deal a new puzzle: the vendor's own control, else the model's point on one. False when there is neither. */
431
437
  private executeRefresh;
432
438
  private executeDrag;
439
+ /**
440
+ * The answer's handle point, unless it sits inside its target box and on no named handle while its source sits on
441
+ * one. A slide-to-end slider (DataDome) moves its handle and nothing else, so the handle is also the source. A model
442
+ * never shown DataDome answered with the handle on the target and the source on the handle: the press grabbed empty
443
+ * track and nothing moved (fixture 0/4 on 2026-11-14, client 2383fbf). The page names the handle that moves, so a
444
+ * press goes there when the model's own point is its target. A handle away from the target is left alone: Yidun
445
+ * names its jigsaw piece as a handle too, and pressing the piece is not a slide.
446
+ */
447
+ private pressPoint;
433
448
  private findControl;
434
449
  /**
435
450
  * The vendor's own `bar`, else the track of its first slider handle, visible with its centre outside the widget
package/dist/solver.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.CaptchaKrakenSolver = exports.SOLVE_DEFAULTS = exports.HOLD_MAX_MS = exports.HOLD_SETTLE_MS = exports.GRID_LOAD_CAP_FACTOR = exports.IDLE_DRIFT_PX = exports.IDLE_DRIFT_EVERY_MS = exports.INPUT_SETTLE_MS = void 0;
36
+ exports.CaptchaKrakenSolver = exports.SOLVE_DEFAULTS = exports.HOLD_MAX_MS = exports.HOLD_SETTLE_MS = exports.GRID_LOAD_CAP_FACTOR = exports.IDLE_DRIFT_PX = exports.IDLE_DRIFT_EVERY_MS = exports.INPUT_SETTLE_MS = exports.boardFrame = void 0;
37
37
  exports.withAnswerBox = withAnswerBox;
38
38
  exports.bandRoll = bandRoll;
39
39
  exports.answerNeedsElementBox = answerNeedsElementBox;
@@ -176,6 +176,28 @@ const visible = async (scope, selectors) => (await Promise.all(selectors.map((s)
176
176
  const handleOf = (at) => at.elementHandle({ timeout: HANDLE_TIMEOUT_MS }).catch(() => null);
177
177
  const handles = async (ats) => (await Promise.all(ats.map(handleOf))).filter((h) => h !== null);
178
178
  const frameOf = async (at) => (await (await handleOf(at))?.contentFrame().catch(() => null)) ?? null;
179
+ /**
180
+ * The frame that holds the photographed board, when it is not the widget's own frame, else null. Proton draws its
181
+ * board, its Next and its pieces a frame below the padded widget frame. Its Verify was looked for in the widget frame,
182
+ * never found, and the dragged answer was never submitted (fixture 0/4 on 2026-11-14).
183
+ */
184
+ const boardFrame = async (element, frame) => {
185
+ if (!frame)
186
+ return null;
187
+ const owner = (await element.ownerFrame?.().catch(() => null)) ?? null;
188
+ if (!owner || owner === frame)
189
+ return null;
190
+ // Only a frame INSIDE the widget's: the widget's own iframe element lives in the host page, which is no board.
191
+ const below = [...(frame.childFrames?.() ?? [])];
192
+ while (below.length) {
193
+ const f = below.shift();
194
+ if (f === owner)
195
+ return owner;
196
+ below.push(...(f.childFrames?.() ?? []));
197
+ }
198
+ return null;
199
+ };
200
+ exports.boardFrame = boardFrame;
179
201
  /**
180
202
  * Where the host-page selectors are read: the page, then the inside of every VISIBLE vendor enclave. A hidden enclave is
181
203
  * skipped because Playwright judges an element visible within its own document, whatever its frame's visibility.
@@ -832,7 +854,7 @@ class CaptchaKrakenSolver {
832
854
  this.solveVendor = puzzleSource;
833
855
  const frame = await captchaElement.contentFrame();
834
856
  this.solveWidgetHost = frame ? hostname(frame) : null;
835
- const scope = frame ?? widget.at;
857
+ let scope = frame ?? widget.at;
836
858
  if (frameRole === kinds_1.FrameRole.CHECKBOX) {
837
859
  await this.clickCheckbox(page, widget, frame);
838
860
  return { didInteract: true, tokenUsage: [] };
@@ -855,6 +877,7 @@ class CaptchaKrakenSolver {
855
877
  : await this.ph(kinds_1.Phase.BOARD_PAINT, () => this.waitForBoardPainted(captchaElement));
856
878
  const framed = await this.framed(widget, frame, scope);
857
879
  captchaElement = framed.element;
880
+ scope = (await (0, exports.boardFrame)(captchaElement, frame)) ?? scope;
858
881
  const textMode = framed.answerBox !== null;
859
882
  // A reCAPTCHA board is read by its grid below, not filmed.
860
883
  const filmable = puzzleSource !== kinds_1.Vendor.RECAPTCHA && !textMode;
@@ -2995,6 +3018,34 @@ class CaptchaKrakenSolver {
2995
3018
  const center = (bbox) => [elementBox.x + ((bbox[0] + bbox[2]) / 2) * elementBox.width, elementBox.y + ((bbox[1] + bbox[3]) / 2) * elementBox.height];
2996
3019
  await this.gesture(() => this.human.drag(page, center(action.source_bounding_box), center(action.target_bounding_box)));
2997
3020
  }
3021
+ /**
3022
+ * The answer's handle point, unless it sits inside its target box and on no named handle while its source sits on
3023
+ * one. A slide-to-end slider (DataDome) moves its handle and nothing else, so the handle is also the source. A model
3024
+ * never shown DataDome answered with the handle on the target and the source on the handle: the press grabbed empty
3025
+ * track and nothing moved (fixture 0/4 on 2026-11-14, client 2383fbf). The page names the handle that moves, so a
3026
+ * press goes there when the model's own point is its target. A handle away from the target is left alone: Yidun
3027
+ * names its jigsaw piece as a handle too, and pressing the piece is not a slide.
3028
+ */
3029
+ async pressPoint(scope, elementBox, handle, seed, target) {
3030
+ if (!(target[0] <= handle[0] && handle[0] <= target[2] && target[1] <= handle[1] && handle[1] <= target[3]))
3031
+ return handle;
3032
+ let boxes;
3033
+ try {
3034
+ const named = await handles(await visible(scope, this.sel.sliderHandle));
3035
+ boxes = (await Promise.all(named.map((el) => el.boundingBox().catch(() => null)))).filter((b) => !!b);
3036
+ }
3037
+ catch {
3038
+ return handle;
3039
+ }
3040
+ const on = (p) => {
3041
+ const [x, y] = [elementBox.x + p[0], elementBox.y + p[1]];
3042
+ return boxes.some((b) => b.x <= x && x <= b.x + b.width && b.y <= y && y <= b.y + b.height);
3043
+ };
3044
+ if (on(handle) || !on(seed))
3045
+ return handle;
3046
+ console.log("Slider: the answer's handle is its target, and its source is on the handle the page names; pressing that.");
3047
+ return seed;
3048
+ }
2998
3049
  async findControl(scope, selectors) {
2999
3050
  const [first] = await visible(scope, selectors);
3000
3051
  return first ? handleOf(first) : null;
@@ -3227,6 +3278,8 @@ class CaptchaKrakenSolver {
3227
3278
  if (action.action === kinds_1.ActionKind.SLIDE) {
3228
3279
  handle = at(action.handle_bounding_box);
3229
3280
  seed = at(action.source_bounding_box);
3281
+ const t = action.target_bounding_box;
3282
+ handle = await this.pressPoint(scope, elementBox, handle, seed, [t[0] * w, t[1] * h, t[2] * w, t[3] * h]);
3230
3283
  }
3231
3284
  else {
3232
3285
  const slider = await this.findControl(scope, this.sel.sliderHandle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "captchakraken",
3
- "version": "5.0.0-beta.47",
3
+ "version": "5.0.0-beta.48",
4
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",
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "captchakraken"
7
- version = "5.0.0b47"
7
+ version = "5.0.0b48"
8
8
  description = "Captcha-solving engine and CLI: a v2 pointer model for image grids, click and drag puzzles, sliders, distorted text and animated challenges. Hosted API or self-hosted on vLLM."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -100,4 +100,4 @@ __all__ = [
100
100
  "PauseKind",
101
101
  ]
102
102
 
103
- __version__ = "5.0.0b47"
103
+ __version__ = "5.0.0b48"
@@ -431,6 +431,26 @@ def _visible(scope: Any, selectors: Sequence[str]) -> List[Any]:
431
431
  return found
432
432
 
433
433
 
434
+ def _board_frame(element: Any, frame: Any) -> Optional[Any]:
435
+ """The frame that holds the photographed board, when it is not the widget's own frame, else None.
436
+
437
+ Proton draws its board, its Next and its pieces a frame below the padded widget frame. Its Verify was looked for
438
+ in the widget frame, never found, and the dragged answer was never submitted (fixture 0/4 on 2026-11-14).
439
+ """
440
+ owner = getattr(element, "owner_frame", None)
441
+ if frame is None or owner is None:
442
+ return None
443
+ try:
444
+ board = owner()
445
+ # Only a frame INSIDE the widget's: the widget's own iframe element lives in the host page, which is no board.
446
+ up = board.parent_frame if board is not None and board != frame else None
447
+ while up is not None and up != frame:
448
+ up = up.parent_frame
449
+ except Exception:
450
+ return None
451
+ return board if up is not None else None
452
+
453
+
434
454
  def _handle_of(at: Any) -> Optional[Any]:
435
455
  try:
436
456
  return at.element_handle(timeout=HANDLE_TIMEOUT_MS)
@@ -1134,6 +1154,33 @@ class PageSolver:
1134
1154
  with self._gesture():
1135
1155
  self._human.drag(page, center(action["source_bounding_box"]), center(action["target_bounding_box"]))
1136
1156
 
1157
+ def _press_point(self, scope: Any, element_box: Dict[str, float], handle: Tuple[float, float],
1158
+ seed: Tuple[float, float], target: Tuple[float, float, float, float]) -> Tuple[float, float]:
1159
+ """The answer's handle point, unless it sits on the target and on no named handle while its source sits on one.
1160
+
1161
+ A slide-to-end slider (DataDome) moves its handle and nothing else, so the handle is also the source. A model
1162
+ never shown DataDome answered with the handle on the target and the source on the handle: the press grabbed
1163
+ empty track and nothing moved (fixture 0/4 on 2026-11-14, client 2383fbf). The page names the handle that
1164
+ moves, so a press goes there when the model's own point is inside its target box. A handle away from the target is left
1165
+ alone: Yidun names its jigsaw piece as a handle too, and pressing the piece is not a slide.
1166
+ """
1167
+ if not (target[0] <= handle[0] <= target[2] and target[1] <= handle[1] <= target[3]):
1168
+ return handle
1169
+ try:
1170
+ boxes = [b for b in (h.bounding_box() for h in (_handle_of(f) for f in _visible(scope, self._sel.slider_handle))
1171
+ if h is not None) if b]
1172
+ except Exception:
1173
+ return handle
1174
+
1175
+ def on(p: Tuple[float, float]) -> bool:
1176
+ x, y = element_box["x"] + p[0], element_box["y"] + p[1]
1177
+ return any(b["x"] <= x <= b["x"] + b["width"] and b["y"] <= y <= b["y"] + b["height"] for b in boxes)
1178
+
1179
+ if on(handle) or not on(seed):
1180
+ return handle
1181
+ _log("slider: the answer's handle is its target, and its source is on the handle the page names; pressing that")
1182
+ return seed
1183
+
1137
1184
  def _find_control(self, scope: Any, selectors: Sequence[str]) -> Optional[Any]:
1138
1185
  first = next(iter(_visible(scope, selectors)), None)
1139
1186
  return _handle_of(first) if first is not None else None
@@ -1357,6 +1404,9 @@ class PageSolver:
1357
1404
  goal = at(action["target_bounding_box"])
1358
1405
  if action.get("handle_bounding_box"):
1359
1406
  handle, seed = at(action["handle_bounding_box"]), at(action["source_bounding_box"])
1407
+ t = action["target_bounding_box"]
1408
+ handle = self._press_point(scope, element_box, handle, seed,
1409
+ (float(t[0]) * w, float(t[1]) * h, float(t[2]) * w, float(t[3]) * h))
1360
1410
  else:
1361
1411
  slider = self._find_control(scope, self._sel.slider_handle)
1362
1412
  piece = None if slider is not None else self._find_control(scope, self._sel.piece)
@@ -2497,6 +2547,7 @@ class PageSolver:
2497
2547
  self._wait_for_board_painted(element)
2498
2548
 
2499
2549
  element, answer_box = self._framed(widget, frame, scope)
2550
+ scope = _board_frame(element, frame) or scope
2500
2551
  text_mode = answer_box is not None
2501
2552
 
2502
2553
  # A reCAPTCHA board is read by its grid below, not filmed.