captchakraken 4.1.1 → 4.2.0

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/dist/kinds.d.ts CHANGED
@@ -21,6 +21,7 @@ export declare const Vendor: {
21
21
  readonly DINGXIANG: "dingxiang";
22
22
  readonly FUNCAPTCHA: "funcaptcha";
23
23
  readonly PROTON: "proton";
24
+ readonly DATADOME: "datadome";
24
25
  readonly UNKNOWN: "unknown";
25
26
  };
26
27
  export type Vendor = (typeof Vendor)[keyof typeof Vendor];
package/dist/kinds.js CHANGED
@@ -25,6 +25,7 @@ exports.Vendor = {
25
25
  DINGXIANG: 'dingxiang',
26
26
  FUNCAPTCHA: 'funcaptcha',
27
27
  PROTON: 'proton',
28
+ DATADOME: 'datadome',
28
29
  UNKNOWN: 'unknown',
29
30
  };
30
31
  exports.ActionKind = { CLICK: 'click', DRAG: 'drag', TYPE: 'type', WAIT: 'wait', DONE: 'done', HOLD: 'hold', REFRESH: 'refresh', SLIDE: 'slide' };
package/dist/solver.d.ts CHANGED
@@ -16,13 +16,16 @@ export interface Widget {
16
16
  }
17
17
  /**
18
18
  * A typed captcha's image and its text box, photographed and pointed into as one element.
19
+ * The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
20
+ * float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and on
21
+ * the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
19
22
  *
20
23
  * BotDetect's widget element is a 280x50 strip holding only the image; its text box is a sibling. Every training
21
24
  * board and every real capture of a typed captcha shows the box under the image, and on the bare strip the pointer
22
25
  * read the image as a click puzzle or doubled a glyph. The answer's points are taken in this union's frame, so
23
26
  * `boundingBox` is the union everywhere the round reads it; everything else is the element's own.
24
27
  */
25
- export declare function withAnswerBox(el: ElementHandle, box: ElementHandle): ElementHandle;
28
+ export declare function withAnswerBox(el: ElementHandle, box: ElementHandle, maxGrowth?: number): ElementHandle;
26
29
  /** An allow-list of what needs nothing: the other direction raises instead of clicking at the origin. */
