captchakraken 4.2.0 → 5.0.0-beta.42
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 +1 -0
- package/dist/kinds.js +1 -0
- package/dist/playwright-types.d.ts +4 -0
- package/dist/puppeteer-adapter.d.ts +2 -0
- package/dist/puppeteer-adapter.js +34 -2
- package/dist/selectors.d.ts +22 -11
- package/dist/selectors.js +9 -19
- package/dist/solver.d.ts +49 -4
- package/dist/solver.js +177 -47
- 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 +43 -9
- package/python/src/captchakraken/cli.py +2 -47
- package/python/src/captchakraken/config.py +0 -4
- package/python/src/captchakraken/kinds.py +1 -0
- package/python/src/captchakraken/models.json +15 -14
- package/python/src/captchakraken/page_solver.py +168 -49
- 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 +19 -17
- 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/updater.py +57 -27
- package/python/src/captchakraken/pointer/detector.py +0 -333
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""The `captchakraken` CLI: one-shot solves, the
|
|
1
|
+
"""The `captchakraken` CLI: one-shot solves, the pixel tool calls, the CV worker, and server management.
|
|
2
2
|
|
|
3
3
|
`captchakraken image.png [model] [api_provider] [api_key] [--puzzle-source ...]` solves one still.
|
|
4
4
|
Exit codes: 1 failure, 2 unsupported puzzle, 3 the hosted API refused.
|
|
@@ -106,13 +106,6 @@ def fill_step(req: dict) -> dict:
|
|
|
106
106
|
return {"error": str(e)}
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
def _find_grid(args):
|
|
110
|
-
from .tool_calls.find_grid import find_grid
|
|
111
|
-
|
|
112
|
-
_need(args, 1, "find-grid image.png")
|
|
113
|
-
return find_grid(_image(args[0]))
|
|
114
|
-
|
|
115
|
-
|
|
116
109
|
def _find_checkbox(args):
|
|
117
110
|
from .tool_calls.find_checkbox import find_checkbox
|
|
118
111
|
|
|
@@ -120,25 +113,6 @@ def _find_checkbox(args):
|
|
|
120
113
|
return find_checkbox(_image(args[0]))
|
|
121
114
|
|
|
122
115
|
|
|
123
|
-
def _detect_selected(args):
|
|
124
|
-
from .tool_calls.find_grid import detect_selected_cells, find_grid
|
|
125
|
-
|
|
126
|
-
_need(args, 1, "detect-selected image.png")
|
|
127
|
-
boxes = find_grid(_image(args[0]))
|
|
128
|
-
if not boxes:
|
|
129
|
-
return {"error": "No grid detected"}
|
|
130
|
-
selected, loading = detect_selected_cells(args[0], boxes)
|
|
131
|
-
return {"selected": selected, "loading": loading}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def _get_numbered_grid(args):
|
|
135
|
-
from .tool_calls.find_grid import find_grid, get_numbered_grid_overlay
|
|
136
|
-
|
|
137
|
-
_need(args, 1, "get-numbered-grid image.png")
|
|
138
|
-
boxes = find_grid(_image(args[0]))
|
|
139
|
-
return {"overlay_image": get_numbered_grid_overlay(args[0], boxes)} if boxes else {"error": "No grid detected"}
|
|
140
|
-
|
|
141
|
-
|
|
142
116
|
def _check_movement(args):
|
|
143
117
|
from .image_processor import ImageProcessor
|
|
144
118
|
|
|
@@ -152,17 +126,8 @@ def _check_movement(args):
|
|
|
152
126
|
return {"has_movement": ImageProcessor.detect_movement(args[0], args[1], threshold)}
|
|
153
127
|
|
|
154
128
|
|
|
155
|
-
def _grid_cell_states(args):
|
|
156
|
-
from .tool_calls.find_grid import find_grid
|
|
157
|
-
|
|
158
|
-
_need(args, 2, "grid-cell-states imgA.png imgB.png")
|
|
159
|
-
a, b = _image(args[0]), _image(args[1])
|
|
160
|
-
boxes = find_grid(b)
|
|
161
|
-
return grid_cell_states(a, b, boxes) if boxes else {"grid": None}
|
|
162
|
-
|
|
163
|
-
|
|
164
129
|
def _grid_cell_states_fixed(args):
|
|
165
|
-
"""Boxes supplied by the caller:
|
|
130
|
+
"""Boxes supplied by the caller, read from the vendor's DOM: the pixels alone do not say where the tiles are."""
|
|
166
131
|
_need(args, 3, "grid-cell-states-fixed imgA.png imgB.png '<json grid_boxes>'")
|
|
167
132
|
a, b = _image(args[0]), _image(args[1])
|
|
168
133
|
try:
|
|
@@ -216,15 +181,9 @@ def _serve(args):
|
|
|
216
181
|
"""Persistent CV worker: one JSON request per stdin line, one JSON reply per stdout line."""
|
|
217
182
|
from .image_processor import ImageProcessor
|
|
218
183
|
from .tool_calls.find_checkbox import find_checkbox
|
|
219
|
-
from .tool_calls.find_grid import find_grid
|
|
220
184
|
|
|
221
185
|
def handle(req):
|
|
222
186
|
cmd = req.get("cmd")
|
|
223
|
-
if cmd == "find-grid":
|
|
224
|
-
return find_grid(req["image"])
|
|
225
|
-
if cmd == "grid-cell-states":
|
|
226
|
-
boxes = find_grid(req["b"])
|
|
227
|
-
return grid_cell_states(req["a"], req["b"], boxes) if boxes else {"grid": None}
|
|
228
187
|
if cmd == "grid-cell-states-fixed":
|
|
229
188
|
boxes = [tuple(int(v) for v in box) for box in req["grid_boxes"]]
|
|
230
189
|
if not boxes:
|
|
@@ -423,12 +382,8 @@ def _fetch(args):
|
|
|
423
382
|
|
|
424
383
|
|
|
425
384
|
COMMANDS: Dict[str, Callable[[List[str]], Any]] = {
|
|
426
|
-
"find-grid": _find_grid,
|
|
427
385
|
"find-checkbox": _find_checkbox,
|
|
428
|
-
"detect-selected": _detect_selected,
|
|
429
|
-
"get-numbered-grid": _get_numbered_grid,
|
|
430
386
|
"check-movement": _check_movement,
|
|
431
|
-
"grid-cell-states": _grid_cell_states,
|
|
432
387
|
"grid-cell-states-fixed": _grid_cell_states_fixed,
|
|
433
388
|
"match-region": _match_region,
|
|
434
389
|
"board-painted": _board_painted,
|
|
@@ -246,10 +246,6 @@ def serve_model() -> str:
|
|
|
246
246
|
return os.getenv("CAPTCHA_BASE_MODEL") or selfhost_active().get("model_path") or base_model()
|
|
247
247
|
|
|
248
248
|
|
|
249
|
-
def pointer_detector() -> Optional[str]:
|
|
250
|
-
return os.getenv("CAPTCHA_POINTER_DETECTOR") or selfhost_active().get("detector")
|
|
251
|
-
|
|
252
|
-
|
|
253
249
|
def max_model_len() -> int:
|
|
254
250
|
return int(os.getenv("VLLM_MAX_MODEL_LEN", "65536"))
|
|
255
251
|
|
|
@@ -58,25 +58,26 @@
|
|
|
58
58
|
" NOT pre-empt it — doing so would stop our own admin token",
|
|
59
59
|
" from fetching weights it is entitled to.",
|
|
60
60
|
"",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
" never be private either — an unpinned self-hoster would get",
|
|
65
|
-
" a 401 instead of a model — and the release parity gate says so.",
|
|
61
|
+
" `latest` may never be private — an unpinned self-hoster",
|
|
62
|
+
" would get a 401 instead of a model — and the release parity",
|
|
63
|
+
" gate says so.",
|
|
66
64
|
"",
|
|
67
|
-
" \"licensed\" —
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
65
|
+
" \"licensed\" — ON THE HUB, in a GATED repo named by the entry's key.",
|
|
66
|
+
" Access is granted to the Hugging Face account of each",
|
|
67
|
+
" licence holder, and withdrawn when the licence lapses.",
|
|
68
|
+
" Served to every account through api.captchakraken.com.",
|
|
69
|
+
" `captchakraken fetch` downloads it with the caller's own",
|
|
70
|
+
" Hub token, like a private model; a refusal from the Hub",
|
|
71
|
+
" becomes LicensedModelError, which names where the licence",
|
|
72
|
+
" is sold rather than reading as \"you are not logged in\".",
|
|
71
73
|
"",
|
|
72
74
|
"Why it lives HERE and not only in a policy doc: this file is already the one",
|
|
73
75
|
"place that decides what an unpinned client downloads and what prompts it",
|
|
74
76
|
"sends. A second list of 'models you may not publish' kept somewhere else",
|
|
75
77
|
"would be a list that drifts, and the drift is silent in the direction that",
|
|
76
|
-
"costs the most. The
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"they cannot obtain.",
|
|
78
|
+
"costs the most. The release parity gate refuses to let `latest` be a",
|
|
79
|
+
"licensed model, because an unpinned self-hoster would resolve to weights",
|
|
80
|
+
"they cannot obtain without a licence.",
|
|
80
81
|
"",
|
|
81
82
|
"`experts` is the fourth axis, and the newest. A ROUTED model is not one",
|
|
82
83
|
"adapter: Abyss is four LoRAs behind one endpoint, and the thing that picks",
|
|
@@ -263,7 +264,7 @@
|
|
|
263
264
|
"video": "abyss-video",
|
|
264
265
|
"text": "abyss-text"
|
|
265
266
|
},
|
|
266
|
-
"note": "A routed mixture of four expert LoRAs on Qwen3.5-9B — grid, pixel, video and text — selected by prompt family.
|
|
267
|
+
"note": "A routed mixture of four expert LoRAs on Qwen3.5-9B — grid, pixel, video and text — selected by prompt family. Its weights are in a gated Hub repo open to licence holders; everyone else reaches it through the hosted API. The current client names this model against our endpoint, which is why it and each of its arms has a served_aliases entry. `lora_name` is `abyss-general` rather than a fifth name because the generalist IS the fallback for any family `experts` does not map, so the two point at one adapter and the mixture needs one fewer resident LoRA slot."
|
|
267
268
|
},
|
|
268
269
|
"CaptchaKraken/Abyss-27B": {
|
|
269
270
|
"availability": "private",
|
|
@@ -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:
|
|
@@ -71,6 +73,20 @@ def _unlink(path: Optional[str]) -> None:
|
|
|
71
73
|
pass
|
|
72
74
|
|
|
73
75
|
|
|
76
|
+
def _shot(take: Any, style: Optional[str], **kwargs: Any) -> Any:
|
|
77
|
+
"""`take(**kwargs)` with `style` when there is one. Playwright before 1.41 has no `style` and raises TypeError;
|
|
78
|
+
that capture is then taken without it, so an older install keeps solving and only the board hash loses the
|
|
79
|
+
feedback mask."""
|
|
80
|
+
if style is None:
|
|
81
|
+
return take(**kwargs)
|
|
82
|
+
try:
|
|
83
|
+
return take(style=style, **kwargs)
|
|
84
|
+
except TypeError as exc:
|
|
85
|
+
if "style" not in str(exc):
|
|
86
|
+
raise
|
|
87
|
+
return take(**kwargs)
|
|
88
|
+
|
|
89
|
+
|
|
74
90
|
def _sha1(path: str) -> str:
|
|
75
91
|
with open(path, "rb") as fh:
|
|
76
92
|
return hashlib.sha1(fh.read()).hexdigest()
|
|
@@ -468,6 +484,11 @@ SLIDE_STALL_PX = 1.0
|
|
|
468
484
|
|
|
469
485
|
# No prompt and no pictures both read as ready: waiting for `.prompt-text` to exist once paid the whole timeout
|
|
470
486
|
# before every board of a challenge that draws none (tower_stack: 18s a round, 2/2 -> 0/2).
|
|
487
|
+
_TILE_RECTS_JS = """(sel) => Array.from(document.querySelectorAll(sel))
|
|
488
|
+
.map((e) => e.getBoundingClientRect())
|
|
489
|
+
.filter((r) => r.width > 0 && r.height > 0)
|
|
490
|
+
.map((r) => [r.left, r.top, r.right, r.bottom])"""
|
|
491
|
+
|
|
471
492
|
_BOARD_IMAGES_READY_JS = """({ prompt, images }) => {
|
|
472
493
|
const vis = (el) => !!el && el.getClientRects().length > 0
|
|
473
494
|
&& getComputedStyle(el).visibility !== 'hidden';
|
|
@@ -514,9 +535,8 @@ class PageSolver:
|
|
|
514
535
|
self._solver = solver or CaptchaSolver(**solver_kwargs)
|
|
515
536
|
self._human: Humanizer = resolve_humanizer(self.config)
|
|
516
537
|
self._sel = SelectorTable(self.config.custom_selectors, config=self.config.selectors)
|
|
517
|
-
#
|
|
518
|
-
|
|
519
|
-
_detector.configure(self._sel.config.detector)
|
|
538
|
+
# A stylesheet that takes every verdict message out of a photograph, laid out as if it had never been shown.
|
|
539
|
+
self._feedback_hidden = "\n".join(f"{s} {{ display: none !important; }}" for s in self._sel.feedback)
|
|
520
540
|
self._last_submit_frame_hash: Optional[str] = None
|
|
521
541
|
self._deadline_ms: Optional[float] = None
|
|
522
542
|
self._budget: Optional[PhaseBudget] = None
|
|
@@ -709,13 +729,17 @@ class PageSolver:
|
|
|
709
729
|
if planner is not None and hasattr(planner, "pointer_history"):
|
|
710
730
|
planner.pointer_history = self._pointer_history
|
|
711
731
|
|
|
712
|
-
def _board_hash(self, element: Any
|
|
713
|
-
"""The board's identity,
|
|
714
|
-
|
|
715
|
-
|
|
732
|
+
def _board_hash(self, element: Any) -> str:
|
|
733
|
+
"""The board's identity, from a photograph of its own.
|
|
734
|
+
|
|
735
|
+
A filmed frame of an unchanged board differs in bytes, and so does one wearing the vendor's verdict message,
|
|
736
|
+
a toast that comes and goes over the same board (see TRIBAL_KNOWLEDGE.md). The message is left out of the
|
|
737
|
+
picture, not waited out.
|
|
738
|
+
"""
|
|
716
739
|
plain = _tmp_png("board")
|
|
717
740
|
try:
|
|
718
|
-
self._screenshot(element, plain, timeout_ms=self.config.element_screenshot_timeout_ms
|
|
741
|
+
self._screenshot(element, plain, timeout_ms=self.config.element_screenshot_timeout_ms,
|
|
742
|
+
style=self._feedback_hidden)
|
|
719
743
|
return _sha1(plain)
|
|
720
744
|
finally:
|
|
721
745
|
_unlink(plain)
|
|
@@ -788,14 +812,30 @@ class PageSolver:
|
|
|
788
812
|
|
|
789
813
|
# ── the shared half, in-process ──────────────────────────────────────
|
|
790
814
|
|
|
791
|
-
def
|
|
792
|
-
|
|
815
|
+
def _dom_grid(self, element: Any, image_path: str) -> Optional[List[Sequence[int]]]:
|
|
816
|
+
"""The board's tiles as (x0, y0, x1, y1) pixels of `image_path`, a screenshot of `element`, in reading order.
|
|
793
817
|
|
|
818
|
+
Read from the vendor's own markup, not the picture: a tile is where the challenge frame placed it. A tile's
|
|
819
|
+
rectangle is in the frame's CSS pixels, which start at the iframe's corner, so it scales straight onto the
|
|
820
|
+
screenshot. None when the vendor names no tiles or the frame shows none.
|
|
821
|
+
"""
|
|
822
|
+
sel = self._sel.selectors.get(Vendor.RECAPTCHA)
|
|
823
|
+
dims = _read_png_dimensions(image_path)
|
|
824
|
+
if sel is None or not sel.tiles or not dims:
|
|
825
|
+
return None
|
|
794
826
|
try:
|
|
795
|
-
|
|
827
|
+
frame = element.content_frame()
|
|
828
|
+
box = element.bounding_box()
|
|
829
|
+
if frame is None or not box or box["width"] <= 0 or box["height"] <= 0:
|
|
830
|
+
return None
|
|
831
|
+
rects = frame.evaluate(_TILE_RECTS_JS, ",".join(sel.tiles))
|
|
796
832
|
except Exception as exc:
|
|
797
|
-
_debug(f"
|
|
833
|
+
_debug(f"reading the grid's tiles failed: {exc}")
|
|
798
834
|
return None
|
|
835
|
+
sx, sy = dims[0] / box["width"], dims[1] / box["height"]
|
|
836
|
+
boxes = [(int(round(x0 * sx)), int(round(y0 * sy)), int(round(x1 * sx)), int(round(y1 * sy)))
|
|
837
|
+
for x0, y0, x1, y1 in rects or ()]
|
|
838
|
+
return boxes if len(boxes) >= 4 else None
|
|
799
839
|
|
|
800
840
|
def _has_movement(self, path_a: str, path_b: str, threshold: float) -> bool:
|
|
801
841
|
from .image_processor import ImageProcessor
|
|
@@ -1058,17 +1098,92 @@ class PageSolver:
|
|
|
1058
1098
|
first = next(iter(_visible(scope, selectors)), None)
|
|
1059
1099
|
return _handle_of(first) if first is not None else None
|
|
1060
1100
|
|
|
1101
|
+
def _framed(self, widget: Widget, frame: Any, scope: Any) -> Tuple[Any, Optional[Any]]:
|
|
1102
|
+
"""The element whose screenshot the model is shown for `widget`, and the text box when it is typed.
|
|
1103
|
+
|
|
1104
|
+
This is the whole of what the client PHOTOGRAPHS, kept in one place so the capture gate can check it without
|
|
1105
|
+
solving: the widget, else the board its frame pads (Proton), widened by a text box beside it (BotDetect) or
|
|
1106
|
+
by the vendor's bar or slider track outside it (Yidun).
|
|
1107
|
+
"""
|
|
1108
|
+
element, puzzle_source = widget.element, widget.vendor
|
|
1109
|
+
# A widget frame that pads its board (Proton) is photographed by the board inside it.
|
|
1110
|
+
board = self._board_inside(frame, puzzle_source)
|
|
1111
|
+
if board is not None:
|
|
1112
|
+
_log("the widget frame pads its board; photographing the board itself")
|
|
1113
|
+
element = board
|
|
1114
|
+
|
|
1115
|
+
# Only the DOM can tell a typed captcha from a click puzzle; hCaptcha and reCAPTCHA never type.
|
|
1116
|
+
answer_box = None if puzzle_source in VENDORS_WITH_BESPOKE_HANDLING else self._answer_box(scope, widget.at)
|
|
1117
|
+
if answer_box is not None:
|
|
1118
|
+
_log("widget has a text box; solving as a distorted-text captcha")
|
|
1119
|
+
element = _WithAnswerBox(element, answer_box)
|
|
1120
|
+
elif puzzle_source not in VENDORS_WITH_BESPOKE_HANDLING:
|
|
1121
|
+
track = self._track_outside(scope, puzzle_source, element, widget.at)
|
|
1122
|
+
if track is not None:
|
|
1123
|
+
_log("the vendor bar or slider track sits outside the widget; photographing the two as one")
|
|
1124
|
+
element = _WithAnswerBox(element, track, SLIDER_TRACK_MAX_GROWTH)
|
|
1125
|
+
return element, answer_box
|
|
1126
|
+
|
|
1127
|
+
def capture(self, page: Any) -> Optional[Tuple[Widget, Any]]:
|
|
1128
|
+
"""The widget on `page` and the element the solver would photograph for it, without solving anything.
|
|
1129
|
+
|
|
1130
|
+
For release gates: whether the client finds a vendor's widget, by its selectors and URL markers, and frames
|
|
1131
|
+
the whole board, is checkable on a live page at no inference cost. A checkbox widget is returned with its own
|
|
1132
|
+
element; it is clicked, not photographed.
|
|
1133
|
+
"""
|
|
1134
|
+
self._page = page
|
|
1135
|
+
widget = self.detect_captcha(page)
|
|
1136
|
+
if widget is None:
|
|
1137
|
+
return None
|
|
1138
|
+
if widget.role == FrameRole.CHECKBOX:
|
|
1139
|
+
return widget, widget.element
|
|
1140
|
+
frame = widget.element.content_frame()
|
|
1141
|
+
if widget.vendor != Vendor.RECAPTCHA:
|
|
1142
|
+
self._wait_for_board_painted(widget.element)
|
|
1143
|
+
element, _ = self._framed(widget, frame, frame or widget.at)
|
|
1144
|
+
return widget, element
|
|
1145
|
+
|
|
1146
|
+
def _board_inside(self, frame: Any, vendor: Any) -> Optional[Any]:
|
|
1147
|
+
"""The vendor's own `board`, found in the widget's frame or a frame nested in it, or None.
|
|
1148
|
+
|
|
1149
|
+
Proton's widget frame is 682x600 with its 370x534 `.protonCaptchaContainer` centred two frames down; the
|
|
1150
|
+
pointer trained on that container, and shown the padded frame it repeated one answer until the solve gave up
|
|
1151
|
+
(live 0/2 on 2026-11-13). The board is drawn a moment after the frame, so it is waited for briefly.
|
|
1152
|
+
"""
|
|
1153
|
+
own = getattr(self._sel.selectors.get(vendor), "board", None)
|
|
1154
|
+
if not own or frame is None:
|
|
1155
|
+
return None
|
|
1156
|
+
deadline = _now() + _BOARD_INSIDE_WAIT_MS
|
|
1157
|
+
while True:
|
|
1158
|
+
try:
|
|
1159
|
+
frames = [frame]
|
|
1160
|
+
while frames:
|
|
1161
|
+
where = frames.pop(0)
|
|
1162
|
+
for found in _visible(where, own):
|
|
1163
|
+
handle = _handle_of(found)
|
|
1164
|
+
if handle is not None and handle.bounding_box():
|
|
1165
|
+
return handle
|
|
1166
|
+
frames.extend(where.child_frames)
|
|
1167
|
+
except Exception:
|
|
1168
|
+
return None
|
|
1169
|
+
if _now() >= deadline:
|
|
1170
|
+
return None
|
|
1171
|
+
_delay(_DETECTION_POLL_MS)
|
|
1172
|
+
|
|
1061
1173
|
def _track_outside(self, scope: Any, vendor: Any, element: Any, at: Any = None) -> Optional[Any]:
|
|
1062
|
-
"""The
|
|
1174
|
+
"""The vendor's own `bar`, else the track of its first slider handle, visible with its centre outside the widget.
|
|
1063
1175
|
|
|
1064
|
-
|
|
1176
|
+
The bar is what Yidun's click modes need: `.yidun_control` holds the 请依次点击 prompt that names the marks and
|
|
1177
|
+
their order, and on the bare `.yidun_panel` the pointer was shown neither (live 0/6 on 2026-11-13). The
|
|
1178
|
+
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
|
|
1065
1179
|
`.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed
|
|
1066
1180
|
over, not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The
|
|
1067
1181
|
track (the handle's parent) is returned rather than the handle, whose box moves as it slides and would
|
|
1068
1182
|
resize the frame.
|
|
1069
1183
|
"""
|
|
1070
|
-
|
|
1071
|
-
if
|
|
1184
|
+
mine = self._sel.selectors.get(vendor)
|
|
1185
|
+
kinds = [(sels, is_bar) for sels, is_bar in ((getattr(mine, "bar", None), True), (getattr(mine, "slider_handle", None), False)) if sels]
|
|
1186
|
+
if not kinds:
|
|
1072
1187
|
return None
|
|
1073
1188
|
# Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
|
|
1074
1189
|
try:
|
|
@@ -1076,16 +1191,17 @@ class PageSolver:
|
|
|
1076
1191
|
a = element.bounding_box()
|
|
1077
1192
|
if not a:
|
|
1078
1193
|
return None
|
|
1079
|
-
for
|
|
1080
|
-
for
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1194
|
+
for own, is_bar in kinds:
|
|
1195
|
+
for where in wheres:
|
|
1196
|
+
for found in _visible(where, own):
|
|
1197
|
+
handle = _handle_of(found)
|
|
1198
|
+
b = handle.bounding_box() if handle is not None else None
|
|
1199
|
+
if not b:
|
|
1200
|
+
continue
|
|
1201
|
+
cx, cy = b["x"] + b["width"] / 2, b["y"] + b["height"] / 2
|
|
1202
|
+
if a["x"] <= cx <= a["x"] + a["width"] and a["y"] <= cy <= a["y"] + a["height"]:
|
|
1203
|
+
continue
|
|
1204
|
+
return handle if is_bar else (_handle_of(found.locator("xpath=..")) or handle)
|
|
1089
1205
|
except Exception:
|
|
1090
1206
|
return None
|
|
1091
1207
|
return None
|
|
@@ -1430,7 +1546,7 @@ class PageSolver:
|
|
|
1430
1546
|
_delay(_DETECTION_POLL_MS)
|
|
1431
1547
|
|
|
1432
1548
|
def _checkbox_on_screen(self, element: Any) -> Optional[Tuple[float, float]]:
|
|
1433
|
-
"""One capture and
|
|
1549
|
+
"""One capture and plain pixel arithmetic, no model: a point inside the tick box, or None when none is drawn."""
|
|
1434
1550
|
from .tool_calls.find_checkbox import find_checkbox
|
|
1435
1551
|
|
|
1436
1552
|
box = element.bounding_box()
|
|
@@ -1462,19 +1578,30 @@ class PageSolver:
|
|
|
1462
1578
|
return
|
|
1463
1579
|
_delay(self.config.post_solve_outcome_poll_ms)
|
|
1464
1580
|
|
|
1465
|
-
def _get_verify_button(self, scope: Any) -> Optional[Any]:
|
|
1466
|
-
|
|
1581
|
+
def _get_verify_button(self, scope: Any, typed_at: Any = None) -> Optional[Any]:
|
|
1582
|
+
"""The widget's Verify, else, after a typed answer, the vendor-named submit beside its text box.
|
|
1583
|
+
|
|
1584
|
+
BotDetect's Validate sits in the widget's fieldset, outside the 280x50 `.BDC_CaptchaDiv`, like `#captchaCode`
|
|
1585
|
+
(see `_answer_box`). Without it the code was typed and never sent: live 0/9 on 2026-11-13. Only vendor-named
|
|
1586
|
+
selectors widen, so a login form's own Submit is never pressed.
|
|
1587
|
+
"""
|
|
1588
|
+
inside = self._find_control(scope, self._sel.submit)
|
|
1589
|
+
if inside is not None or typed_at is None:
|
|
1590
|
+
return inside
|
|
1591
|
+
around = (self._find_control(typed_at.locator(f"xpath={axis}"), self._sel.submit_vendor)
|
|
1592
|
+
for axis in ("ancestor::fieldset[1]", "ancestor::form[1]"))
|
|
1593
|
+
return next((found for found in around if found is not None), None)
|
|
1467
1594
|
|
|
1468
1595
|
# ── frames and polling ───────────────────────────────────────────────
|
|
1469
1596
|
|
|
1470
1597
|
def _screenshot(self, element: Any, path: str, timeout_ms: Optional[int] = None,
|
|
1471
|
-
animations: str = "disabled") -> None:
|
|
1598
|
+
animations: str = "disabled", style: Optional[str] = None) -> None:
|
|
1472
1599
|
"""Every capture the driver takes: the whole viewport, cropped here to the element.
|
|
1473
1600
|
|
|
1474
1601
|
Never a clipped capture. An element screenshot, or any `clip`, makes a headed Chromium repaint the page at
|
|
1475
1602
|
the clip's size for that frame, which the user watches as the page flashing and jumping; a viewport
|
|
1476
1603
|
capture repaints nothing, and measured twice as fast. Short timeout; `disabled` freezes CSS animation,
|
|
1477
|
-
so bursts and the keyframe gate pass `allow`.
|
|
1604
|
+
so bursts and the keyframe gate pass `allow`. `style` is CSS applied for this capture only.
|
|
1478
1605
|
"""
|
|
1479
1606
|
timeout = 2_500 if timeout_ms is None else timeout_ms
|
|
1480
1607
|
page = self._page
|
|
@@ -1483,9 +1610,9 @@ class PageSolver:
|
|
|
1483
1610
|
if rect is None:
|
|
1484
1611
|
# Bigger than the viewport, or a zoomed-out mobile layout: no viewport capture holds it in its own
|
|
1485
1612
|
# coordinates, so the element photographs itself.
|
|
1486
|
-
element.screenshot
|
|
1613
|
+
_shot(element.screenshot, style, path=path, timeout=timeout, animations=animations)
|
|
1487
1614
|
return
|
|
1488
|
-
png = crop_png(page.screenshot
|
|
1615
|
+
png = crop_png(_shot(page.screenshot, style, timeout=timeout, animations=animations), rect, view["width"])
|
|
1489
1616
|
with open(path, "wb") as fh:
|
|
1490
1617
|
fh.write(png)
|
|
1491
1618
|
|
|
@@ -1594,7 +1721,7 @@ class PageSolver:
|
|
|
1594
1721
|
def judge(frames, elapsed):
|
|
1595
1722
|
if len(frames) < 2:
|
|
1596
1723
|
return None
|
|
1597
|
-
boxes = self.
|
|
1724
|
+
boxes = self._dom_grid(element, frames[1])
|
|
1598
1725
|
if not boxes:
|
|
1599
1726
|
return False if elapsed >= cfg.grid_load_timeout_ms else None
|
|
1600
1727
|
states = self._grid_cell_states(frames[0], frames[1], boxes)
|
|
@@ -1645,7 +1772,7 @@ class PageSolver:
|
|
|
1645
1772
|
path = _tmp_png("findgrid")
|
|
1646
1773
|
try:
|
|
1647
1774
|
self._screenshot(element, path, timeout_ms=self.config.element_screenshot_timeout_ms)
|
|
1648
|
-
boxes = self.
|
|
1775
|
+
boxes = self._dom_grid(element, path)
|
|
1649
1776
|
dims = _read_png_dimensions(path)
|
|
1650
1777
|
if not boxes or len(boxes) not in (9, 16) or not dims:
|
|
1651
1778
|
return None
|
|
@@ -2260,17 +2387,8 @@ class PageSolver:
|
|
|
2260
2387
|
with self._phase(Phase.BOARD_PAINT):
|
|
2261
2388
|
self._wait_for_board_painted(element)
|
|
2262
2389
|
|
|
2263
|
-
|
|
2264
|
-
answer_box = None if puzzle_source in VENDORS_WITH_BESPOKE_HANDLING else self._answer_box(scope, widget.at)
|
|
2390
|
+
element, answer_box = self._framed(widget, frame, scope)
|
|
2265
2391
|
text_mode = answer_box is not None
|
|
2266
|
-
if text_mode:
|
|
2267
|
-
_log("widget has a text box; solving as a distorted-text captcha")
|
|
2268
|
-
element = _WithAnswerBox(element, answer_box)
|
|
2269
|
-
elif puzzle_source not in VENDORS_WITH_BESPOKE_HANDLING:
|
|
2270
|
-
track = self._track_outside(scope, puzzle_source, element, widget.at)
|
|
2271
|
-
if track is not None:
|
|
2272
|
-
_log("the slider track sits outside the widget; photographing the two as one")
|
|
2273
|
-
element = _WithAnswerBox(element, track, SLIDER_TRACK_MAX_GROWTH)
|
|
2274
2392
|
|
|
2275
2393
|
# A reCAPTCHA board is read by its grid below, not filmed.
|
|
2276
2394
|
filmable = puzzle_source != Vendor.RECAPTCHA and not text_mode
|
|
@@ -2298,7 +2416,7 @@ class PageSolver:
|
|
|
2298
2416
|
|
|
2299
2417
|
shot = _tmp_png("captcha")
|
|
2300
2418
|
self._round_board = None
|
|
2301
|
-
performed = slid = answered = have_shot = False
|
|
2419
|
+
performed = slid = answered = typed = have_shot = False
|
|
2302
2420
|
all_usage: List[Dict[str, Any]] = []
|
|
2303
2421
|
keyframe_dir: Optional[str] = None
|
|
2304
2422
|
try:
|
|
@@ -2341,7 +2459,7 @@ class PageSolver:
|
|
|
2341
2459
|
if not have_shot:
|
|
2342
2460
|
with self._phase(Phase.SCREENSHOT):
|
|
2343
2461
|
self._screenshot(element, shot, timeout_ms=self.config.element_screenshot_timeout_ms)
|
|
2344
|
-
self._guard_fallbacks_to_board(self._board_hash(element
|
|
2462
|
+
self._guard_fallbacks_to_board(self._board_hash(element))
|
|
2345
2463
|
if self._should_speculate(puzzle_source, text_mode):
|
|
2346
2464
|
actions, all_usage, keyframe_dir = self._speculate(element, shot, puzzle_source, retry_mode, text_mode)
|
|
2347
2465
|
is_animated = keyframe_dir is not None
|
|
@@ -2399,7 +2517,7 @@ class PageSolver:
|
|
|
2399
2517
|
performed = answered = True
|
|
2400
2518
|
elif kind == ActionKind.TYPE:
|
|
2401
2519
|
if self._execute_type(page, scope, action, widget.at):
|
|
2402
|
-
performed = answered = True
|
|
2520
|
+
performed = answered = typed = True
|
|
2403
2521
|
elif kind == ActionKind.HOLD:
|
|
2404
2522
|
# The widget submits itself when the hold completes, like a slide on release.
|
|
2405
2523
|
self._execute_hold(page, action, element_box, element, self._sel.selectors[widget.vendor].hold_completes)
|
|
@@ -2419,7 +2537,8 @@ class PageSolver:
|
|
|
2419
2537
|
# `done` plan still presses Verify/Skip. FunCaptcha's answer is the click itself: an arrow pages and
|
|
2420
2538
|
# Submit submits. The generic Verify fallback would submit the page an arrow just turned to.
|
|
2421
2539
|
submits = self._submitted_on_board if slid else answered or not performed
|
|
2422
|
-
verify_button = self._get_verify_button(scope
|
|
2540
|
+
verify_button = (self._get_verify_button(scope, widget.at if typed else None)
|
|
2541
|
+
if submits and puzzle_source != Vendor.FUNCAPTCHA else None)
|
|
2423
2542
|
if verify_button:
|
|
2424
2543
|
_log(f"clicking Verify to submit ({puzzle_source}).")
|
|
2425
2544
|
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
|