Spaces:
Paused
Paused
File size: 1,325 Bytes
488aedf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /**
* Captcha solver worker entry.
*
* Runs the happy-dom solver (captcha-happy.ts) inside a worker thread so the
* proxy's main event loop NEVER blocks on Atomics.wait sync XHRs. One solve
* per worker at a time: the module's global browser-frame/cookie state is
* per-worker, which also removes the cross-solve global races of in-process
* parallel solving.
*
* Protocol: {id, scene, region, prefix} in -> {id, ok, param|error} out.
* Spawned by captcha-worker-dispatch.ts via the captcha-worker-asset.ts
* file asset (`with { type: "file" }`) -- the only worker mechanism that
* survives `bun build --compile` single-file binaries (verified on Bun 1.4).
*/
import { parentPort } from "node:worker_threads";
import { solveTraceless } from "./captcha-happy.js";
type SolveMsg = { id: number; scene: string; region: string; prefix: string };
const port = parentPort;
if (!port) throw new Error("captcha worker entry requires a worker_threads parent");
port.on("message", (m: SolveMsg) => {
void (async () => {
try {
const param = await solveTraceless({ scene: m.scene, region: m.region, prefix: m.prefix });
port.postMessage({ id: m.id, ok: true, param });
} catch (err) {
port.postMessage({ id: m.id, ok: false, error: String((err as Error)?.message ?? err) });
}
})();
});
|