@xbrowser/cli 1.34.0 → 1.35.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/{browser-GXL6V2JW.js → browser-KY7AIRAB.js} +3 -2
- package/dist/{browser-ZWEJ663M.js → browser-MLKP72XP.js} +3 -3
- package/dist/{browser-X7LO42UI.js → browser-RZ7DPBI3.js} +3 -3
- package/dist/cdp-driver-CCG3OJUQ.js +49 -0
- package/dist/{cdp-driver-GCFEMRFJ.js → cdp-driver-HBMCD7NU.js} +2 -2
- package/dist/{cdp-driver-QOUSRPR2.js → cdp-driver-MJD7YIQI.js} +2 -2
- package/dist/{cdp-driver-4MNHDU2J.js → cdp-driver-YJU4GRSV.js} +196 -95
- package/dist/chunk-3SZTCI33.js +147 -0
- package/dist/{chunk-DZ6XEPAH.js → chunk-43U5VDLB.js} +8 -2
- package/dist/chunk-53VZHESL.js +150 -0
- package/dist/{chunk-NAIHOVDZ.js → chunk-63526WET.js} +2 -8
- package/dist/{chunk-YIL44YDX.js → chunk-6DS3T6UK.js} +196 -95
- package/dist/{chunk-N7DFS4V7.js → chunk-BLCBCESM.js} +8 -2
- package/dist/{chunk-SH6OTPXN.js → chunk-C5ZPXPD7.js} +31 -7
- package/dist/chunk-EGOWDZXP.js +149 -0
- package/dist/chunk-GNLZWHSP.js +1380 -0
- package/dist/{chunk-3E6VVMK2.js → chunk-GYGVHWG3.js} +272 -1460
- package/dist/{chunk-2KPI5GKP.js → chunk-IYCB2KJL.js} +2 -8
- package/dist/chunk-JYYKMSFH.js +39 -0
- package/dist/{chunk-TBJUSUKF.js → chunk-NBT2CE3H.js} +140 -96
- package/dist/{chunk-J4NOL5XX.js → chunk-QRFM4NOV.js} +1025 -202
- package/dist/chunk-RGL2YTWQ.js +64 -0
- package/dist/{chunk-BND5O5KC.js → chunk-SQLICOPZ.js} +177 -240
- package/dist/{chunk-O5PASNI7.js → chunk-UUW5EGES.js} +139 -237
- package/dist/{chunk-43TEMG4U.js → chunk-WGS3Y6ZV.js} +3 -1
- package/dist/{chunk-R57Z5KZX.js → chunk-Y2GRCINH.js} +1004 -183
- package/dist/{chunk-R7AG7ONI.js → chunk-ZCZELQCS.js} +196 -95
- package/dist/cli.js +2237 -278
- package/dist/{daemon-client-7D6EZNOE.js → daemon-client-OXKRGLPQ.js} +32 -8
- package/dist/{daemon-client-HEGAXWGK.js → daemon-client-Z3NKNZRL.js} +5 -1
- package/dist/daemon-main.js +2214 -159
- package/dist/human-interaction-BGAZC3JR.js +12 -0
- package/dist/human-interaction-TPKPEE7A.js +11 -0
- package/dist/human-interaction-ZSD3IX6Q.js +12 -0
- package/dist/index.d.ts +225 -94
- package/dist/index.js +2880 -267
- package/dist/{launcher-TOLF23ET.js → launcher-AUJK5QQM.js} +1 -1
- package/dist/{launcher-ZYB32LSZ.js → launcher-QBAZ6F5L.js} +1 -1
- package/dist/mistake-ledger-2B4N54CO.js +29 -0
- package/dist/{recovery-ORHJSBDN.js → recovery-5AGY7CV3.js} +4 -5
- package/dist/{recovery-JFGV3DBX.js → recovery-7NRRHLS4.js} +4 -4
- package/dist/{recovery-XDKN63O5.js → recovery-TIBRFGRP.js} +4 -4
- package/dist/run-routes-SJKVZ34L.js +26 -0
- package/dist/run-routes-TFNV5BBR.js +24 -0
- package/dist/{server-5U56MQD2.js → server-HUSX7EFE.js} +5 -4
- package/dist/{server-R4OYD7ZC.js → server-KSP5H4HD.js} +5 -3
- package/dist/{session-replayer-GHEFFNGV.js → session-replayer-4TCLQI76.js} +1 -1
- package/dist/viewer-routes-YOS5GTCV.js +11 -0
- package/package.json +1 -1
- package/dist/chunk-QCV2PI7U.js +0 -184
- package/dist/human-interaction-ISMMOJOK.js +0 -8
- package/dist/human-interaction-STTZZZ5N.js +0 -8
- package/dist/human-interaction-UXFYV7DU.js +0 -8
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/cli/output.ts
|
|
2
|
+
import { outputFormatter, OutputFormatter } from "@dyyz1993/xcli-core";
|
|
3
|
+
var formatter = new OutputFormatter();
|
|
4
|
+
function outputResult(result, mode = "text") {
|
|
5
|
+
if (mode !== "json" && mode !== "yaml" && typeof result === "object" && result !== null) {
|
|
6
|
+
const r = result;
|
|
7
|
+
if (r.success === false) {
|
|
8
|
+
outputError(r.message ? String(r.message) : "Unknown error");
|
|
9
|
+
}
|
|
10
|
+
if (r.ok === false) {
|
|
11
|
+
outputError(r.error ? String(r.error) : "Unknown error");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const output = outputFormatter.format(result, {
|
|
15
|
+
mode,
|
|
16
|
+
color: mode === "text",
|
|
17
|
+
emoji: false
|
|
18
|
+
});
|
|
19
|
+
console.log(output);
|
|
20
|
+
}
|
|
21
|
+
function outputError(message) {
|
|
22
|
+
const formatted = formatter.formatError(message, { color: true, emoji: false });
|
|
23
|
+
console.error(formatted);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
}
|
|
26
|
+
function outputEnvelope(result, meta, mode) {
|
|
27
|
+
if (mode !== "json" && mode !== "yaml") {
|
|
28
|
+
if (!result.success) {
|
|
29
|
+
outputError(result.message || "Unknown error");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
outputResult(result.data, mode);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const { command, ...extraMeta } = meta;
|
|
36
|
+
const commandResult = {
|
|
37
|
+
success: result.success,
|
|
38
|
+
data: result.data,
|
|
39
|
+
message: result.message,
|
|
40
|
+
tips: [],
|
|
41
|
+
meta: {
|
|
42
|
+
duration: result.duration ?? 0,
|
|
43
|
+
...extraMeta
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const formatted = outputFormatter.formatEnvelope(commandResult, {
|
|
47
|
+
command,
|
|
48
|
+
extraMeta,
|
|
49
|
+
mode
|
|
50
|
+
});
|
|
51
|
+
console.log(formatted);
|
|
52
|
+
if (result.tips?.length) {
|
|
53
|
+
for (const tip of result.tips) {
|
|
54
|
+
const text = typeof tip === "string" ? tip : tip.message;
|
|
55
|
+
if (text) console.error(` \u{1F4A1} ${text}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export {
|
|
61
|
+
outputResult,
|
|
62
|
+
outputError,
|
|
63
|
+
outputEnvelope
|
|
64
|
+
};
|
|
@@ -1,152 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getCaptchaConfig
|
|
3
|
-
} from "./chunk-ZTHE5RBZ.js";
|
|
4
|
-
|
|
5
1
|
// src/human-interaction.ts
|
|
6
2
|
import { execFile } from "child_process";
|
|
7
3
|
|
|
8
|
-
// src/screencast.ts
|
|
9
|
-
var ScreencastCapturer = class {
|
|
10
|
-
interval;
|
|
11
|
-
quality;
|
|
12
|
-
type;
|
|
13
|
-
maxWidth;
|
|
14
|
-
maxHeight;
|
|
15
|
-
isCapturing = false;
|
|
16
|
-
frameCallback = null;
|
|
17
|
-
// CDP Cast state
|
|
18
|
-
cdpSession = null;
|
|
19
|
-
sessionId = "";
|
|
20
|
-
// Fallback polling state
|
|
21
|
-
fallbackTimer = null;
|
|
22
|
-
constructor(options = {}) {
|
|
23
|
-
this.interval = options.interval || 100;
|
|
24
|
-
this.quality = options.quality || 60;
|
|
25
|
-
this.type = options.type || "jpeg";
|
|
26
|
-
this.maxWidth = options.width || 1920;
|
|
27
|
-
this.maxHeight = options.height || 1080;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Start screencast capture using CDP Page.startScreencast.
|
|
31
|
-
*
|
|
32
|
-
* If CDP session creation fails (non-Chromium, restricted access),
|
|
33
|
-
* automatically falls back to `page.screenshot()` polling.
|
|
34
|
-
*/
|
|
35
|
-
async startCapture(page, sessionId, onFrame) {
|
|
36
|
-
if (this.isCapturing) {
|
|
37
|
-
throw new Error("Screencast is already capturing");
|
|
38
|
-
}
|
|
39
|
-
this.isCapturing = true;
|
|
40
|
-
this.frameCallback = onFrame;
|
|
41
|
-
this.sessionId = sessionId;
|
|
42
|
-
try {
|
|
43
|
-
const cdp = await page.context().newCDPSession(page);
|
|
44
|
-
this.cdpSession = cdp;
|
|
45
|
-
cdp.on("Page.screencastFrame", async (params) => {
|
|
46
|
-
const cb = this.frameCallback;
|
|
47
|
-
if (!cb) return;
|
|
48
|
-
cdp.send("Page.screencastFrameAck", { sessionId: params.sessionId }).catch(() => {
|
|
49
|
-
});
|
|
50
|
-
const logicalViewport = page.viewportSize();
|
|
51
|
-
const viewport = logicalViewport ?? {
|
|
52
|
-
width: params.metadata?.deviceWidth || this.maxWidth,
|
|
53
|
-
height: params.metadata?.deviceHeight || this.maxHeight
|
|
54
|
-
};
|
|
55
|
-
cb({
|
|
56
|
-
id: crypto.randomUUID(),
|
|
57
|
-
sessionId: this.sessionId,
|
|
58
|
-
timestamp: Date.now(),
|
|
59
|
-
data: Buffer.from(params.data, "base64"),
|
|
60
|
-
url: page.url(),
|
|
61
|
-
viewport
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
await cdp.send("Page.startScreencast", {
|
|
65
|
-
format: this.type === "png" ? "png" : "jpeg",
|
|
66
|
-
quality: this.type === "jpeg" ? this.quality : void 0,
|
|
67
|
-
maxWidth: this.maxWidth,
|
|
68
|
-
maxHeight: this.maxHeight
|
|
69
|
-
});
|
|
70
|
-
} catch {
|
|
71
|
-
this.cdpSession = null;
|
|
72
|
-
this.startFallbackPolling(page, sessionId);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Fallback: periodic page.screenshot() polling when CDP Cast is unavailable.
|
|
77
|
-
*/
|
|
78
|
-
startFallbackPolling(page, sessionId) {
|
|
79
|
-
const captureLoop = async () => {
|
|
80
|
-
if (!this.frameCallback) return;
|
|
81
|
-
try {
|
|
82
|
-
const frame = await this.captureFrame(page, sessionId);
|
|
83
|
-
this.frameCallback(frame);
|
|
84
|
-
} catch {
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
captureLoop();
|
|
88
|
-
this.fallbackTimer = setInterval(captureLoop, this.interval);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Capture a single screenshot frame from the page (fallback mode).
|
|
92
|
-
*/
|
|
93
|
-
async captureFrame(page, sessionId) {
|
|
94
|
-
let viewport = page.viewportSize();
|
|
95
|
-
if (!viewport) {
|
|
96
|
-
try {
|
|
97
|
-
viewport = await page.evaluate(() => ({ width: window.innerWidth, height: window.innerHeight }));
|
|
98
|
-
} catch {
|
|
99
|
-
viewport = { width: 1920, height: 1080 };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
const screenshot = await page.screenshot({
|
|
103
|
-
type: this.type,
|
|
104
|
-
quality: this.type === "jpeg" ? this.quality : void 0
|
|
105
|
-
});
|
|
106
|
-
return {
|
|
107
|
-
id: crypto.randomUUID(),
|
|
108
|
-
sessionId,
|
|
109
|
-
timestamp: Date.now(),
|
|
110
|
-
data: screenshot,
|
|
111
|
-
url: page.url(),
|
|
112
|
-
viewport: viewport || { width: 0, height: 0 }
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Stop the current screencast capture.
|
|
117
|
-
*/
|
|
118
|
-
async stopCapture() {
|
|
119
|
-
if (this.cdpSession) {
|
|
120
|
-
try {
|
|
121
|
-
this.cdpSession.off("Page.screencastFrame", () => {
|
|
122
|
-
});
|
|
123
|
-
await this.cdpSession.send("Page.stopScreencast");
|
|
124
|
-
} catch {
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
await this.cdpSession.detach();
|
|
128
|
-
} catch {
|
|
129
|
-
}
|
|
130
|
-
this.cdpSession = null;
|
|
131
|
-
}
|
|
132
|
-
if (this.fallbackTimer) {
|
|
133
|
-
clearInterval(this.fallbackTimer);
|
|
134
|
-
this.fallbackTimer = null;
|
|
135
|
-
}
|
|
136
|
-
this.isCapturing = false;
|
|
137
|
-
this.frameCallback = null;
|
|
138
|
-
}
|
|
139
|
-
isActive() {
|
|
140
|
-
return this.isCapturing;
|
|
141
|
-
}
|
|
142
|
-
setInterval(interval) {
|
|
143
|
-
this.interval = interval;
|
|
144
|
-
}
|
|
145
|
-
setQuality(quality) {
|
|
146
|
-
this.quality = quality;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
|
|
150
4
|
// src/captcha-detector.ts
|
|
151
5
|
var CAPTCHA_SELECTORS = [
|
|
152
6
|
{ selector: 'iframe[src*="recaptcha"]', type: "recaptcha", confidence: "high" },
|
|
@@ -317,28 +171,90 @@ var WebhookNotifier = class {
|
|
|
317
171
|
}
|
|
318
172
|
};
|
|
319
173
|
|
|
174
|
+
// src/config.ts
|
|
175
|
+
import { homedir, tmpdir } from "os";
|
|
176
|
+
import { join } from "path";
|
|
177
|
+
import { loadConfig as coreLoadConfig, saveConfig as coreSaveConfig } from "@dyyz1993/xcli-core";
|
|
178
|
+
function getConfigSource() {
|
|
179
|
+
return { configDir: join(homedir() || tmpdir(), ".xbrowser") };
|
|
180
|
+
}
|
|
181
|
+
function loadConfig() {
|
|
182
|
+
return coreLoadConfig(getConfigSource());
|
|
183
|
+
}
|
|
184
|
+
function getConfigValue(key) {
|
|
185
|
+
const parts = key.split(".");
|
|
186
|
+
let obj = loadConfig();
|
|
187
|
+
for (const part of parts) {
|
|
188
|
+
if (obj && typeof obj === "object") {
|
|
189
|
+
obj = obj[part];
|
|
190
|
+
} else {
|
|
191
|
+
return void 0;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return obj;
|
|
195
|
+
}
|
|
196
|
+
function getCaptchaConfig() {
|
|
197
|
+
const config = loadConfig();
|
|
198
|
+
return {
|
|
199
|
+
notifyUrl: process.env.XBROWSER_NOTIFY_URL || config.captcha?.notifyUrl,
|
|
200
|
+
autoOpen: process.env.XBROWSER_AUTO_OPEN === "true" || config.captcha?.autoOpen === true,
|
|
201
|
+
timeout: parseInt(process.env.XBROWSER_CAPTCHA_TIMEOUT || "") || config.captcha?.timeout || 120,
|
|
202
|
+
previewPort: parseInt(process.env.XBROWSER_PREVIEW_PORT || "") || config.preview?.port || 9223
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function resolveScreenshotsDir() {
|
|
206
|
+
const configured = getConfigValue("screenshots.dir");
|
|
207
|
+
if (typeof configured === "string" && configured.trim()) return configured.trim();
|
|
208
|
+
return join(tmpdir(), "xbrowser", "screenshots");
|
|
209
|
+
}
|
|
210
|
+
|
|
320
211
|
// src/human-interaction.ts
|
|
212
|
+
var DEFAULT_HUMAN_INTERACTION_SESSION = "default";
|
|
213
|
+
var activeWaitsByServer = /* @__PURE__ */ new WeakMap();
|
|
214
|
+
function acquireWaitSlot(server, sessionName) {
|
|
215
|
+
let sessions = activeWaitsByServer.get(server);
|
|
216
|
+
if (!sessions) {
|
|
217
|
+
sessions = /* @__PURE__ */ new Map();
|
|
218
|
+
activeWaitsByServer.set(server, sessions);
|
|
219
|
+
}
|
|
220
|
+
if (sessions.has(sessionName)) return false;
|
|
221
|
+
sessions.set(sessionName, "starting");
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
function releaseWaitSlot(server, sessionName) {
|
|
225
|
+
activeWaitsByServer.get(server)?.delete(sessionName);
|
|
226
|
+
}
|
|
227
|
+
function isHumanWaitActive(server, sessionName) {
|
|
228
|
+
return activeWaitsByServer.get(server)?.get(sessionName) === "waiting";
|
|
229
|
+
}
|
|
321
230
|
var HumanInteractionManager = class {
|
|
322
231
|
wsServer;
|
|
323
232
|
page;
|
|
324
|
-
|
|
233
|
+
sessionName;
|
|
325
234
|
webhook;
|
|
326
235
|
autoOpen;
|
|
327
|
-
constructor(wsServer, page) {
|
|
236
|
+
constructor(wsServer, page, sessionName) {
|
|
328
237
|
this.wsServer = wsServer;
|
|
329
238
|
this.page = page;
|
|
330
|
-
this.
|
|
239
|
+
this.sessionName = sessionName && sessionName.trim() ? sessionName.trim() : DEFAULT_HUMAN_INTERACTION_SESSION;
|
|
331
240
|
const cfg = getCaptchaConfig();
|
|
332
241
|
this.webhook = new WebhookNotifier(cfg.notifyUrl);
|
|
333
242
|
this.autoOpen = cfg.autoOpen;
|
|
334
|
-
this.wsServer.registerSession(
|
|
243
|
+
this.wsServer.registerSession(this.sessionName, page);
|
|
244
|
+
}
|
|
245
|
+
/** The named session this manager interacts with. */
|
|
246
|
+
get session() {
|
|
247
|
+
return this.sessionName;
|
|
248
|
+
}
|
|
249
|
+
buildPreviewUrl() {
|
|
250
|
+
return `http://localhost:${this.wsServer.getPort()}/preview/${encodeURIComponent(this.sessionName)}`;
|
|
335
251
|
}
|
|
336
252
|
async sendWebhook(event, overrides = {}) {
|
|
337
253
|
await this.webhook.notify({
|
|
338
254
|
event,
|
|
339
255
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
340
256
|
url: this.page.url(),
|
|
341
|
-
previewUrl:
|
|
257
|
+
previewUrl: this.buildPreviewUrl(),
|
|
342
258
|
...overrides
|
|
343
259
|
});
|
|
344
260
|
}
|
|
@@ -355,11 +271,16 @@ var HumanInteractionManager = class {
|
|
|
355
271
|
/**
|
|
356
272
|
* Wait for a human to solve a CAPTCHA or complete an interaction.
|
|
357
273
|
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
274
|
+
* Sends session-scoped notifications and waits for CAPTCHA resolution
|
|
275
|
+
* or a manual solve signal from a viewer bound to this session.
|
|
276
|
+
*
|
|
277
|
+
* Only one wait may be in flight per session per WSServer. The wait
|
|
278
|
+
* slot, listener, and timers are cleaned
|
|
279
|
+
* up on every exit path (auto-detected / preview / timeout / error).
|
|
360
280
|
*
|
|
361
281
|
* @param options - Configuration for timeout, auto-detection, and reason text.
|
|
362
282
|
* @returns Result indicating whether the CAPTCHA was solved and by what method.
|
|
283
|
+
* @throws If a wait is already in progress for this session.
|
|
363
284
|
*/
|
|
364
285
|
async waitForHuman(options = {}) {
|
|
365
286
|
const {
|
|
@@ -368,102 +289,118 @@ var HumanInteractionManager = class {
|
|
|
368
289
|
autoDetect = true,
|
|
369
290
|
detectInterval = 2e3
|
|
370
291
|
} = options;
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
url: frame.url,
|
|
382
|
-
viewport: frame.viewport
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
});
|
|
386
|
-
const previewUrl = `http://localhost:${this.wsServer.getPort()}`;
|
|
387
|
-
await this.sendWebhook("captcha-detected", {
|
|
388
|
-
reason: captchaInfo ? `${captchaInfo.type ?? "unknown"} CAPTCHA detected` : reason,
|
|
389
|
-
timeout,
|
|
390
|
-
targetUrl: this.page.url()
|
|
391
|
-
});
|
|
392
|
-
this.wsServer.broadcast({
|
|
393
|
-
type: "captcha-detected",
|
|
394
|
-
sessionId: "default",
|
|
395
|
-
url: this.page.url(),
|
|
396
|
-
reason: captchaInfo ? `${captchaInfo.type ?? "unknown"} CAPTCHA detected` : reason,
|
|
397
|
-
timeout
|
|
398
|
-
});
|
|
399
|
-
this.tryAutoOpen(previewUrl);
|
|
400
|
-
console.log("");
|
|
401
|
-
console.log("\u26A0\uFE0F \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
402
|
-
console.log(`\u26A0\uFE0F ${captchaInfo ? (captchaInfo.type ?? "UNKNOWN").toUpperCase() + " CAPTCHA" : "INTERACTION"} REQUIRED`);
|
|
403
|
-
console.log(`\u26A0\uFE0F URL: ${this.page.url()}`);
|
|
404
|
-
console.log(`\u26A0\uFE0F `);
|
|
405
|
-
console.log(`\u26A0\uFE0F Solve via:`);
|
|
406
|
-
console.log(`\u26A0\uFE0F \u{1F4FA} Preview: ${previewUrl}`);
|
|
407
|
-
console.log(`\u26A0\uFE0F \u{1F310} Direct: ${this.page.url()}`);
|
|
408
|
-
console.log(`\u26A0\uFE0F \u23ED\uFE0F Skip`);
|
|
409
|
-
console.log(`\u26A0\uFE0F \u274C Abort`);
|
|
410
|
-
console.log(`\u26A0\uFE0F `);
|
|
411
|
-
console.log(`\u26A0\uFE0F \u23F3 Waiting... (${timeout}s timeout)`);
|
|
412
|
-
console.log("\u26A0\uFE0F \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
413
|
-
console.log("");
|
|
414
|
-
return new Promise((resolve) => {
|
|
415
|
-
let resolved = false;
|
|
416
|
-
let pollTimer = null;
|
|
417
|
-
let timeoutTimer = null;
|
|
418
|
-
const cleanup = () => {
|
|
419
|
-
if (pollTimer) clearInterval(pollTimer);
|
|
420
|
-
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
421
|
-
this.wsServer.removeListener("human-solved", onHumanSolved);
|
|
422
|
-
this.capturer.stopCapture();
|
|
423
|
-
};
|
|
424
|
-
if (autoDetect && captchaInfo) {
|
|
425
|
-
pollTimer = setInterval(async () => {
|
|
426
|
-
if (resolved) return;
|
|
427
|
-
try {
|
|
428
|
-
const solved = await CaptchaDetector.isSolved(this.page, captchaInfo.selector);
|
|
429
|
-
if (solved) {
|
|
430
|
-
resolved = true;
|
|
431
|
-
cleanup();
|
|
432
|
-
this.wsServer.broadcast({ type: "resolved", sessionId: "default" });
|
|
433
|
-
console.log("\u2705 CAPTCHA auto-detected as solved!");
|
|
434
|
-
this.sendWebhook("captcha-resolved", { reason: "auto-detected" });
|
|
435
|
-
resolve({ solved: true, method: "auto-detected" });
|
|
436
|
-
}
|
|
437
|
-
} catch {
|
|
438
|
-
}
|
|
439
|
-
}, detectInterval);
|
|
292
|
+
if (!acquireWaitSlot(this.wsServer, this.sessionName)) {
|
|
293
|
+
throw new Error(
|
|
294
|
+
`waitForHuman already in progress for session "${this.sessionName}" \u2014 only one human-interaction wait per session is allowed`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
let slotReleased = false;
|
|
298
|
+
const releaseSlot = () => {
|
|
299
|
+
if (!slotReleased) {
|
|
300
|
+
slotReleased = true;
|
|
301
|
+
releaseWaitSlot(this.wsServer, this.sessionName);
|
|
440
302
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
303
|
+
};
|
|
304
|
+
try {
|
|
305
|
+
const captcha = await CaptchaDetector.detect(this.page);
|
|
306
|
+
const captchaInfo = captcha.detected ? captcha : void 0;
|
|
307
|
+
const previewUrl = this.buildPreviewUrl();
|
|
308
|
+
const waitReason = captchaInfo ? `${captchaInfo.type ?? "unknown"} CAPTCHA detected` : reason;
|
|
309
|
+
console.log("");
|
|
310
|
+
console.log("\u26A0\uFE0F \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
311
|
+
console.log(`\u26A0\uFE0F ${captchaInfo ? (captchaInfo.type ?? "UNKNOWN").toUpperCase() + " CAPTCHA" : "INTERACTION"} REQUIRED (session: ${this.sessionName})`);
|
|
312
|
+
console.log(`\u26A0\uFE0F URL: ${this.page.url()}`);
|
|
313
|
+
console.log(`\u26A0\uFE0F `);
|
|
314
|
+
console.log(`\u26A0\uFE0F Solve via:`);
|
|
315
|
+
console.log(`\u26A0\uFE0F \u{1F4FA} Preview: ${previewUrl}`);
|
|
316
|
+
console.log(`\u26A0\uFE0F \u{1F310} Direct: ${this.page.url()}`);
|
|
317
|
+
console.log(`\u26A0\uFE0F \u23ED\uFE0F Skip`);
|
|
318
|
+
console.log(`\u26A0\uFE0F \u274C Abort`);
|
|
319
|
+
console.log(`\u26A0\uFE0F `);
|
|
320
|
+
console.log(`\u26A0\uFE0F \u23F3 Waiting... (${timeout}s timeout)`);
|
|
321
|
+
console.log("\u26A0\uFE0F \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550");
|
|
322
|
+
console.log("");
|
|
323
|
+
return await new Promise((resolve) => {
|
|
324
|
+
let resolved = false;
|
|
325
|
+
let pollTimer = null;
|
|
326
|
+
let timeoutTimer = null;
|
|
327
|
+
const cleanup = () => {
|
|
328
|
+
if (pollTimer) clearInterval(pollTimer);
|
|
329
|
+
if (timeoutTimer) clearTimeout(timeoutTimer);
|
|
330
|
+
this.wsServer.removeListener("human-solved", onHumanSolved);
|
|
331
|
+
releaseSlot();
|
|
332
|
+
};
|
|
333
|
+
if (autoDetect && captchaInfo) {
|
|
334
|
+
pollTimer = setInterval(async () => {
|
|
335
|
+
if (resolved) return;
|
|
336
|
+
try {
|
|
337
|
+
const solved = await CaptchaDetector.isSolved(this.page, captchaInfo.selector);
|
|
338
|
+
if (solved && !resolved) {
|
|
339
|
+
resolved = true;
|
|
340
|
+
cleanup();
|
|
341
|
+
this.wsServer.broadcastToSession(this.sessionName, {
|
|
342
|
+
type: "resolved",
|
|
343
|
+
sessionId: this.sessionName
|
|
344
|
+
});
|
|
345
|
+
console.log("\u2705 CAPTCHA auto-detected as solved!");
|
|
346
|
+
this.sendWebhook("captcha-resolved", { reason: "auto-detected" });
|
|
347
|
+
resolve({ solved: true, method: "auto-detected" });
|
|
348
|
+
}
|
|
349
|
+
} catch {
|
|
350
|
+
}
|
|
351
|
+
}, detectInterval);
|
|
449
352
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
if (timeout > 0) {
|
|
453
|
-
timeoutTimer = setTimeout(() => {
|
|
353
|
+
const onHumanSolved = (payload) => {
|
|
354
|
+
if (!payload || payload.sessionId !== this.sessionName) return;
|
|
454
355
|
if (!resolved) {
|
|
455
356
|
resolved = true;
|
|
456
357
|
cleanup();
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
358
|
+
this.wsServer.broadcastToSession(this.sessionName, {
|
|
359
|
+
type: "resolved",
|
|
360
|
+
sessionId: this.sessionName
|
|
361
|
+
});
|
|
362
|
+
console.log("\u2705 CAPTCHA solved via preview!");
|
|
363
|
+
this.sendWebhook("captcha-resolved", { reason: "preview" });
|
|
364
|
+
resolve({ solved: true, method: "preview" });
|
|
460
365
|
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
366
|
+
};
|
|
367
|
+
this.wsServer.on("human-solved", onHumanSolved);
|
|
368
|
+
if (timeout > 0) {
|
|
369
|
+
timeoutTimer = setTimeout(() => {
|
|
370
|
+
if (!resolved) {
|
|
371
|
+
resolved = true;
|
|
372
|
+
cleanup();
|
|
373
|
+
this.wsServer.broadcastToSession(this.sessionName, {
|
|
374
|
+
type: "handoff-timeout",
|
|
375
|
+
sessionId: this.sessionName
|
|
376
|
+
});
|
|
377
|
+
console.log("\u23F0 Timeout - skipping");
|
|
378
|
+
this.sendWebhook("captcha-resolved", { reason: "timeout" });
|
|
379
|
+
resolve({ solved: false, method: "timeout" });
|
|
380
|
+
}
|
|
381
|
+
}, timeout * 1e3);
|
|
382
|
+
}
|
|
383
|
+
activeWaitsByServer.get(this.wsServer)?.set(this.sessionName, "waiting");
|
|
384
|
+
this.wsServer.broadcastToSession(this.sessionName, {
|
|
385
|
+
type: "captcha-detected",
|
|
386
|
+
sessionId: this.sessionName,
|
|
387
|
+
url: this.page.url(),
|
|
388
|
+
reason: waitReason,
|
|
389
|
+
timeout
|
|
390
|
+
});
|
|
391
|
+
void this.sendWebhook("captcha-detected", { reason: waitReason, timeout, targetUrl: this.page.url() });
|
|
392
|
+
this.tryAutoOpen(previewUrl);
|
|
393
|
+
});
|
|
394
|
+
} catch (err) {
|
|
395
|
+
releaseSlot();
|
|
396
|
+
throw err;
|
|
397
|
+
}
|
|
464
398
|
}
|
|
465
399
|
};
|
|
466
400
|
|
|
467
401
|
export {
|
|
402
|
+
resolveScreenshotsDir,
|
|
403
|
+
DEFAULT_HUMAN_INTERACTION_SESSION,
|
|
404
|
+
isHumanWaitActive,
|
|
468
405
|
HumanInteractionManager
|
|
469
406
|
};
|