captchakraken 2.1.0 → 2.3.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/LICENSE ADDED
@@ -0,0 +1,105 @@
1
+ CaptchaKraken Source-Available License v1.0
2
+ Copyright (c) 2026 JobHarvest / JWriter20. All rights reserved.
3
+
4
+ This license governs use of the CaptchaKraken software in this repository and of
5
+ the associated machine-learning model weights and LoRA adapters published by the
6
+ copyright holder (collectively, the "Software"). By using the Software you agree
7
+ to these terms. If you do not agree, do not use the Software.
8
+
9
+ ================================================================================
10
+ 1. GRANT
11
+ ================================================================================
12
+ Subject to the restrictions below, you are granted a worldwide, royalty-free,
13
+ non-exclusive license to use, copy, modify, and distribute the Software, and to
14
+ incorporate it into your own products and services.
15
+
16
+ ================================================================================
17
+ 2. PERMITTED USES
18
+ ================================================================================
19
+ You MAY use the Software for:
20
+
21
+ (a) Personal, non-commercial use, research, and education.
22
+
23
+ (b) Commercial use INSIDE a larger product or service that delivers
24
+ substantial value BEYOND captcha solving itself — that is, where captcha
25
+ solving is an internal, enabling component rather than the product.
26
+
27
+ Illustrative (non-exhaustive) examples of PERMITTED commercial use:
28
+ - Web scrapers and data-collection pipelines.
29
+ - Stealth / anti-detection browsers and browser automation frameworks
30
+ that use the Software as one internal capability.
31
+ - QA, testing, and accessibility tooling.
32
+ - Any application where the captcha solve is a means to an end the user
33
+ is actually paying for.
34
+
35
+ ================================================================================
36
+ 3. PROHIBITED USES
37
+ ================================================================================
38
+ You MAY NOT, without a separate written commercial agreement from the copyright
39
+ holder:
40
+
41
+ (a) Sell, resell, rent, or otherwise offer for a fee any captcha-SOLVING
42
+ service, product, or API whose primary value is solving captchas,
43
+ where that service is powered by the Software or its model outputs.
44
+
45
+ (b) Distribute "thin wrappers" around the Software whose primary purpose is
46
+ captcha solving — including but not limited to browser extensions,
47
+ hosted endpoints, SaaS products, or CLIs that simply expose the
48
+ Software's solving capability to end users.
49
+
50
+ (c) Expose, proxy, or relay the responses or outputs of the Software's LoRA
51
+ models (e.g. bounding boxes, tile selections, click plans) through a paid
52
+ or public API as a captcha-solving service.
53
+
54
+ In short: you may BUILD WITH this Software, but you may not SELL THE SOLVE.
55
+
56
+ ================================================================================
57
+ 4. MODEL OUTPUTS
58
+ ================================================================================
59
+ Outputs produced by the model weights/adapters are subject to Sections 2 and 3
60
+ to the same extent as the Software itself. Reselling or API-relaying those
61
+ outputs as a captcha-solving service is prohibited under Section 3(c).
62
+
63
+ ================================================================================
64
+ 5. REDISTRIBUTION
65
+ ================================================================================
66
+ If you redistribute the Software (modified or not), you must retain this license
67
+ and this notice, and you must not remove or alter the restrictions in Section 3.
68
+
69
+ ================================================================================
70
+ 6. TRADEMARKS
71
+ ================================================================================
72
+ This license does not grant permission to use the trade names, trademarks, or
73
+ product names of the copyright holder, except as required to describe the origin
74
+ of the Software.
75
+
76
+ ================================================================================
77
+ 7. NO WARRANTY
78
+ ================================================================================
79
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
81
+ FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
82
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER
83
+ IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR IN
84
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
85
+
86
+ ================================================================================
87
+ 8. RESPONSIBLE USE
88
+ ================================================================================
89
+ You are responsible for ensuring your use of the Software complies with all
90
+ applicable laws, the terms of service of any site you interact with, and
91
+ applicable anti-fraud and computer-access statutes. The copyright holder does
92
+ not endorse using the Software to violate any third party's terms or rights.
93
+
94
+ ================================================================================
95
+ 9. COMMERCIAL LICENSING
96
+ ================================================================================
97
+ For uses prohibited under Section 3 — including selling captcha-solving as a
98
+ service — contact the copyright holder to discuss a separate commercial license.
99
+
100
+ --------------------------------------------------------------------------------
101
+ This text is a license, not legal advice. If the boundary between a permitted
102
+ "value-add" product and a prohibited "thin wrapper" is unclear for your use
103
+ case, ask by opening an issue or messaging the maintainer on GitHub:
104
+ https://github.com/JWriter20/CaptchaKraken
105
+ --------------------------------------------------------------------------------
package/README.md CHANGED
@@ -51,4 +51,6 @@ Puppeteer users wrap the page once with `fromPuppeteer(page)`.
51
51
 
52
52
  ## License
53
53
 
