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.
- package/README.md +0 -1
- package/dist/index.d.ts +1 -1
- package/dist/kinds.d.ts +2 -0
- package/dist/kinds.js +2 -0
- package/dist/playwright-types.d.ts +2 -0
- package/dist/selectors.d.ts +19 -10
- package/dist/selectors.js +7 -18
- package/dist/solver.d.ts +52 -2
- package/dist/solver.js +213 -21
- package/package.json +2 -2
- package/python/AGENTS.md +5 -4
- package/python/README.md +3 -6
- package/python/pyproject.toml +6 -9
- package/python/src/captchakraken/__init__.py +1 -1
- package/python/src/captchakraken/captchakraken.config.json +53 -8
- package/python/src/captchakraken/cli.py +2 -47
- package/python/src/captchakraken/config.py +0 -4
- package/python/src/captchakraken/kinds.py +2 -0
- package/python/src/captchakraken/models.json +15 -14
- package/python/src/captchakraken/page_solver.py +191 -24
- package/python/src/captchakraken/pointer/__init__.py +7 -9
- package/python/src/captchakraken/pointer/elements.py +1 -1
- package/python/src/captchakraken/pointer/server.py +13 -17
- package/python/src/captchakraken/pointer/service.py +35 -324
- package/python/src/captchakraken/prompts.py +3 -4
- package/python/src/captchakraken/selectors.py +15 -16
- package/python/src/captchakraken/selfhost.py +9 -16
- package/python/src/captchakraken/server_manager.py +0 -4
- package/python/src/captchakraken/solver.py +4 -25
- package/python/src/captchakraken/tool_calls/find_checkbox.py +150 -13
- package/python/src/captchakraken/tool_calls/find_grid.py +6 -132
- package/python/src/captchakraken/tool_calls/slide_tracker.py +10 -1
- package/python/src/captchakraken/updater.py +57 -27
- package/python/src/captchakraken/pointer/detector.py +0 -333
|
@@ -37,6 +37,8 @@ _SITE_ENV = "CAPTCHA_KRAKEN_SITE"
|
|
|
37
37
|
_WIDGET_HOST_ENV = "CAPTCHA_KRAKEN_WIDGET_HOST"
|
|
38
38
|
# How often a page that has not drawn its widget yet is looked at again.
|
|
39
39
|
_DETECTION_POLL_MS = 250
|
|
40
|
+
#: How long a widget frame is given to draw the board inside it (`board`) before the frame itself is shot.
|
|
41
|
+
_BOARD_INSIDE_WAIT_MS = 3_000
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
def _log(message: str) -> None:
|
|
@@ -198,6 +200,9 @@ class SolveResult:
|
|
|
198
200
|
#: A typed captcha's text box widens the shot only when it sits by the image: the union may be at most this many
|
|
199
201
|
#: times the image's area. A vendor-named box found in the enclosing form can be a whole login form away.
|
|
200
202
|
ANSWER_BOX_MAX_GROWTH = 4.0
|
|
203
|
+
#: A slider's handle widens the shot only when it sits just outside the picture: the union may be at most this many
|
|
204
|
+
#: times the picture's area. Yidun's bar is 40px under a 175px panel (x1.23).
|
|
205
|
+
SLIDER_TRACK_MAX_GROWTH = 2.0
|
|
201
206
|
|
|
202
207
|
|
|
203
208
|
class _WithAnswerBox:
|
|
@@ -208,10 +213,14 @@ class _WithAnswerBox:
|
|
|
208
213
|
strip the pointer read the image as a click puzzle (p(type) 0.46) or doubled a glyph, where the same frame
|
|
209
214
|
with its box read R9VK at p >= 0.89 per character. The answer's points are taken in this union's frame, so
|
|
210
215
|
`bounding_box` is the union everywhere the round reads it; everything else is the element's own.
|
|
216
|
+
|
|
217
|
+
The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
|
|
218
|
+
float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and
|
|
219
|
+
on the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
|
|
211
220
|
"""
|
|
212
221
|
|
|
213
|
-
def __init__(self, element: Any, box: Any):
|
|
214
|
-
self._element, self._box = element, box
|
|
222
|
+
def __init__(self, element: Any, box: Any, max_growth: float = ANSWER_BOX_MAX_GROWTH):
|
|
223
|
+
self._element, self._box, self._max_growth = element, box, max_growth
|
|
215
224
|
|
|
216
225
|
def bounding_box(self) -> Optional[Dict[str, float]]:
|
|
217
226
|
a = self._element.bounding_box()
|
|
@@ -221,7 +230,7 @@ class _WithAnswerBox:
|
|
|
221
230
|
x0, y0 = min(a["x"], b["x"]), min(a["y"], b["y"])
|
|
222
231
|
x1 = max(a["x"] + a["width"], b["x"] + b["width"])
|
|
223
232
|
y1 = max(a["y"] + a["height"], b["y"] + b["height"])
|
|
224
|
-
if (x1 - x0) * (y1 - y0) >
|
|
233
|
+
if (x1 - x0) * (y1 - y0) > self._max_growth * max(a["width"] * a["height"], 1.0):
|
|
225
234
|
return a
|
|
226
235
|
return {"x": x0, "y": y0, "width": x1 - x0, "height": y1 - y0}
|
|
227
236
|
|
|
@@ -454,9 +463,18 @@ def _has_text(handle: Any) -> bool:
|
|
|
454
463
|
# The nudge that shows the tracker what the handle moves: enough to separate the part from still ground, little enough
|
|
455
464
|
# that a piece resting against the board's edge stays on it.
|
|
456
465
|
SLIDE_PROBE_PX = 8.0
|
|
466
|
+
# A part that moves less than this while the handle travels more than half a probe has reached the end of its
|
|
467
|
+
# track: pushing on only carries the pointer away from the handle, and a vendor may cancel a drag that strays
|
|
468
|
+
# (DataDome snapped its handle home about 110 px past the stop). Shot pixels at device scale 1.
|
|
469
|
+
SLIDE_STALL_PX = 1.0
|
|
457
470
|
|
|
458
471
|
# No prompt and no pictures both read as ready: waiting for `.prompt-text` to exist once paid the whole timeout
|
|
459
472
|
# before every board of a challenge that draws none (tower_stack: 18s a round, 2/2 -> 0/2).
|
|
473
|
+
_TILE_RECTS_JS = """(sel) => Array.from(document.querySelectorAll(sel))
|
|
474
|
+
.map((e) => e.getBoundingClientRect())
|
|
475
|
+
.filter((r) => r.width > 0 && r.height > 0)
|
|
476
|
+
.map((r) => [r.left, r.top, r.right, r.bottom])"""
|
|
477
|
+
|
|
460
478
|
_BOARD_IMAGES_READY_JS = """({ prompt, images }) => {
|
|
461
479
|
const vis = (el) => !!el && el.getClientRects().length > 0
|
|
462
480
|
&& getComputedStyle(el).visibility !== 'hidden';
|
|
@@ -478,6 +496,18 @@ _RESOURCES_JS = """() => {
|
|
|
478
496
|
}"""
|
|
479
497
|
|
|
480
498
|
|
|
499
|
+
def _offset(s: Any) -> Tuple[float, float]:
|
|
500
|
+
"""A slide travel as (dx, dy): a number runs along the track, a pair is a carried piece's own offset."""
|
|
501
|
+
return (float(s[0]), float(s[1])) if isinstance(s, (list, tuple)) else (float(s), 0.0)
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
def _stalled(before: Tuple[Any, Sequence[float]], now: Tuple[Any, Sequence[float]], k: float) -> bool:
|
|
505
|
+
"""Did the handle travel while the part stayed put? Each side is (travel, the part's point) of one look."""
|
|
506
|
+
(ax, ay), (bx, by) = _offset(before[0]), _offset(now[0])
|
|
507
|
+
moved = math.hypot(now[1][0] - before[1][0], now[1][1] - before[1][1])
|
|
508
|
+
return math.hypot(bx - ax, by - ay) > SLIDE_PROBE_PX / 2 * k and moved < SLIDE_STALL_PX * k
|
|
509
|
+
|
|
510
|
+
|
|
481
511
|
class PageSolver:
|
|
482
512
|
"""Drives one Playwright-compatible `page` through a captcha. Reusable across solves."""
|
|
483
513
|
|
|
@@ -491,9 +521,6 @@ class PageSolver:
|
|
|
491
521
|
self._solver = solver or CaptchaSolver(**solver_kwargs)
|
|
492
522
|
self._human: Humanizer = resolve_humanizer(self.config)
|
|
493
523
|
self._sel = SelectorTable(self.config.custom_selectors, config=self.config.selectors)
|
|
494
|
-
# The config's `detector`: which element detector finds this solver's grids and tick boxes.
|
|
495
|
-
from .pointer import detector as _detector
|
|
496
|
-
_detector.configure(self._sel.config.detector)
|
|
497
524
|
self._last_submit_frame_hash: Optional[str] = None
|
|
498
525
|
self._deadline_ms: Optional[float] = None
|
|
499
526
|
self._budget: Optional[PhaseBudget] = None
|
|
@@ -765,14 +792,30 @@ class PageSolver:
|
|
|
765
792
|
|
|
766
793
|
# ── the shared half, in-process ──────────────────────────────────────
|
|
767
794
|
|
|
768
|
-
def
|
|
769
|
-
|
|
795
|
+
def _dom_grid(self, element: Any, image_path: str) -> Optional[List[Sequence[int]]]:
|
|
796
|
+
"""The board's tiles as (x0, y0, x1, y1) pixels of `image_path`, a screenshot of `element`, in reading order.
|
|
770
797
|
|
|
798
|
+
Read from the vendor's own markup, not the picture: a tile is where the challenge frame placed it. A tile's
|
|
799
|
+
rectangle is in the frame's CSS pixels, which start at the iframe's corner, so it scales straight onto the
|
|
800
|
+
screenshot. None when the vendor names no tiles or the frame shows none.
|
|
801
|
+
"""
|
|
802
|
+
sel = self._sel.selectors.get(Vendor.RECAPTCHA)
|
|
803
|
+
dims = _read_png_dimensions(image_path)
|
|
804
|
+
if sel is None or not sel.tiles or not dims:
|
|
805
|
+
return None
|
|
771
806
|
try:
|
|
772
|
-
|
|
807
|
+
frame = element.content_frame()
|
|
808
|
+
box = element.bounding_box()
|
|
809
|
+
if frame is None or not box or box["width"] <= 0 or box["height"] <= 0:
|
|
810
|
+
return None
|
|
811
|
+
rects = frame.evaluate(_TILE_RECTS_JS, ",".join(sel.tiles))
|
|
773
812
|
except Exception as exc:
|
|
774
|
-
_debug(f"
|
|
813
|
+
_debug(f"reading the grid's tiles failed: {exc}")
|
|
775
814
|
return None
|
|
815
|
+
sx, sy = dims[0] / box["width"], dims[1] / box["height"]
|
|
816
|
+
boxes = [(int(round(x0 * sx)), int(round(y0 * sy)), int(round(x1 * sx)), int(round(y1 * sy)))
|
|
817
|
+
for x0, y0, x1, y1 in rects or ()]
|
|
818
|
+
return boxes if len(boxes) >= 4 else None
|
|
776
819
|
|
|
777
820
|
def _has_movement(self, path_a: str, path_b: str, threshold: float) -> bool:
|
|
778
821
|
from .image_processor import ImageProcessor
|
|
@@ -1035,6 +1078,115 @@ class PageSolver:
|
|
|
1035
1078
|
first = next(iter(_visible(scope, selectors)), None)
|
|
1036
1079
|
return _handle_of(first) if first is not None else None
|
|
1037
1080
|
|
|
1081
|
+
def _framed(self, widget: Widget, frame: Any, scope: Any) -> Tuple[Any, Optional[Any]]:
|
|
1082
|
+
"""The element whose screenshot the model is shown for `widget`, and the text box when it is typed.
|
|
1083
|
+
|
|
1084
|
+
This is the whole of what the client PHOTOGRAPHS, kept in one place so the capture gate can check it without
|
|
1085
|
+
solving: the widget, else the board its frame pads (Proton), widened by a text box beside it (BotDetect) or
|
|
1086
|
+
by the vendor's bar or slider track outside it (Yidun).
|
|
1087
|
+
"""
|
|
1088
|
+
element, puzzle_source = widget.element, widget.vendor
|
|
1089
|
+
# A widget frame that pads its board (Proton) is photographed by the board inside it.
|
|
1090
|
+
board = self._board_inside(frame, puzzle_source)
|
|
1091
|
+
if board is not None:
|
|
1092
|
+
_log("the widget frame pads its board; photographing the board itself")
|
|
1093
|
+
element = board
|
|
1094
|
+
|
|
1095
|
+
# Only the DOM can tell a typed captcha from a click puzzle; hCaptcha and reCAPTCHA never type.
|
|
1096
|
+
answer_box = None if puzzle_source in VENDORS_WITH_BESPOKE_HANDLING else self._answer_box(scope, widget.at)
|
|
1097
|
+
if answer_box is not None:
|
|
1098
|
+
_log("widget has a text box; solving as a distorted-text captcha")
|
|
1099
|
+
element = _WithAnswerBox(element, answer_box)
|
|
1100
|
+
elif puzzle_source not in VENDORS_WITH_BESPOKE_HANDLING:
|
|
1101
|
+
track = self._track_outside(scope, puzzle_source, element, widget.at)
|
|
1102
|
+
if track is not None:
|
|
1103
|
+
_log("the vendor bar or slider track sits outside the widget; photographing the two as one")
|
|
1104
|
+
element = _WithAnswerBox(element, track, SLIDER_TRACK_MAX_GROWTH)
|
|
1105
|
+
return element, answer_box
|
|
1106
|
+
|
|
1107
|
+
def capture(self, page: Any) -> Optional[Tuple[Widget, Any]]:
|
|
1108
|
+
"""The widget on `page` and the element the solver would photograph for it, without solving anything.
|
|
1109
|
+
|
|
1110
|
+
For release gates: whether the client finds a vendor's widget, by its selectors and URL markers, and frames
|
|
1111
|
+
the whole board, is checkable on a live page at no inference cost. A checkbox widget is returned with its own
|
|
1112
|
+
element; it is clicked, not photographed.
|
|
1113
|
+
"""
|
|
1114
|
+
self._page = page
|
|
1115
|
+
widget = self.detect_captcha(page)
|
|
1116
|
+
if widget is None:
|
|
1117
|
+
return None
|
|
1118
|
+
if widget.role == FrameRole.CHECKBOX:
|
|
1119
|
+
return widget, widget.element
|
|
1120
|
+
frame = widget.element.content_frame()
|
|
1121
|
+
if widget.vendor != Vendor.RECAPTCHA:
|
|
1122
|
+
self._wait_for_board_painted(widget.element)
|
|
1123
|
+
element, _ = self._framed(widget, frame, frame or widget.at)
|
|
1124
|
+
return widget, element
|
|
1125
|
+
|
|
1126
|
+
def _board_inside(self, frame: Any, vendor: Any) -> Optional[Any]:
|
|
1127
|
+
"""The vendor's own `board`, found in the widget's frame or a frame nested in it, or None.
|
|
1128
|
+
|
|
1129
|
+
Proton's widget frame is 682x600 with its 370x534 `.protonCaptchaContainer` centred two frames down; the
|
|
1130
|
+
pointer trained on that container, and shown the padded frame it repeated one answer until the solve gave up
|
|
1131
|
+
(live 0/2 on 2026-11-13). The board is drawn a moment after the frame, so it is waited for briefly.
|
|
1132
|
+
"""
|
|
1133
|
+
own = getattr(self._sel.selectors.get(vendor), "board", None)
|
|
1134
|
+
if not own or frame is None:
|
|
1135
|
+
return None
|
|
1136
|
+
deadline = _now() + _BOARD_INSIDE_WAIT_MS
|
|
1137
|
+
while True:
|
|
1138
|
+
try:
|
|
1139
|
+
frames = [frame]
|
|
1140
|
+
while frames:
|
|
1141
|
+
where = frames.pop(0)
|
|
1142
|
+
for found in _visible(where, own):
|
|
1143
|
+
handle = _handle_of(found)
|
|
1144
|
+
if handle is not None and handle.bounding_box():
|
|
1145
|
+
return handle
|
|
1146
|
+
frames.extend(where.child_frames)
|
|
1147
|
+
except Exception:
|
|
1148
|
+
return None
|
|
1149
|
+
if _now() >= deadline:
|
|
1150
|
+
return None
|
|
1151
|
+
_delay(_DETECTION_POLL_MS)
|
|
1152
|
+
|
|
1153
|
+
def _track_outside(self, scope: Any, vendor: Any, element: Any, at: Any = None) -> Optional[Any]:
|
|
1154
|
+
"""The vendor's own `bar`, else the track of its first slider handle, visible with its centre outside the widget.
|
|
1155
|
+
|
|
1156
|
+
The bar is what Yidun's click modes need: `.yidun_control` holds the 请依次点击 prompt that names the marks and
|
|
1157
|
+
their order, and on the bare `.yidun_panel` the pointer was shown neither (live 0/6 on 2026-11-13). The
|
|
1158
|
+
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
|
|
1159
|
+
`.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed
|
|
1160
|
+
over, not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The
|
|
1161
|
+
track (the handle's parent) is returned rather than the handle, whose box moves as it slides and would
|
|
1162
|
+
resize the frame.
|
|
1163
|
+
"""
|
|
1164
|
+
mine = self._sel.selectors.get(vendor)
|
|
1165
|
+
kinds = [(sels, is_bar) for sels, is_bar in ((getattr(mine, "bar", None), True), (getattr(mine, "slider_handle", None), False)) if sels]
|
|
1166
|
+
if not kinds:
|
|
1167
|
+
return None
|
|
1168
|
+
# Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
|
|
1169
|
+
try:
|
|
1170
|
+
wheres = [scope, *((at.locator(f"xpath=ancestor::*[{k}]") for k in (1, 2)) if at is not None else ())]
|
|
1171
|
+
a = element.bounding_box()
|
|
1172
|
+
if not a:
|
|
1173
|
+
return None
|
|
1174
|
+
for own, is_bar in kinds:
|
|
1175
|
+
for where in wheres:
|
|
1176
|
+
for found in _visible(where, own):
|
|
1177
|
+
handle = _handle_of(found)
|
|
1178
|
+
b = handle.bounding_box() if handle is not None else None
|
|
1179
|
+
if not b:
|
|
1180
|
+
continue
|
|
1181
|
+
cx, cy = b["x"] + b["width"] / 2, b["y"] + b["height"] / 2
|
|
1182
|
+
if a["x"] <= cx <= a["x"] + a["width"] and a["y"] <= cy <= a["y"] + a["height"]:
|
|
1183
|
+
continue
|
|
1184
|
+
return handle if is_bar else (_handle_of(found.locator("xpath=..")) or handle)
|
|
1185
|
+
except Exception:
|
|
1186
|
+
return None
|
|
1187
|
+
return None
|
|
1188
|
+
return None
|
|
1189
|
+
|
|
1038
1190
|
def _answer_box(self, scope: Any, at: Any = None) -> Optional[Any]:
|
|
1039
1191
|
"""The text box inside the widget, else a vendor-named one in its enclosing fieldset/form.
|
|
1040
1192
|
|
|
@@ -1115,6 +1267,7 @@ class PageSolver:
|
|
|
1115
1267
|
handle=(handle[0] * k, handle[1] * k), bounds=(-handle[0] * k, (w - handle[0]) * k),
|
|
1116
1268
|
tol=self.config.slide_tolerance_px * k)
|
|
1117
1269
|
look, s, history, moves = probed, probe * k, [], 0
|
|
1270
|
+
last: Optional[Tuple[Any, Sequence[float]]] = None
|
|
1118
1271
|
while True:
|
|
1119
1272
|
try:
|
|
1120
1273
|
reply = slide_step(first, probed, look, s=s, history=history, **ask)
|
|
@@ -1123,6 +1276,12 @@ class PageSolver:
|
|
|
1123
1276
|
break
|
|
1124
1277
|
if look is not probed:
|
|
1125
1278
|
history.append(reply["observation"])
|
|
1279
|
+
if last is not None and _stalled(last, (s, reply["pos"]), k):
|
|
1280
|
+
_log("slider: the part stopped following the handle; releasing at the end of its track")
|
|
1281
|
+
dx, dy = _offset(last[0])
|
|
1282
|
+
self._smooth_move(page, press[0] + dx / k, press[1] + dy / k)
|
|
1283
|
+
break
|
|
1284
|
+
last = (s, reply["pos"])
|
|
1126
1285
|
_debug(f"slider: point at ({reply['pos'][0] / k:.1f}, {reply['pos'][1] / k:.1f}), "
|
|
1127
1286
|
f"{reply['error'] / k:.1f}px from its target, {reply['kind']}")
|
|
1128
1287
|
if reply["done"] or moves >= self.config.slide_max_corrections:
|
|
@@ -1130,7 +1289,7 @@ class PageSolver:
|
|
|
1130
1289
|
_log(f"slider: releasing {reply['error'] / k:.1f}px off target")
|
|
1131
1290
|
break
|
|
1132
1291
|
s = reply["next"]
|
|
1133
|
-
dx, dy = (s
|
|
1292
|
+
dx, dy = _offset(s)
|
|
1134
1293
|
self._smooth_move(page, press[0] + dx / k, press[1] + dy / k)
|
|
1135
1294
|
self._human.pause(PauseKind.PROBE)
|
|
1136
1295
|
self._screenshot(element, current, timeout_ms=timeout)
|
|
@@ -1367,7 +1526,7 @@ class PageSolver:
|
|
|
1367
1526
|
_delay(_DETECTION_POLL_MS)
|
|
1368
1527
|
|
|
1369
1528
|
def _checkbox_on_screen(self, element: Any) -> Optional[Tuple[float, float]]:
|
|
1370
|
-
"""One capture and
|
|
1529
|
+
"""One capture and plain pixel arithmetic, no model: a point inside the tick box, or None when none is drawn."""
|
|
1371
1530
|
from .tool_calls.find_checkbox import find_checkbox
|
|
1372
1531
|
|
|
1373
1532
|
box = element.bounding_box()
|
|
@@ -1399,8 +1558,19 @@ class PageSolver:
|
|
|
1399
1558
|
return
|
|
1400
1559
|
_delay(self.config.post_solve_outcome_poll_ms)
|
|
1401
1560
|
|
|
1402
|
-
def _get_verify_button(self, scope: Any) -> Optional[Any]:
|
|
1403
|
-
|
|
1561
|
+
def _get_verify_button(self, scope: Any, typed_at: Any = None) -> Optional[Any]:
|
|
1562
|
+
"""The widget's Verify, else, after a typed answer, the vendor-named submit beside its text box.
|
|
1563
|
+
|
|
1564
|
+
BotDetect's Validate sits in the widget's fieldset, outside the 280x50 `.BDC_CaptchaDiv`, like `#captchaCode`
|
|
1565
|
+
(see `_answer_box`). Without it the code was typed and never sent: live 0/9 on 2026-11-13. Only vendor-named
|
|
1566
|
+
selectors widen, so a login form's own Submit is never pressed.
|
|
1567
|
+
"""
|
|
1568
|
+
inside = self._find_control(scope, self._sel.submit)
|
|
1569
|
+
if inside is not None or typed_at is None:
|
|
1570
|
+
return inside
|
|
1571
|
+
around = (self._find_control(typed_at.locator(f"xpath={axis}"), self._sel.submit_vendor)
|
|
1572
|
+
for axis in ("ancestor::fieldset[1]", "ancestor::form[1]"))
|
|
1573
|
+
return next((found for found in around if found is not None), None)
|
|
1404
1574
|
|
|
1405
1575
|
# ── frames and polling ───────────────────────────────────────────────
|
|
1406
1576
|
|
|
@@ -1531,7 +1701,7 @@ class PageSolver:
|
|
|
1531
1701
|
def judge(frames, elapsed):
|
|
1532
1702
|
if len(frames) < 2:
|
|
1533
1703
|
return None
|
|
1534
|
-
boxes = self.
|
|
1704
|
+
boxes = self._dom_grid(element, frames[1])
|
|
1535
1705
|
if not boxes:
|
|
1536
1706
|
return False if elapsed >= cfg.grid_load_timeout_ms else None
|
|
1537
1707
|
states = self._grid_cell_states(frames[0], frames[1], boxes)
|
|
@@ -1582,7 +1752,7 @@ class PageSolver:
|
|
|
1582
1752
|
path = _tmp_png("findgrid")
|
|
1583
1753
|
try:
|
|
1584
1754
|
self._screenshot(element, path, timeout_ms=self.config.element_screenshot_timeout_ms)
|
|
1585
|
-
boxes = self.
|
|
1755
|
+
boxes = self._dom_grid(element, path)
|
|
1586
1756
|
dims = _read_png_dimensions(path)
|
|
1587
1757
|
if not boxes or len(boxes) not in (9, 16) or not dims:
|
|
1588
1758
|
return None
|
|
@@ -2197,12 +2367,8 @@ class PageSolver:
|
|
|
2197
2367
|
with self._phase(Phase.BOARD_PAINT):
|
|
2198
2368
|
self._wait_for_board_painted(element)
|
|
2199
2369
|
|
|
2200
|
-
|
|
2201
|
-
answer_box = None if puzzle_source in VENDORS_WITH_BESPOKE_HANDLING else self._answer_box(scope, widget.at)
|
|
2370
|
+
element, answer_box = self._framed(widget, frame, scope)
|
|
2202
2371
|
text_mode = answer_box is not None
|
|
2203
|
-
if text_mode:
|
|
2204
|
-
_log("widget has a text box; solving as a distorted-text captcha")
|
|
2205
|
-
element = _WithAnswerBox(element, answer_box)
|
|
2206
2372
|
|
|
2207
2373
|
# A reCAPTCHA board is read by its grid below, not filmed.
|
|
2208
2374
|
filmable = puzzle_source != Vendor.RECAPTCHA and not text_mode
|
|
@@ -2230,7 +2396,7 @@ class PageSolver:
|
|
|
2230
2396
|
|
|
2231
2397
|
shot = _tmp_png("captcha")
|
|
2232
2398
|
self._round_board = None
|
|
2233
|
-
performed = slid = answered = have_shot = False
|
|
2399
|
+
performed = slid = answered = typed = have_shot = False
|
|
2234
2400
|
all_usage: List[Dict[str, Any]] = []
|
|
2235
2401
|
keyframe_dir: Optional[str] = None
|
|
2236
2402
|
try:
|
|
@@ -2331,7 +2497,7 @@ class PageSolver:
|
|
|
2331
2497
|
performed = answered = True
|
|
2332
2498
|
elif kind == ActionKind.TYPE:
|
|
2333
2499
|
if self._execute_type(page, scope, action, widget.at):
|
|
2334
|
-
performed = answered = True
|
|
2500
|
+
performed = answered = typed = True
|
|
2335
2501
|
elif kind == ActionKind.HOLD:
|
|
2336
2502
|
# The widget submits itself when the hold completes, like a slide on release.
|
|
2337
2503
|
self._execute_hold(page, action, element_box, element, self._sel.selectors[widget.vendor].hold_completes)
|
|
@@ -2351,7 +2517,8 @@ class PageSolver:
|
|
|
2351
2517
|
# `done` plan still presses Verify/Skip. FunCaptcha's answer is the click itself: an arrow pages and
|
|
2352
2518
|
# Submit submits. The generic Verify fallback would submit the page an arrow just turned to.
|
|
2353
2519
|
submits = self._submitted_on_board if slid else answered or not performed
|
|
2354
|
-
verify_button = self._get_verify_button(scope
|
|
2520
|
+
verify_button = (self._get_verify_button(scope, widget.at if typed else None)
|
|
2521
|
+
if submits and puzzle_source != Vendor.FUNCAPTCHA else None)
|
|
2355
2522
|
if verify_button:
|
|
2356
2523
|
_log(f"clicking Verify to submit ({puzzle_source}).")
|
|
2357
2524
|
self._move_and_click(page, verify_button)
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"""The pointer solver: a captcha answered from ONE forward pass, never generated.
|
|
2
2
|
|
|
3
|
-
The board is shown to a Qwen3.5 model (still, or a video)
|
|
4
|
-
|
|
5
|
-
in the prompt. Every question the answer needs (which action, how many clicks,
|
|
3
|
+
The board is shown to a Qwen3.5 model (still, or a video) as it was captured.
|
|
4
|
+
Every question the answer needs (which action, how many clicks,
|
|
6
5
|
where each one lands, what to type, which moment of a video) has a marker
|
|
7
6
|
token in the prompt, and small heads read each marker's hidden state from the
|
|
8
|
-
prefill. The answer always carries points
|
|
9
|
-
when the point lands on a numbered element.
|
|
7
|
+
prefill. The answer always carries points.
|
|
10
8
|
|
|
11
9
|
layout the prompt, the questions and the packed decision vector
|
|
12
|
-
elements
|
|
13
|
-
|
|
10
|
+
elements numbered elements, and the element under a point (training reads
|
|
11
|
+
them; the client sends every board bare)
|
|
12
|
+
marks the outlines and numbers a marked training board is drawn with
|
|
14
13
|
heads the torch heads (training and serving share them)
|
|
15
|
-
detector the element detector (Mask R-CNN, ResNet-18 FPN)
|
|
16
14
|
vllm_plugin the heads inside vLLM's pooling runner
|
|
17
|
-
service board in, answer out:
|
|
15
|
+
service board in, answer out: vLLM, decode
|
|
18
16
|
|
|
19
17
|
Only `layout`, `elements` and `marks` import without torch.
|
|
20
18
|
"""
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
An element is {"class", "box": [x0, y0, x1, y1], "score", "mask": ((x, y), bool
|
|
4
4
|
array)} in board pixels; the mask is cropped to its own extent and placed at
|
|
5
|
-
(x, y), as
|
|
5
|
+
(x, y), as an element detector returns it. Numbers are 1-based in reading
|
|
6
6
|
order (rows of ~12 px, then left to right), so a grid's cells number row-major.
|
|
7
7
|
|
|
8
8
|
`element_at` is the inverse question training asks: which numbered element does
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"""The /pointer HTTP endpoint: one board per request, generation 3's answer back.
|
|
2
2
|
|
|
3
|
-
python -m captchakraken.pointer.server --model /models/pointer-0.8b
|
|
4
|
-
--detector /models/detector_r18.pt --port 8001
|
|
3
|
+
python -m captchakraken.pointer.server --model /models/pointer-0.8b --port 8001
|
|
5
4
|
|
|
6
5
|
POST /v1/pointer
|
|
7
6
|
{"image": "<base64 PNG/JPEG>"} a still, as captured
|
|
8
7
|
{"frames": ["<base64 JPEG>", ...], "fps": 5.0} a video, `clipvideo`-cut
|
|
9
|
-
{"marked": false} optional: skip the detector
|
|
10
8
|
{"avoid": [answer, ...]} optional: answers already refused on this
|
|
11
9
|
board; the likeliest other ones come back
|
|
12
10
|
-> {"actions": [{...}, {...}, {...}], the three likeliest distinct answers, best first
|
|
13
11
|
"answer": {...}, the first action, kept for older callers
|
|
14
|
-
"elements": [
|
|
12
|
+
"elements": [], "size": [W, H]}
|
|
15
13
|
|
|
16
|
-
`
|
|
17
|
-
|
|
14
|
+
`size` is the board in pixels as the model saw it. `elements` is always empty and
|
|
15
|
+
`marked` in a request is ignored: both are left from the element detector, which
|
|
16
|
+
the client no longer has, so older callers keep working. The client sends no
|
|
17
|
+
prompt: the server owns it.
|
|
18
18
|
"""
|
|
19
19
|
from __future__ import annotations
|
|
20
20
|
|
|
@@ -45,7 +45,6 @@ def parse(body: Dict) -> Dict:
|
|
|
45
45
|
"""A request body -> PointerService.solve's arguments. Raises ValueError on a bad one."""
|
|
46
46
|
if ("image" in body) == ("frames" in body):
|
|
47
47
|
raise ValueError("send exactly one of image or frames")
|
|
48
|
-
marked = bool(body.get("marked", True))
|
|
49
48
|
avoid = body.get("avoid") or []
|
|
50
49
|
if not isinstance(avoid, list) or not all(isinstance(a, dict) for a in avoid):
|
|
51
50
|
raise ValueError("avoid is a list of earlier answers")
|
|
@@ -55,7 +54,7 @@ def parse(body: Dict) -> Dict:
|
|
|
55
54
|
if "image" in body:
|
|
56
55
|
if len(history) > L.MAX_HISTORY:
|
|
57
56
|
raise ValueError(f"{len(history)} earlier screens; at most {L.MAX_HISTORY}")
|
|
58
|
-
return {"image": _image(body["image"]), "
|
|
57
|
+
return {"image": _image(body["image"]), "avoid": avoid,
|
|
59
58
|
"history": [_image(h) for h in history]}
|
|
60
59
|
if history:
|
|
61
60
|
raise ValueError("a video board carries no earlier screens")
|
|
@@ -65,14 +64,12 @@ def parse(body: Dict) -> Dict:
|
|
|
65
64
|
frames = [np.asarray(Image.open(io.BytesIO(base64.b64decode(f))).convert("RGB")) for f in body["frames"]]
|
|
66
65
|
if len(frames) < 2:
|
|
67
66
|
raise ValueError("a video needs at least two frames")
|
|
68
|
-
return {"frames": frames, "
|
|
67
|
+
return {"frames": frames, "avoid": avoid}
|
|
69
68
|
|
|
70
69
|
|
|
71
70
|
def reply(result: Dict) -> Dict:
|
|
72
71
|
return {"actions": result.get("answers") or [result["answer"]],
|
|
73
|
-
"answer": result["answer"], "size": list(result["size"]),
|
|
74
|
-
"elements": [{"id": n, "class": e["class"], "box": [round(v, 1) for v in e["box"]],
|
|
75
|
-
"score": e["score"]} for n, e in enumerate(result["elements"], 1)]}
|
|
72
|
+
"answer": result["answer"], "size": list(result["size"]), "elements": []}
|
|
76
73
|
|
|
77
74
|
|
|
78
75
|
def make_handler(service):
|
|
@@ -129,9 +126,9 @@ def make_handler(service):
|
|
|
129
126
|
def main():
|
|
130
127
|
ap = argparse.ArgumentParser()
|
|
131
128
|
ap.add_argument("--model", required=True, help="an exported pointer checkpoint")
|
|
132
|
-
|
|
133
|
-
ap.add_argument("--
|
|
134
|
-
|
|
129
|
+
# Left from the element and letter detectors; a unit file that still passes them starts the same server.
|
|
130
|
+
ap.add_argument("--detector", default=None, help=argparse.SUPPRESS)
|
|
131
|
+
ap.add_argument("--letters", default=None, help=argparse.SUPPRESS)
|
|
135
132
|
ap.add_argument("--host", default="127.0.0.1")
|
|
136
133
|
ap.add_argument("--port", type=int, default=8001)
|
|
137
134
|
ap.add_argument("--gpu-memory-utilization", type=float, default=0.45)
|
|
@@ -140,8 +137,7 @@ def main():
|
|
|
140
137
|
a = ap.parse_args()
|
|
141
138
|
from .service import PointerService
|
|
142
139
|
capture = a.max_cudagraph_capture_size
|
|
143
|
-
svc = PointerService(a.model,
|
|
144
|
-
gpu_memory_utilization=a.gpu_memory_utilization,
|
|
140
|
+
svc = PointerService(a.model, gpu_memory_utilization=a.gpu_memory_utilization,
|
|
145
141
|
**({"compilation_config": {"max_cudagraph_capture_size": capture}} if capture else {}))
|
|
146
142
|
ThreadingHTTPServer((a.host, a.port), make_handler(svc)).serve_forever()
|
|
147
143
|
|