27
30
  export declare function answerNeedsElementBox(actions: ReadonlyArray<{
28
31
  action?: string;
@@ -391,6 +394,14 @@ export declare class CaptchaKrakenSolver {
391
394
  private executeRefresh;
392
395
  private executeDrag;
393
396
  private findControl;
397
+ /**
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
400
+ * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
401
+ * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
402
+ * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
403
+ */
404
+ private trackOutside;
394
405
  /**
395
406
  * The text box inside the widget, else a vendor-named one in its enclosing fieldset/form, never the page: the generic
396
407
  * tail outside the widget is how a captcha's answer lands in a login form's username box. The widening exists for
package/dist/solver.js CHANGED
@@ -133,15 +133,23 @@ const HANDLE_TIMEOUT_MS = 1000;
133
133
  * times the image's area. A vendor-named box found in the enclosing form can be a whole login form away.
134
134
  */
135
135
  const ANSWER_BOX_MAX_GROWTH = 4;
136
+ /**
137
+ * A slider's handle widens the shot only when it sits just outside the picture: the union may be at most this many
138
+ * times the picture's area. Yidun's bar is 40px under a 175px panel (x1.23).
139
+ */
140
+ const SLIDER_TRACK_MAX_GROWTH = 2;
136
141
  /**
137
142
  * A typed captcha's image and its text box, photographed and pointed into as one element.
143
+ * The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
144
+ * float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and on
145
+ * the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
138
146
  *
139
147
  * BotDetect's widget element is a 280x50 strip holding only the image; its text box is a sibling. Every training
140
148
  * board and every real capture of a typed captcha shows the box under the image, and on the bare strip the pointer
141
149
  * read the image as a click puzzle or doubled a glyph. The answer's points are taken in this union's frame, so
142
150
  * `boundingBox` is the union everywhere the round reads it; everything else is the element's own.
143
151
  */
144
- function withAnswerBox(el, box) {
152
+ function withAnswerBox(el, box, maxGrowth = ANSWER_BOX_MAX_GROWTH) {
145
153
  const union = async () => {
146
154
  const a = await el.boundingBox();
147
155
  const b = a ? await box.boundingBox() : null;
@@ -149,7 +157,7 @@ function withAnswerBox(el, box) {
149
157
  return a;
150
158
  const x0 = Math.min(a.x, b.x), y0 = Math.min(a.y, b.y);
151
159
  const x1 = Math.max(a.x + a.width, b.x + b.width), y1 = Math.max(a.y + a.height, b.y + b.height);
152
- if ((x1 - x0) * (y1 - y0) > ANSWER_BOX_MAX_GROWTH * Math.max(a.width * a.height, 1))
160
+ if ((x1 - x0) * (y1 - y0) > maxGrowth * Math.max(a.width * a.height, 1))
153
161
  return a;
154
162
  return { x: x0, y: y0, width: x1 - x0, height: y1 - y0 };
155
163
  };
@@ -179,6 +187,17 @@ const SLIDE_MAX_CORRECTIONS = 3;
179
187
  // The nudge that shows the tracker what the handle moves: enough to separate the part from still ground, little
180
188
  // enough that a piece resting against the board's edge stays on it. Mirrors page_solver.py SLIDE_PROBE_PX.
181
189
  const SLIDE_PROBE_PX = 8;
190
+ // A part that moves less than this while the handle travels more than half a probe has reached the end of its track:
191
+ // pushing on only carries the pointer away from the handle. Mirrors page_solver.py SLIDE_STALL_PX.
192
+ const SLIDE_STALL_PX = 1;
193
+ const slideOffset = (s) => (Array.isArray(s) ? [s[0], s[1]] : [s, 0]);
194
+ /** Did the handle travel while the part stayed put? Each side is the travel and the part's point of one look. */
195
+ const slideStalled = (before, now, k) => {
196
+ const [ax, ay] = slideOffset(before[0]);
197
+ const [bx, by] = slideOffset(now[0]);
198
+ const moved = Math.hypot(now[1][0] - before[1][0], now[1][1] - before[1][1]);
199
+ return Math.hypot(bx - ax, by - ay) > (SLIDE_PROBE_PX / 2) * k && moved < SLIDE_STALL_PX * k;
200
+ };
182
201
  /** An allow-list of what needs nothing: the other direction raises instead of clicking at the origin. */
183
202
  function answerNeedsElementBox(actions) {
184
203
  return actions.some((a) => a?.action !== kinds_1.ActionKind.DONE);
@@ -805,6 +824,13 @@ class CaptchaKrakenSolver {
805
824
  console.log('Widget has a text box; solving as a distorted-text captcha.');
806
825
  captchaElement = withAnswerBox(captchaElement, answerBox);
807
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
+ }
808
834
  // A reCAPTCHA board is read by its grid below, not filmed.
809
835
  const filmable = puzzleSource !== kinds_1.Vendor.RECAPTCHA && !textMode;
810
836
  if (filmable && !this.knownAnimated)
@@ -2897,6 +2923,39 @@ class CaptchaKrakenSolver {
2897
2923
  const [first] = await visible(scope, selectors);
2898
2924
  return first ? handleOf(first) : null;
2899
2925
  }
2926
+ /**
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
2929
+ * `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed over,
2930
+ * not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The track (the
2931
+ * handle's parent) is returned rather than the handle, whose box moves as it slides and would resize the frame.
2932
+ */
2933
+ async trackOutside(scope, vendor, el, at) {
2934
+ const own = this.sel.selectors[vendor]?.sliderHandle;
2935
+ if (!own?.length)
2936
+ return null;
2937
+ // Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
2938
+ try {
2939
+ const a = await el.boundingBox();
2940
+ if (!a)
2941
+ 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);
2951
+ }
2952
+ }
2953
+ }
2954
+ catch {
2955
+ return null;
2956
+ }
2957
+ return null;
2958
+ }
2900
2959
  /**
2901
2960
  * The text box inside the widget, else a vendor-named one in its enclosing fieldset/form, never the page: the generic
2902
2961
  * tail outside the widget is how a captcha's answer lands in a login form's username box. The widening exists for
@@ -2988,19 +3047,28 @@ class CaptchaKrakenSolver {
2988
3047
  let look = probed;
2989
3048
  let s = probe * k;
2990
3049
  const history = [];
3050
+ let last = null;
2991
3051
  for (let moves = 0;; moves++) {
2992
3052
  const reply = await this.slideStep({ ...ask, current: look, s, history });
2993
3053
  if (!reply)
2994
3054
  break;
2995
3055
  if (look !== probed)
2996
3056
  history.push(reply.observation);
3057
+ const pos = [reply.pos[0], reply.pos[1]];
3058
+ if (last && slideStalled(last, [s, pos], k)) {
3059
+ console.warn('[slide] the part stopped following the handle; releasing at the end of its track');
3060
+ const [bx, by] = slideOffset(last[0]);
3061
+ await this.performSmoothMove(page, press[0] + bx / k, press[1] + by / k);
3062
+ break;
3063
+ }
3064
+ last = [s, pos];
2997
3065
  if (reply.done || moves >= SLIDE_MAX_CORRECTIONS) {
2998
3066
  if (reply.error > ask.tol)
2999
3067
  console.warn(`[slide] releasing ${(reply.error / k).toFixed(1)}px off target`);
3000
3068
  break;
3001
3069
  }
3002
3070
  s = reply.next;
3003
- const [dx, dy] = Array.isArray(s) ? s : [s, 0];
3071
+ const [dx, dy] = slideOffset(s);
3004
3072
  await this.performSmoothMove(page, press[0] + dx / k, press[1] + dy / k);
3005
3073
  await this.human.pause(kinds_1.PauseKind.PROBE);
3006
3074
  await this.shot(element, current, timeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "captchakraken",
3
- "version": "4.1.1",
3
+ "version": "4.2.0",
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 \u2014 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 = "4.1.1"
7
+ version = "4.2.0"
8
8
  description = "Captcha-solving engine and CLI: a v2 pointer model and CNN element detector 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__ = "4.1.1"
103
+ __version__ = "4.2.0"
@@ -377,6 +377,24 @@
377
377
  "iframe[src*=\"/core/v4/captcha\"]"
378
378
  ]
379
379
  },
380
+ "datadome": {
381
+ "note": "The interstitial is one full-viewport iframe served from geo.captcha-delivery.com/captcha/, so it is the challenge itself, with no checkbox. Its visual mode is a slide-to-the-end bar; the handle is `.slider` inside `.sliderContainer`, and a pass reloads the host page. A refused session gets a 'You have been blocked' page in the same frame, under the same URL.",
382
+ "hosts": [
383
+ "captcha-delivery.com"
384
+ ],
385
+ "challenge": [
386
+ "iframe[src*=\"captcha-delivery.com/captcha\"]"
387
+ ],
388
+ "blocked": [
389
+ "body.dd-response-page--hard-block .captcha__human__title"
390
+ ],
391
+ "slider_handle": [
392
+ ".sliderContainer .slider"
393
+ ],
394
+ "refresh": [
395
+ "#captcha__reload__button"
396
+ ]
397
+ },
380
398
  "unknown": {
381
399
  "hosts": []
382
400
  }
@@ -22,6 +22,7 @@ class Vendor(StrEnum):
22
22
  DINGXIANG = "dingxiang"
23
23
  FUNCAPTCHA = "funcaptcha"
24
24
  PROTON = "proton"
25
+ DATADOME = "datadome"
25
26
  UNKNOWN = "unknown"
26
27
 
27
28
 
@@ -198,6 +198,9 @@ class SolveResult:
198
198
  #: 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
199
  #: times the image's area. A vendor-named box found in the enclosing form can be a whole login form away.
200
200
  ANSWER_BOX_MAX_GROWTH = 4.0
201
+ #: A slider's handle widens the shot only when it sits just outside the picture: the union may be at most this many
202
+ #: times the picture's area. Yidun's bar is 40px under a 175px panel (x1.23).
203
+ SLIDER_TRACK_MAX_GROWTH = 2.0
201
204
 
202
205
 
203
206
  class _WithAnswerBox:
@@ -208,10 +211,14 @@ class _WithAnswerBox:
208
211
  strip the pointer read the image as a click puzzle (p(type) 0.46) or doubled a glyph, where the same frame
209
212
  with its box read R9VK at p >= 0.89 per character. The answer's points are taken in this union's frame, so
210
213
  `bounding_box` is the union everywhere the round reads it; everything else is the element's own.
214
+
215
+ The same union carries a slider's handle when the vendor draws its track outside the widget element: Yidun's
216
+ float layout pops `.yidun_panel` above a separate bar. Every training board shows the bar with its handle, and
217
+ on the bare panel the pointer had no handle to name, so it dragged the piece (which Yidun ignores) or named the hole.
211
218
  """
212
219
 
213
- def __init__(self, element: Any, box: Any):
214
- self._element, self._box = element, box
220
+ def __init__(self, element: Any, box: Any, max_growth: float = ANSWER_BOX_MAX_GROWTH):
221
+ self._element, self._box, self._max_growth = element, box, max_growth
215
222
 
216
223
  def bounding_box(self) -> Optional[Dict[str, float]]:
217
224
  a = self._element.bounding_box()
@@ -221,7 +228,7 @@ class _WithAnswerBox:
221
228
  x0, y0 = min(a["x"], b["x"]), min(a["y"], b["y"])
222
229
  x1 = max(a["x"] + a["width"], b["x"] + b["width"])
223
230
  y1 = max(a["y"] + a["height"], b["y"] + b["height"])
224
- if (x1 - x0) * (y1 - y0) > ANSWER_BOX_MAX_GROWTH * max(a["width"] * a["height"], 1.0):
231
+ if (x1 - x0) * (y1 - y0) > self._max_growth * max(a["width"] * a["height"], 1.0):
225
232
  return a
226
233
  return {"x": x0, "y": y0, "width": x1 - x0, "height": y1 - y0}
227
234
 
@@ -454,6 +461,10 @@ def _has_text(handle: Any) -> bool:
454
461
  # The nudge that shows the tracker what the handle moves: enough to separate the part from still ground, little enough
455
462
  # that a piece resting against the board's edge stays on it.
456
463
  SLIDE_PROBE_PX = 8.0
464
+ # A part that moves less than this while the handle travels more than half a probe has reached the end of its
465
+ # track: pushing on only carries the pointer away from the handle, and a vendor may cancel a drag that strays
466
+ # (DataDome snapped its handle home about 110 px past the stop). Shot pixels at device scale 1.
467
+ SLIDE_STALL_PX = 1.0
457
468
 
458
469
  # No prompt and no pictures both read as ready: waiting for `.prompt-text` to exist once paid the whole timeout
459
470
  # before every board of a challenge that draws none (tower_stack: 18s a round, 2/2 -> 0/2).
@@ -478,6 +489,18 @@ _RESOURCES_JS = """() => {
478
489
  }"""
479
490
 
480
491
 
492
+ def _offset(s: Any) -> Tuple[float, float]:
493
+ """A slide travel as (dx, dy): a number runs along the track, a pair is a carried piece's own offset."""
494
+ return (float(s[0]), float(s[1])) if isinstance(s, (list, tuple)) else (float(s), 0.0)
495
+
496
+
497
+ def _stalled(before: Tuple[Any, Sequence[float]], now: Tuple[Any, Sequence[float]], k: float) -> bool:
498
+ """Did the handle travel while the part stayed put? Each side is (travel, the part's point) of one look."""
499
+ (ax, ay), (bx, by) = _offset(before[0]), _offset(now[0])
500
+ moved = math.hypot(now[1][0] - before[1][0], now[1][1] - before[1][1])
501
+ return math.hypot(bx - ax, by - ay) > SLIDE_PROBE_PX / 2 * k and moved < SLIDE_STALL_PX * k
502
+
503
+
481
504
  class PageSolver:
482
505
  """Drives one Playwright-compatible `page` through a captcha. Reusable across solves."""
483
506
 
@@ -1035,6 +1058,39 @@ class PageSolver:
1035
1058
  first = next(iter(_visible(scope, selectors)), None)
1036
1059
  return _handle_of(first) if first is not None else None
1037
1060
 
1061
+ def _track_outside(self, scope: Any, vendor: Any, element: Any, at: Any = None) -> Optional[Any]:
1062
+ """The track of the first of the vendor's own slider handles that is visible with its centre outside the widget.
1063
+
1064
+ It is looked for in the widget, then in its parent and grandparent: Yidun's `.yidun_slider` is in
1065
+ `.yidun_control`, a sibling of the `.yidun_panel` the widget resolves to. A match inside the widget is passed
1066
+ over, not taken as the answer: Yidun lists its piece (`.yidun_jigsaw`, in the panel) as a handle too. The
1067
+ track (the handle's parent) is returned rather than the handle, whose box moves as it slides and would
1068
+ resize the frame.
1069
+ """
1070
+ own = getattr(self._sel.selectors.get(vendor), "slider_handle", None)
1071
+ if not own:
1072
+ return None
1073
+ # Widening the shot is a nicety: a scope that cannot be searched (a detached frame) leaves the shot as it was.
1074
+ try:
1075
+ wheres = [scope, *((at.locator(f"xpath=ancestor::*[{k}]") for k in (1, 2)) if at is not None else ())]
1076
+ a = element.bounding_box()
1077
+ if not a:
1078
+ return None
1079
+ for where in wheres:
1080
+ for found in _visible(where, own):
1081
+ handle = _handle_of(found)
1082
+ b = handle.bounding_box() if handle is not None else None
1083
+ if not b:
1084
+ continue
1085
+ cx, cy = b["x"] + b["width"] / 2, b["y"] + b["height"] / 2
1086
+ if a["x"] <= cx <= a["x"] + a["width"] and a["y"] <= cy <= a["y"] + a["height"]:
1087
+ continue
1088
+ return _handle_of(found.locator("xpath=..")) or handle
1089
+ except Exception:
1090
+ return None
1091
+ return None
1092
+ return None
1093
+
1038
1094
  def _answer_box(self, scope: Any, at: Any = None) -> Optional[Any]:
1039
1095
  """The text box inside the widget, else a vendor-named one in its enclosing fieldset/form.
1040
1096
 
@@ -1115,6 +1171,7 @@ class PageSolver:
1115
1171
  handle=(handle[0] * k, handle[1] * k), bounds=(-handle[0] * k, (w - handle[0]) * k),
1116
1172
  tol=self.config.slide_tolerance_px * k)
1117
1173
  look, s, history, moves = probed, probe * k, [], 0
1174
+ last: Optional[Tuple[Any, Sequence[float]]] = None
1118
1175
  while True:
1119
1176
  try:
1120
1177
  reply = slide_step(first, probed, look, s=s, history=history, **ask)
@@ -1123,6 +1180,12 @@ class PageSolver:
1123
1180
  break
1124
1181
  if look is not probed:
1125
1182
  history.append(reply["observation"])
1183
+ if last is not None and _stalled(last, (s, reply["pos"]), k):
1184
+ _log("slider: the part stopped following the handle; releasing at the end of its track")
1185
+ dx, dy = _offset(last[0])
1186
+ self._smooth_move(page, press[0] + dx / k, press[1] + dy / k)
1187
+ break
1188
+ last = (s, reply["pos"])
1126
1189
  _debug(f"slider: point at ({reply['pos'][0] / k:.1f}, {reply['pos'][1] / k:.1f}), "
1127
1190
  f"{reply['error'] / k:.1f}px from its target, {reply['kind']}")
1128
1191
  if reply["done"] or moves >= self.config.slide_max_corrections:
@@ -1130,7 +1193,7 @@ class PageSolver:
1130
1193
  _log(f"slider: releasing {reply['error'] / k:.1f}px off target")
1131
1194
  break
1132
1195
  s = reply["next"]
1133
- dx, dy = (s[0], s[1]) if reply["grabbed"] else (s, 0.0)
1196
+ dx, dy = _offset(s)
1134
1197
  self._smooth_move(page, press[0] + dx / k, press[1] + dy / k)
1135
1198
  self._human.pause(PauseKind.PROBE)
1136
1199
  self._screenshot(element, current, timeout_ms=timeout)
@@ -2203,6 +2266,11 @@ class PageSolver:
2203
2266
  if text_mode:
2204
2267
  _log("widget has a text box; solving as a distorted-text captcha")
2205
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)
2206
2274
 
2207
2275
  # A reCAPTCHA board is read by its grid below, not filmed.
2208
2276
  filmable = puzzle_source != Vendor.RECAPTCHA and not text_mode
@@ -1091,7 +1091,16 @@ def slide_step(first: Image, probe: Image, current: Image, *, probe_s: Offset, s
1091
1091
  if _same(current, probe):
1092
1092
  params, corr = measure(first, probe, seg, guess=seg.probe, reach_px=2.0, reach_deg=1.0)
1093
1093
  else:
1094
- params, corr = measure(first, current, seg, guess=predict(samples, seg, cur))
1094
+ guess = predict(samples, seg, cur)
1095
+ try:
1096
+ params, corr = measure(first, current, seg, guess=guess)
1097
+ except TrackingError:
1098
+ # A part that trails its handle reads a short gain off the probe: Yidun's lags by half the travel up to
1099
+ # ~11px, so an 8px probe moved it 4 and the plan sent the handle twice as far as it needed. The part then
1100
+ # lands far outside the reach around the guess. On a rail the whole track is cheap to search.
1101
+ if _rail(seg) is None:
1102
+ raise
1103
+ params, corr = measure(first, current, seg, guess=guess, reach_px=float(a.shape[1]))
1095
1104
  samples.append(Sample(cur, params))
1096
1105
  pos = transform_point(params, seg.centroid, point)
1097
1106
  dist = math.hypot(goal[0] - pos[0], goal[1] - pos[1])