54
- GPL-3.0-or-later.
54
+ **CaptchaKraken Source-Available License v1.0** — see [LICENSE](./LICENSE).
55
+ Build *with* it (scrapers, stealth browsers, QA tooling); you may **not sell the
56
+ solve itself** or ship a thin wrapper (browser extension, hosted solving API).
@@ -42,6 +42,8 @@ export interface PlaywrightElementHandle {
42
42
  /** Screenshot just this element to a PNG file (the only option the solver passes). */
43
43
  screenshot(options?: {
44
44
  path?: string;
45
+ timeout?: number;
46
+ animations?: 'disabled' | 'allow';
45
47
  }): Promise<Buffer>;
46
48
  /** The content document of an `<iframe>` element handle, or null if not a frame. */
47
49
  contentFrame(): Promise<PlaywrightFrame | null>;
package/dist/solver.d.ts CHANGED
@@ -15,6 +15,9 @@ export declare class CaptchaKrakenSolver {
15
15
  private cvWorkerPending;
16
16
  private cvWorkerBuf;
17
17
  private solutionCache;
18
+ private state;
19
+ private lastSubmitFrameHash;
20
+ private solveSessionId;
18
21
  constructor(config?: CaptchaKrakenConfig);
19
22
  solve(page: Page): Promise<SolveResult | void>;
20
23
  private solveImpl;
@@ -245,6 +248,70 @@ export declare class CaptchaKrakenSolver {
245
248
  */
246
249
  private solveRecaptchaGrid;
247
250
  private getSolution;
251
+ /**
252
+ * Query the model for `initialShot`, then guard against the captcha frame
253
+ * having changed DURING inference. reCAPTCHA/hCaptcha fade fresh tiles in over
254
+ * ~1s; if new imagery painted while the model was generating, its answer
255
+ * targets a stale ("undeveloped") frame and its tile picks / bboxes no longer
256
+ * line up with what's on screen. After the model returns we re-screenshot the
257
+ * element and diff it against the frame we sent (reusing the `check-movement`
258
+ * primitive); if it moved beyond the threshold we discard the answer and
259
+ * re-solve on the fresh frame, up to `maxStaleFrameReSolves` times, then act on
260
+ * the latest answer rather than spin.
261
+ *
262
+ * `runQuery` performs the actual model call for a given screenshot path (the
263
+ * caller wraps it in idle-wander where appropriate); it is re-invoked with the
264
+ * fresh path on each re-solve. Token usage from every query — including
265
+ * discarded ones — is accumulated, since those tokens were really spent. The
266
+ * caller owns `initialShot`; every fresh frame captured here is created and
267
+ * cleaned up here. Best-effort: a screenshot/diff failure falls through to the
268
+ * answer already in hand.
269
+ */
270
+ private solveFrameFreshnessGuarded;
271
+ /**
272
+ * Screenshot the captcha element to a throwaway temp frame and diff it against
273
+ * `priorPath` (the frame we sent the model). Returns true when the frame
274
+ * changed beyond `threshold` — i.e. tiles faded in / refreshed since. Reuses
275
+ * the persistent CV worker's `check-movement` (falling back to a one-shot
276
+ * subprocess), the same frame-diff the settle detectors use. Cleans up its own
277
+ * temp frame. Best-effort: any screenshot/diff failure returns false so the
278
+ * caller acts on the answer it already has rather than spinning.
279
+ */
280
+ private captchaFrameChangedSince;
281
+ /** Record a challenge-state transition. No-op for behaviour; logs the change
282
+ * (via gridDebug, so only when CAPTCHA_DEBUG=1) for offline diagnosis. */
283
+ private setState;
284
+ /**
285
+ * Screenshot the challenge element to a throwaway file and return its sha1
286
+ * content hash (or null on failure). Used to tell whether the frame has
287
+ * changed (e.g. the post-submit transition to the next round). Cleans up.
288
+ */
289
+ private elementFrameHash;
290
+ /**
291
+ * Monitor the challenge element until its pixels stop changing (settled), or
292
+ * until it's clear it never will (animated / video). Polls screenshots and
293
+ * diffs consecutive frames with `check-movement` (the persistent CV worker).
294
+ * Returns:
295
+ * 'settled' — `settleFrames` consecutive frame-pairs showed no movement;
296
+ * safe to screenshot for the model.
297
+ * 'animated' — it kept moving right up to `animatedChallengeAfterMs` without
298
+ * ever settling → very likely a video/animated puzzle.
299
+ * 'timeout' — neither happened within `settleTimeoutMs` (proceed best-effort).
300
+ *
301
+ * Note this is a *pixel* settle; the caller pairs it with the DOM-level
302
+ * `waitForHcaptchaChallengeImages` so a static loading frame (spinner on grey,
303
+ * below the pixel threshold) isn't mistaken for painted tiles. Cleans up.
304
+ */
305
+ private waitForElementSettled;
306
+ /**
307
+ * After a submit we EXPECT the challenge frame to change (advance to the next
308
+ * round, or close because it was accepted). Poll until the element's content
309
+ * hash differs from `sinceHash` — the transition beginning — so we never
310
+ * screenshot/solve the pre-transition frame again. Returns true once it
311
+ * changed, false if it never changed within `postSubmitChangeTimeoutMs` (e.g.
312
+ * it was already the final state). Best-effort.
313
+ */
314
+ private waitForChangeSince;
248
315
  /**
249
316
  * Run `fn` (typically the model query) while idly drifting the cursor over
250
317
  * the captcha, so the mouse behaves like a human weighing the options instead