@skrillex1224/playwright-toolkit 3.0.39 → 3.0.40
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.js +104 -38
- package/dist/browser.js.map +4 -4
- package/dist/index.cjs +282 -265
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +282 -265
- package/dist/index.js.map +4 -4
- package/index.d.ts +7 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -404,18 +404,18 @@ var fallbackLog = {
|
|
|
404
404
|
error: (...args) => console.error(...args),
|
|
405
405
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
406
406
|
};
|
|
407
|
-
var resolveLogMethod = (
|
|
408
|
-
if (
|
|
409
|
-
return
|
|
407
|
+
var resolveLogMethod = (logger18, name) => {
|
|
408
|
+
if (logger18 && typeof logger18[name] === "function") {
|
|
409
|
+
return logger18[name].bind(logger18);
|
|
410
410
|
}
|
|
411
|
-
if (name === "warning" &&
|
|
412
|
-
return
|
|
411
|
+
if (name === "warning" && logger18 && typeof logger18.warn === "function") {
|
|
412
|
+
return logger18.warn.bind(logger18);
|
|
413
413
|
}
|
|
414
414
|
return fallbackLog[name];
|
|
415
415
|
};
|
|
416
416
|
var defaultLogger = null;
|
|
417
|
-
var setDefaultLogger = (
|
|
418
|
-
defaultLogger =
|
|
417
|
+
var setDefaultLogger = (logger18) => {
|
|
418
|
+
defaultLogger = logger18;
|
|
419
419
|
};
|
|
420
420
|
var resolveLogger = (explicitLogger) => {
|
|
421
421
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -442,8 +442,8 @@ var colorize = (text, color) => {
|
|
|
442
442
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
443
443
|
const name = prefix ? String(prefix) : "";
|
|
444
444
|
const dispatch = (methodName, icon, message, color) => {
|
|
445
|
-
const
|
|
446
|
-
const logFn = resolveLogMethod(
|
|
445
|
+
const logger18 = resolveLogger(explicitLogger);
|
|
446
|
+
const logFn = resolveLogMethod(logger18, methodName);
|
|
447
447
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
448
448
|
const line = formatLine(name, icon, message);
|
|
449
449
|
const coloredLine = colorize(line, color);
|
|
@@ -1621,12 +1621,16 @@ var ProxyMeterRuntime = {
|
|
|
1621
1621
|
getProxyMeterSnapshot
|
|
1622
1622
|
};
|
|
1623
1623
|
|
|
1624
|
+
// src/runtime-env.js
|
|
1625
|
+
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
1626
|
+
|
|
1624
1627
|
// src/internals/constants.js
|
|
1625
1628
|
var PageRuntimeStateKey = "__playwright_toolkit_runtime_state__";
|
|
1626
1629
|
|
|
1627
1630
|
// src/runtime-env.js
|
|
1628
1631
|
var BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
1629
1632
|
var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
|
|
1633
|
+
var logger3 = createInternalLogger("RuntimeEnv");
|
|
1630
1634
|
var rememberedRuntimeState = null;
|
|
1631
1635
|
var isPlainObject = (value) => value && typeof value === "object" && !Array.isArray(value);
|
|
1632
1636
|
var normalizeKnownDevice = (value) => {
|
|
@@ -1783,6 +1787,18 @@ var uniqueStrings = (value) => {
|
|
|
1783
1787
|
});
|
|
1784
1788
|
return result;
|
|
1785
1789
|
};
|
|
1790
|
+
var buildApplyExcludeMatcher = (patterns = []) => {
|
|
1791
|
+
const normalized = (Array.isArray(patterns) ? patterns : []).map((pattern) => String(pattern || "").trim()).filter(Boolean);
|
|
1792
|
+
return normalized.length > 0 ? (0, import_picomatch.default)(normalized, { nocase: true }) : () => false;
|
|
1793
|
+
};
|
|
1794
|
+
var filterApplyEntries = (entries = {}, matcher = () => false) => Object.entries(entries || {}).reduce((acc, [key, value]) => {
|
|
1795
|
+
if (matcher(key)) acc.skipped.push(key);
|
|
1796
|
+
else acc.payload[key] = value;
|
|
1797
|
+
return acc;
|
|
1798
|
+
}, { payload: {}, skipped: [] });
|
|
1799
|
+
var logApplySkipped = (type, keys = []) => {
|
|
1800
|
+
if (keys.length > 0) logger3.info(`applyToPage \u8DF3\u8FC7\u6CE8\u5165 ${type}: ${keys.join(", ")}`);
|
|
1801
|
+
};
|
|
1786
1802
|
var normalizeHttpUrlList = (value) => uniqueStrings(
|
|
1787
1803
|
(Array.isArray(value) ? value : [value]).map((item) => normalizeHttpUrl(item)).filter(Boolean)
|
|
1788
1804
|
);
|
|
@@ -2254,9 +2270,24 @@ var RuntimeEnv = {
|
|
|
2254
2270
|
writable: true,
|
|
2255
2271
|
value: state2
|
|
2256
2272
|
});
|
|
2257
|
-
const
|
|
2258
|
-
const
|
|
2259
|
-
|
|
2273
|
+
const exclude = options?.exclude || {};
|
|
2274
|
+
const localStorageResult = filterApplyEntries(
|
|
2275
|
+
state2.localStorage || {},
|
|
2276
|
+
buildApplyExcludeMatcher(exclude.local_storage)
|
|
2277
|
+
);
|
|
2278
|
+
const sessionStorageResult = filterApplyEntries(
|
|
2279
|
+
state2.sessionStorage || {},
|
|
2280
|
+
buildApplyExcludeMatcher(exclude.session_storage)
|
|
2281
|
+
);
|
|
2282
|
+
const cookieMatcher = buildApplyExcludeMatcher(exclude.cookies);
|
|
2283
|
+
const skippedCookies = [];
|
|
2284
|
+
const localStorage = localStorageResult.payload;
|
|
2285
|
+
const sessionStorage = sessionStorageResult.payload;
|
|
2286
|
+
const cookies = (state2.cookies || []).filter((cookie) => {
|
|
2287
|
+
if (!cookieMatcher(cookie?.name)) return true;
|
|
2288
|
+
skippedCookies.push(cookie.name);
|
|
2289
|
+
return false;
|
|
2290
|
+
}).map((cookie) => {
|
|
2260
2291
|
const normalized = { ...cookie };
|
|
2261
2292
|
if (!normalized.path) {
|
|
2262
2293
|
normalized.path = "/";
|
|
@@ -2266,6 +2297,9 @@ var RuntimeEnv = {
|
|
|
2266
2297
|
}
|
|
2267
2298
|
return normalized;
|
|
2268
2299
|
}).filter(Boolean);
|
|
2300
|
+
logApplySkipped("cookies", skippedCookies);
|
|
2301
|
+
logApplySkipped("local_storage", localStorageResult.skipped);
|
|
2302
|
+
logApplySkipped("session_storage", sessionStorageResult.skipped);
|
|
2269
2303
|
if (cookies.length > 0) {
|
|
2270
2304
|
await page.context().addCookies(cookies);
|
|
2271
2305
|
}
|
|
@@ -2325,7 +2359,7 @@ var RuntimeEnv = {
|
|
|
2325
2359
|
};
|
|
2326
2360
|
|
|
2327
2361
|
// src/apify-kit.js
|
|
2328
|
-
var
|
|
2362
|
+
var logger4 = createInternalLogger("ApifyKit");
|
|
2329
2363
|
var hasFleetAtHomeFlag = () => String(process.env.FLEET_AT_HOME || "").trim() !== "";
|
|
2330
2364
|
var resolveRuntimeContext = (input) => {
|
|
2331
2365
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
@@ -2411,7 +2445,7 @@ var captureAutoEnvPatch = async (page, runtimeContext) => {
|
|
|
2411
2445
|
{ actor: runtimeContext.actor }
|
|
2412
2446
|
);
|
|
2413
2447
|
} catch (error) {
|
|
2414
|
-
|
|
2448
|
+
logger4.warn(`\u81EA\u52A8\u91C7\u96C6 env_patch \u5931\u8D25: ${error?.message || error}`);
|
|
2415
2449
|
return null;
|
|
2416
2450
|
}
|
|
2417
2451
|
};
|
|
@@ -2456,29 +2490,29 @@ async function createApifyKit() {
|
|
|
2456
2490
|
const { times: retryTimes = 0, mode: retryMode = "direct", before: beforeRetry } = retry;
|
|
2457
2491
|
const executeAction = async (attemptNumber) => {
|
|
2458
2492
|
const attemptLabel = attemptNumber > 0 ? ` (\u91CD\u8BD5 #${attemptNumber})` : "";
|
|
2459
|
-
|
|
2493
|
+
logger4.start(`[Step] ${step}${attemptLabel}`);
|
|
2460
2494
|
try {
|
|
2461
2495
|
const result = await actionFn();
|
|
2462
|
-
|
|
2496
|
+
logger4.success(`[Step] ${step}${attemptLabel}`);
|
|
2463
2497
|
return { success: true, result };
|
|
2464
2498
|
} catch (error) {
|
|
2465
|
-
|
|
2499
|
+
logger4.fail(`[Step] ${step}${attemptLabel}`, error);
|
|
2466
2500
|
return { success: false, error };
|
|
2467
2501
|
}
|
|
2468
2502
|
};
|
|
2469
2503
|
const prepareForRetry = async (attemptNumber) => {
|
|
2470
2504
|
if (typeof beforeRetry === "function") {
|
|
2471
|
-
|
|
2505
|
+
logger4.start(`[RetryStep] \u6267\u884C\u81EA\u5B9A\u4E49 before \u94A9\u5B50 (\u7B2C ${attemptNumber} \u6B21\u91CD\u8BD5)`);
|
|
2472
2506
|
await beforeRetry(page, attemptNumber);
|
|
2473
|
-
|
|
2507
|
+
logger4.success(`[RetryStep] before \u94A9\u5B50\u5B8C\u6210`);
|
|
2474
2508
|
} else if (retryMode === "refresh") {
|
|
2475
|
-
|
|
2509
|
+
logger4.start(`[RetryStep] \u5237\u65B0\u9875\u9762 (\u7B2C ${attemptNumber} \u6B21\u91CD\u8BD5)`);
|
|
2476
2510
|
await page.reload({ waitUntil: "commit" });
|
|
2477
|
-
|
|
2511
|
+
logger4.success(`[RetryStep] \u9875\u9762\u5237\u65B0\u5B8C\u6210`);
|
|
2478
2512
|
} else {
|
|
2479
|
-
|
|
2513
|
+
logger4.start(`[RetryStep] \u7B49\u5F85 3 \u79D2 (\u7B2C ${attemptNumber} \u6B21\u91CD\u8BD5)`);
|
|
2480
2514
|
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
2481
|
-
|
|
2515
|
+
logger4.success(`[RetryStep] \u7B49\u5F85\u5B8C\u6210`);
|
|
2482
2516
|
}
|
|
2483
2517
|
};
|
|
2484
2518
|
let lastResult = await executeAction(0);
|
|
@@ -2486,11 +2520,11 @@ async function createApifyKit() {
|
|
|
2486
2520
|
return lastResult.result;
|
|
2487
2521
|
}
|
|
2488
2522
|
for (let attempt = 1; attempt <= retryTimes; attempt++) {
|
|
2489
|
-
|
|
2523
|
+
logger4.start(`[RetryStep] \u51C6\u5907\u7B2C ${attempt}/${retryTimes} \u6B21\u91CD\u8BD5: ${step}`);
|
|
2490
2524
|
try {
|
|
2491
2525
|
await prepareForRetry(attempt);
|
|
2492
2526
|
} catch (prepareError) {
|
|
2493
|
-
|
|
2527
|
+
logger4.warn(`[RetryStep] \u91CD\u8BD5\u51C6\u5907\u5931\u8D25: ${prepareError.message}`);
|
|
2494
2528
|
continue;
|
|
2495
2529
|
}
|
|
2496
2530
|
lastResult = await executeAction(attempt);
|
|
@@ -2506,7 +2540,7 @@ async function createApifyKit() {
|
|
|
2506
2540
|
try {
|
|
2507
2541
|
html = await page.content();
|
|
2508
2542
|
} catch (htmlErr) {
|
|
2509
|
-
|
|
2543
|
+
logger4.warn(`HTML \u91C7\u96C6\u5931\u8D25: ${htmlErr.message}`);
|
|
2510
2544
|
}
|
|
2511
2545
|
}
|
|
2512
2546
|
try {
|
|
@@ -2519,7 +2553,7 @@ async function createApifyKit() {
|
|
|
2519
2553
|
base64 = `data:image/jpeg;base64,${buffer.toString("base64")}`;
|
|
2520
2554
|
}
|
|
2521
2555
|
} catch (snapErr) {
|
|
2522
|
-
|
|
2556
|
+
logger4.warn(`\u622A\u56FE\u751F\u6210\u5931\u8D25: ${snapErr.message}`);
|
|
2523
2557
|
}
|
|
2524
2558
|
await this.pushFailed(
|
|
2525
2559
|
finalError,
|
|
@@ -2592,7 +2626,7 @@ async function createApifyKit() {
|
|
|
2592
2626
|
await Actor2.pushData({
|
|
2593
2627
|
...payload
|
|
2594
2628
|
});
|
|
2595
|
-
|
|
2629
|
+
logger4.success("pushSuccess", "Data pushed");
|
|
2596
2630
|
},
|
|
2597
2631
|
/**
|
|
2598
2632
|
* 推送失败数据的通用方法(私有方法,仅供 runStep 内部使用)。
|
|
@@ -2633,7 +2667,7 @@ async function createApifyKit() {
|
|
|
2633
2667
|
await Actor2.pushData({
|
|
2634
2668
|
...payload
|
|
2635
2669
|
});
|
|
2636
|
-
|
|
2670
|
+
logger4.success("pushFailed", "Error data pushed");
|
|
2637
2671
|
}
|
|
2638
2672
|
};
|
|
2639
2673
|
}
|
|
@@ -2649,7 +2683,7 @@ var ApifyKit = {
|
|
|
2649
2683
|
};
|
|
2650
2684
|
|
|
2651
2685
|
// src/internals/utils.js
|
|
2652
|
-
var
|
|
2686
|
+
var logger5 = createInternalLogger("InternalUtils");
|
|
2653
2687
|
var parseCookies = (cookieString, domain) => {
|
|
2654
2688
|
const cookies = [];
|
|
2655
2689
|
const pairs = cookieString.split(";").map((c) => c.trim());
|
|
@@ -2667,7 +2701,7 @@ var parseCookies = (cookieString, domain) => {
|
|
|
2667
2701
|
cookies.push(cookie);
|
|
2668
2702
|
}
|
|
2669
2703
|
}
|
|
2670
|
-
|
|
2704
|
+
logger5.success("parseCookies", `parsed ${cookies.length} cookies`);
|
|
2671
2705
|
return cookies;
|
|
2672
2706
|
};
|
|
2673
2707
|
|
|
@@ -3505,7 +3539,7 @@ var import_delay4 = __toESM(require("delay"), 1);
|
|
|
3505
3539
|
// src/internals/humanize/desktop.js
|
|
3506
3540
|
var import_delay2 = __toESM(require("delay"), 1);
|
|
3507
3541
|
var import_ghost_cursor_playwright = require("ghost-cursor-playwright");
|
|
3508
|
-
var
|
|
3542
|
+
var logger6 = createInternalLogger("Humanize");
|
|
3509
3543
|
var $CursorWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3510
3544
|
function $GetCursor(page) {
|
|
3511
3545
|
const cursor = $CursorWeakMap.get(page);
|
|
@@ -3533,13 +3567,13 @@ var Humanize = {
|
|
|
3533
3567
|
*/
|
|
3534
3568
|
async initializeCursor(page) {
|
|
3535
3569
|
if ($CursorWeakMap.has(page)) {
|
|
3536
|
-
|
|
3570
|
+
logger6.debug("initializeCursor: cursor already exists, skipping");
|
|
3537
3571
|
return;
|
|
3538
3572
|
}
|
|
3539
|
-
|
|
3573
|
+
logger6.start("initializeCursor", "creating cursor");
|
|
3540
3574
|
const cursor = await (0, import_ghost_cursor_playwright.createCursor)(page);
|
|
3541
3575
|
$CursorWeakMap.set(page, cursor);
|
|
3542
|
-
|
|
3576
|
+
logger6.success("initializeCursor", "cursor initialized");
|
|
3543
3577
|
},
|
|
3544
3578
|
/**
|
|
3545
3579
|
* 人类化鼠标移动 - 使用 ghost-cursor 移动到指定位置或元素
|
|
@@ -3549,17 +3583,17 @@ var Humanize = {
|
|
|
3549
3583
|
*/
|
|
3550
3584
|
async humanMove(page, target) {
|
|
3551
3585
|
const cursor = $GetCursor(page);
|
|
3552
|
-
|
|
3586
|
+
logger6.start("humanMove", `target=${typeof target === "string" ? target : "element/coords"}`);
|
|
3553
3587
|
try {
|
|
3554
3588
|
if (typeof target === "string") {
|
|
3555
3589
|
const element = await page.$(target);
|
|
3556
3590
|
if (!element) {
|
|
3557
|
-
|
|
3591
|
+
logger6.warn(`humanMove: \u5143\u7D20\u4E0D\u5B58\u5728 ${target}`);
|
|
3558
3592
|
return false;
|
|
3559
3593
|
}
|
|
3560
3594
|
const box = await element.boundingBox();
|
|
3561
3595
|
if (!box) {
|
|
3562
|
-
|
|
3596
|
+
logger6.warn(`humanMove: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E ${target}`);
|
|
3563
3597
|
return false;
|
|
3564
3598
|
}
|
|
3565
3599
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.2;
|
|
@@ -3575,10 +3609,10 @@ var Humanize = {
|
|
|
3575
3609
|
await cursor.actions.move({ x, y });
|
|
3576
3610
|
}
|
|
3577
3611
|
}
|
|
3578
|
-
|
|
3612
|
+
logger6.success("humanMove");
|
|
3579
3613
|
return true;
|
|
3580
3614
|
} catch (error) {
|
|
3581
|
-
|
|
3615
|
+
logger6.fail("humanMove", error);
|
|
3582
3616
|
throw error;
|
|
3583
3617
|
}
|
|
3584
3618
|
},
|
|
@@ -3602,12 +3636,12 @@ var Humanize = {
|
|
|
3602
3636
|
maxDurationMs = maxSteps * 220 + 800
|
|
3603
3637
|
} = options;
|
|
3604
3638
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
3605
|
-
|
|
3639
|
+
logger6.start("humanScroll", `target=${targetDesc}`);
|
|
3606
3640
|
let element;
|
|
3607
3641
|
if (typeof target === "string") {
|
|
3608
3642
|
element = await page.$(target);
|
|
3609
3643
|
if (!element) {
|
|
3610
|
-
|
|
3644
|
+
logger6.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${target}`);
|
|
3611
3645
|
return { element: null, didScroll: false };
|
|
3612
3646
|
}
|
|
3613
3647
|
} else {
|
|
@@ -3682,26 +3716,26 @@ var Humanize = {
|
|
|
3682
3716
|
try {
|
|
3683
3717
|
for (let i = 0; i < maxSteps; i++) {
|
|
3684
3718
|
if (Date.now() - startTime > maxDurationMs) {
|
|
3685
|
-
|
|
3719
|
+
logger6.warn(`humanScroll | \u8D85\u65F6\u4FDD\u62A4\u89E6\u53D1 (${maxDurationMs}ms)`);
|
|
3686
3720
|
return { element, didScroll };
|
|
3687
3721
|
}
|
|
3688
3722
|
const status = await checkVisibility();
|
|
3689
3723
|
if (status.code === "VISIBLE") {
|
|
3690
3724
|
if (status.isFixed) {
|
|
3691
|
-
|
|
3725
|
+
logger6.info("humanScroll | fixed \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3692
3726
|
} else {
|
|
3693
|
-
|
|
3727
|
+
logger6.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
3694
3728
|
}
|
|
3695
|
-
|
|
3729
|
+
logger6.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
3696
3730
|
return { element, didScroll };
|
|
3697
3731
|
}
|
|
3698
|
-
|
|
3732
|
+
logger6.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason} ${status.direction ? `(${status.direction})` : ""}`);
|
|
3699
3733
|
if (status.code === "OBSTRUCTED" && status.obstruction) {
|
|
3700
|
-
|
|
3734
|
+
logger6.debug(`humanScroll | \u88AB\u4EE5\u4E0B\u5143\u7D20\u906E\u6321 <${status.obstruction.tag} id="${status.obstruction.id}">`);
|
|
3701
3735
|
}
|
|
3702
3736
|
const scrollRect = await getScrollableRect2();
|
|
3703
3737
|
if (!scrollRect && status.isFixed) {
|
|
3704
|
-
|
|
3738
|
+
logger6.warn("humanScroll | fixed \u5BB9\u5668\u5185\u4E14\u65E0\u53EF\u6EDA\u52A8\u7956\u5148\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3705
3739
|
return { element, didScroll };
|
|
3706
3740
|
}
|
|
3707
3741
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
@@ -3737,10 +3771,10 @@ var Humanize = {
|
|
|
3737
3771
|
didScroll = true;
|
|
3738
3772
|
await (0, import_delay2.default)(this.jitterMs(20 + Math.random() * 40, 0.2));
|
|
3739
3773
|
}
|
|
3740
|
-
|
|
3774
|
+
logger6.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
3741
3775
|
return { element, didScroll };
|
|
3742
3776
|
} catch (error) {
|
|
3743
|
-
|
|
3777
|
+
logger6.fail("humanScroll", error);
|
|
3744
3778
|
throw error;
|
|
3745
3779
|
}
|
|
3746
3780
|
},
|
|
@@ -3758,7 +3792,7 @@ var Humanize = {
|
|
|
3758
3792
|
const cursor = $GetCursor(page);
|
|
3759
3793
|
const { reactionDelay = 250, throwOnMissing = true, scrollIfNeeded = true, restore = false } = options;
|
|
3760
3794
|
const targetDesc = target == null ? "Current Position" : typeof target === "string" ? target : "ElementHandle";
|
|
3761
|
-
|
|
3795
|
+
logger6.start("humanClick", `target=${targetDesc}`);
|
|
3762
3796
|
const restoreOnce = async () => {
|
|
3763
3797
|
if (restoreOnce.restored) return;
|
|
3764
3798
|
restoreOnce.restored = true;
|
|
@@ -3767,14 +3801,14 @@ var Humanize = {
|
|
|
3767
3801
|
await (0, import_delay2.default)(this.jitterMs(1e3));
|
|
3768
3802
|
await restoreOnce.do();
|
|
3769
3803
|
} catch (restoreError) {
|
|
3770
|
-
|
|
3804
|
+
logger6.warn(`humanClick: \u6062\u590D\u6EDA\u52A8\u4F4D\u7F6E\u5931\u8D25: ${restoreError.message}`);
|
|
3771
3805
|
}
|
|
3772
3806
|
};
|
|
3773
3807
|
try {
|
|
3774
3808
|
if (target == null) {
|
|
3775
3809
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3776
3810
|
await cursor.actions.click();
|
|
3777
|
-
|
|
3811
|
+
logger6.success("humanClick", "Clicked current position");
|
|
3778
3812
|
return true;
|
|
3779
3813
|
}
|
|
3780
3814
|
let element;
|
|
@@ -3784,7 +3818,7 @@ var Humanize = {
|
|
|
3784
3818
|
if (throwOnMissing) {
|
|
3785
3819
|
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${target}`);
|
|
3786
3820
|
}
|
|
3787
|
-
|
|
3821
|
+
logger6.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${target}`);
|
|
3788
3822
|
return false;
|
|
3789
3823
|
}
|
|
3790
3824
|
} else {
|
|
@@ -3800,7 +3834,7 @@ var Humanize = {
|
|
|
3800
3834
|
if (throwOnMissing) {
|
|
3801
3835
|
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
3802
3836
|
}
|
|
3803
|
-
|
|
3837
|
+
logger6.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
3804
3838
|
return false;
|
|
3805
3839
|
}
|
|
3806
3840
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.3;
|
|
@@ -3809,11 +3843,11 @@ var Humanize = {
|
|
|
3809
3843
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3810
3844
|
await cursor.actions.click();
|
|
3811
3845
|
await restoreOnce();
|
|
3812
|
-
|
|
3846
|
+
logger6.success("humanClick");
|
|
3813
3847
|
return true;
|
|
3814
3848
|
} catch (error) {
|
|
3815
3849
|
await restoreOnce();
|
|
3816
|
-
|
|
3850
|
+
logger6.fail("humanClick", error);
|
|
3817
3851
|
throw error;
|
|
3818
3852
|
}
|
|
3819
3853
|
},
|
|
@@ -3824,9 +3858,9 @@ var Humanize = {
|
|
|
3824
3858
|
*/
|
|
3825
3859
|
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
3826
3860
|
const ms = this.jitterMs(baseMs, jitterPercent);
|
|
3827
|
-
|
|
3861
|
+
logger6.start("randomSleep", `base=${baseMs}, actual=${ms}ms`);
|
|
3828
3862
|
await (0, import_delay2.default)(ms);
|
|
3829
|
-
|
|
3863
|
+
logger6.success("randomSleep");
|
|
3830
3864
|
},
|
|
3831
3865
|
/**
|
|
3832
3866
|
* 模拟人类"注视"或"阅读"行为:鼠标在页面上随机微动
|
|
@@ -3836,7 +3870,7 @@ var Humanize = {
|
|
|
3836
3870
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
3837
3871
|
const cursor = $GetCursor(page);
|
|
3838
3872
|
const durationMs = this.jitterMs(baseDurationMs, 0.4);
|
|
3839
|
-
|
|
3873
|
+
logger6.start("simulateGaze", `duration=${durationMs}ms`);
|
|
3840
3874
|
const startTime = Date.now();
|
|
3841
3875
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3842
3876
|
while (Date.now() - startTime < durationMs) {
|
|
@@ -3845,7 +3879,7 @@ var Humanize = {
|
|
|
3845
3879
|
await cursor.actions.move({ x, y });
|
|
3846
3880
|
await (0, import_delay2.default)(this.jitterMs(600, 0.5));
|
|
3847
3881
|
}
|
|
3848
|
-
|
|
3882
|
+
logger6.success("simulateGaze");
|
|
3849
3883
|
},
|
|
3850
3884
|
/**
|
|
3851
3885
|
* 人类化输入 - 带节奏变化(快-慢-停顿-偶尔加速)
|
|
@@ -3858,7 +3892,7 @@ var Humanize = {
|
|
|
3858
3892
|
* @param {number} [options.pauseBase=800] - 停顿时长基础值 (ms),实际 ±50% 抖动
|
|
3859
3893
|
*/
|
|
3860
3894
|
async humanType(page, selector, text, options = {}) {
|
|
3861
|
-
|
|
3895
|
+
logger6.start("humanType", `selector=${selector}, textLen=${text.length}`);
|
|
3862
3896
|
const {
|
|
3863
3897
|
baseDelay = 180,
|
|
3864
3898
|
pauseProbability = 0.08,
|
|
@@ -3882,13 +3916,13 @@ var Humanize = {
|
|
|
3882
3916
|
await (0, import_delay2.default)(charDelay);
|
|
3883
3917
|
if (Math.random() < pauseProbability && i < text.length - 1) {
|
|
3884
3918
|
const pauseTime = this.jitterMs(pauseBase, 0.5);
|
|
3885
|
-
|
|
3919
|
+
logger6.debug(`\u505C\u987F ${pauseTime}ms...`);
|
|
3886
3920
|
await (0, import_delay2.default)(pauseTime);
|
|
3887
3921
|
}
|
|
3888
3922
|
}
|
|
3889
|
-
|
|
3923
|
+
logger6.success("humanType");
|
|
3890
3924
|
} catch (error) {
|
|
3891
|
-
|
|
3925
|
+
logger6.fail("humanType", error);
|
|
3892
3926
|
throw error;
|
|
3893
3927
|
}
|
|
3894
3928
|
},
|
|
@@ -3912,7 +3946,7 @@ var Humanize = {
|
|
|
3912
3946
|
keyboardOptions = {}
|
|
3913
3947
|
} = pressOptions || {};
|
|
3914
3948
|
const targetDesc = hasTarget ? typeof targetOrKey === "string" ? targetOrKey : "ElementHandle" : "current focus";
|
|
3915
|
-
|
|
3949
|
+
logger6.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
3916
3950
|
try {
|
|
3917
3951
|
if (hasTarget) {
|
|
3918
3952
|
await this.humanClick(page, targetOrKey, { reactionDelay: focusDelay, scrollIfNeeded, throwOnMissing });
|
|
@@ -3922,10 +3956,10 @@ var Humanize = {
|
|
|
3922
3956
|
...keyboardOptions,
|
|
3923
3957
|
delay: this.jitterMs(holdDelay, 0.5)
|
|
3924
3958
|
});
|
|
3925
|
-
|
|
3959
|
+
logger6.success("humanPress");
|
|
3926
3960
|
return true;
|
|
3927
3961
|
} catch (error) {
|
|
3928
|
-
|
|
3962
|
+
logger6.fail("humanPress", error);
|
|
3929
3963
|
throw error;
|
|
3930
3964
|
}
|
|
3931
3965
|
},
|
|
@@ -3935,22 +3969,22 @@ var Humanize = {
|
|
|
3935
3969
|
* @param {string} selector - 输入框选择器
|
|
3936
3970
|
*/
|
|
3937
3971
|
async humanClear(page, selector) {
|
|
3938
|
-
|
|
3972
|
+
logger6.start("humanClear", `selector=${selector}`);
|
|
3939
3973
|
try {
|
|
3940
3974
|
const locator = page.locator(selector);
|
|
3941
3975
|
await locator.click();
|
|
3942
3976
|
await (0, import_delay2.default)(this.jitterMs(200, 0.4));
|
|
3943
3977
|
const currentValue = await locator.inputValue();
|
|
3944
3978
|
if (!currentValue || currentValue.length === 0) {
|
|
3945
|
-
|
|
3979
|
+
logger6.success("humanClear", "already empty");
|
|
3946
3980
|
return;
|
|
3947
3981
|
}
|
|
3948
3982
|
await page.keyboard.press("Meta+A");
|
|
3949
3983
|
await (0, import_delay2.default)(this.jitterMs(100, 0.4));
|
|
3950
3984
|
await page.keyboard.press("Backspace");
|
|
3951
|
-
|
|
3985
|
+
logger6.success("humanClear");
|
|
3952
3986
|
} catch (error) {
|
|
3953
|
-
|
|
3987
|
+
logger6.fail("humanClear", error);
|
|
3954
3988
|
throw error;
|
|
3955
3989
|
}
|
|
3956
3990
|
},
|
|
@@ -3962,7 +3996,7 @@ var Humanize = {
|
|
|
3962
3996
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
3963
3997
|
const cursor = $GetCursor(page);
|
|
3964
3998
|
const durationMs = this.jitterMs(baseDuration, 0.4);
|
|
3965
|
-
|
|
3999
|
+
logger6.start("warmUpBrowsing", `duration=${durationMs}ms`);
|
|
3966
4000
|
const startTime = Date.now();
|
|
3967
4001
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3968
4002
|
try {
|
|
@@ -3973,17 +4007,13 @@ var Humanize = {
|
|
|
3973
4007
|
const y = 100 + Math.random() * (viewportSize.height - 200);
|
|
3974
4008
|
await cursor.actions.move({ x, y });
|
|
3975
4009
|
await (0, import_delay2.default)(this.jitterMs(350, 0.4));
|
|
3976
|
-
} else if (action < 0.7) {
|
|
3977
|
-
const scrollY = (Math.random() - 0.5) * 200;
|
|
3978
|
-
await page.mouse.wheel(0, scrollY);
|
|
3979
|
-
await (0, import_delay2.default)(this.jitterMs(500, 0.4));
|
|
3980
4010
|
} else {
|
|
3981
4011
|
await (0, import_delay2.default)(this.jitterMs(800, 0.5));
|
|
3982
4012
|
}
|
|
3983
4013
|
}
|
|
3984
|
-
|
|
4014
|
+
logger6.success("warmUpBrowsing");
|
|
3985
4015
|
} catch (error) {
|
|
3986
|
-
|
|
4016
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3987
4017
|
throw error;
|
|
3988
4018
|
}
|
|
3989
4019
|
},
|
|
@@ -3997,7 +4027,7 @@ var Humanize = {
|
|
|
3997
4027
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3998
4028
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3999
4029
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
4000
|
-
|
|
4030
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
4001
4031
|
const sign = direction === "down" ? 1 : -1;
|
|
4002
4032
|
const stepDistance = actualDistance / steps;
|
|
4003
4033
|
try {
|
|
@@ -4009,9 +4039,9 @@ var Humanize = {
|
|
|
4009
4039
|
const baseDelay = 60 + i * 25;
|
|
4010
4040
|
await (0, import_delay2.default)(this.jitterMs(baseDelay, 0.3));
|
|
4011
4041
|
}
|
|
4012
|
-
|
|
4042
|
+
logger6.success("naturalScroll");
|
|
4013
4043
|
} catch (error) {
|
|
4014
|
-
|
|
4044
|
+
logger6.fail("naturalScroll", error);
|
|
4015
4045
|
throw error;
|
|
4016
4046
|
}
|
|
4017
4047
|
}
|
|
@@ -4040,7 +4070,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
4040
4070
|
var waitJitter = (base, jitterPercent = 0.3) => (0, import_delay3.default)(jitterMs(base, jitterPercent));
|
|
4041
4071
|
|
|
4042
4072
|
// src/internals/humanize/mobile.js
|
|
4043
|
-
var
|
|
4073
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
4044
4074
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
4045
4075
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
4046
4076
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4497,7 +4527,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4497
4527
|
}
|
|
4498
4528
|
return true;
|
|
4499
4529
|
} catch (error) {
|
|
4500
|
-
|
|
4530
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4501
4531
|
try {
|
|
4502
4532
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4503
4533
|
await waitJitter(120, 0.35);
|
|
@@ -4531,7 +4561,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4531
4561
|
);
|
|
4532
4562
|
return { method: "touchscreen" };
|
|
4533
4563
|
} catch (error) {
|
|
4534
|
-
|
|
4564
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4535
4565
|
if (!allowMouseFallback) throw error;
|
|
4536
4566
|
}
|
|
4537
4567
|
}
|
|
@@ -4547,10 +4577,10 @@ var MobileHumanize = {
|
|
|
4547
4577
|
async initializeCursor(page) {
|
|
4548
4578
|
if (initializedPages.has(page)) return;
|
|
4549
4579
|
initializedPages.add(page);
|
|
4550
|
-
|
|
4580
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4551
4581
|
},
|
|
4552
4582
|
async humanMove(page, target) {
|
|
4553
|
-
|
|
4583
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4554
4584
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4555
4585
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4556
4586
|
if (!element) {
|
|
@@ -4569,10 +4599,10 @@ var MobileHumanize = {
|
|
|
4569
4599
|
throwOnMissing = false
|
|
4570
4600
|
} = options;
|
|
4571
4601
|
const targetDesc = describeTarget(target);
|
|
4572
|
-
|
|
4602
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4573
4603
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4574
4604
|
if (!element) {
|
|
4575
|
-
|
|
4605
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4576
4606
|
return { element: null, didScroll: false, restore: null };
|
|
4577
4607
|
}
|
|
4578
4608
|
const startTime = Date.now();
|
|
@@ -4581,42 +4611,42 @@ var MobileHumanize = {
|
|
|
4581
4611
|
const status = await checkElementVisibility(element);
|
|
4582
4612
|
if (status.code === "VISIBLE") {
|
|
4583
4613
|
if (status.isFixed) {
|
|
4584
|
-
|
|
4614
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4585
4615
|
} else {
|
|
4586
|
-
|
|
4616
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4587
4617
|
}
|
|
4588
|
-
|
|
4618
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4589
4619
|
return { element, didScroll, restore: null };
|
|
4590
4620
|
}
|
|
4591
4621
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4592
|
-
|
|
4622
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4593
4623
|
return { element, didScroll, restore: null };
|
|
4594
4624
|
}
|
|
4595
4625
|
const scrollRect = await getScrollableRect(element);
|
|
4596
4626
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4597
|
-
|
|
4627
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u4E0D\u5728\u89C6\u53E3\u5185\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (direction=${status.direction || "unknown"})`);
|
|
4598
4628
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4599
4629
|
}
|
|
4600
4630
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4601
|
-
|
|
4631
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4602
4632
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4603
4633
|
}
|
|
4604
4634
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4605
4635
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4606
4636
|
if (moved.moved) {
|
|
4607
|
-
|
|
4637
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4608
4638
|
await waitJitter(90, 0.3);
|
|
4609
4639
|
didScroll = true;
|
|
4610
4640
|
continue;
|
|
4611
4641
|
}
|
|
4612
4642
|
}
|
|
4613
4643
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4614
|
-
|
|
4644
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4615
4645
|
return { element, didScroll, restore: null };
|
|
4616
4646
|
}
|
|
4617
4647
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4618
4648
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4619
|
-
|
|
4649
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4620
4650
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4621
4651
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4622
4652
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4657,7 +4687,7 @@ var MobileHumanize = {
|
|
|
4657
4687
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4658
4688
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4659
4689
|
await page.evaluate((state2) => window.scrollTo(state2.x, state2.y), beforeWindowState);
|
|
4660
|
-
|
|
4690
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4661
4691
|
}
|
|
4662
4692
|
}
|
|
4663
4693
|
let afterElementSnapshot = null;
|
|
@@ -4671,7 +4701,7 @@ var MobileHumanize = {
|
|
|
4671
4701
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4672
4702
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4673
4703
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4674
|
-
|
|
4704
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u9875\u9762\u6EDA\u52A8\u79FB\u52A8\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4675
4705
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4676
4706
|
}
|
|
4677
4707
|
}
|
|
@@ -4703,12 +4733,12 @@ var MobileHumanize = {
|
|
|
4703
4733
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4704
4734
|
if (!moved) {
|
|
4705
4735
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4706
|
-
|
|
4736
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u65E0\u6548\uFF0C\u76F4\u63A5\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4707
4737
|
} else if (beforeState.kind === afterState.kind && Math.abs(expectedDelta) > 24 && Math.sign(topDelta || expectedDelta) === Math.sign(expectedDelta) && Math.abs(topDelta) < Math.min(Math.abs(expectedDelta) * 0.45, 96)) {
|
|
4708
4738
|
const residualDelta = expectedDelta - topDelta;
|
|
4709
4739
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4710
4740
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4711
|
-
|
|
4741
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u8DDD\u79BB\u4E0D\u8DB3\uFF0C\u8865\u507F\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4712
4742
|
}
|
|
4713
4743
|
}
|
|
4714
4744
|
}
|
|
@@ -4716,7 +4746,7 @@ var MobileHumanize = {
|
|
|
4716
4746
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4717
4747
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4718
4748
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4719
|
-
|
|
4749
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u6EDA\u52A8\u5BB9\u5668\u79FB\u52A8\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4720
4750
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4721
4751
|
}
|
|
4722
4752
|
}
|
|
@@ -4727,14 +4757,14 @@ var MobileHumanize = {
|
|
|
4727
4757
|
await waitJitter(80, 0.3);
|
|
4728
4758
|
const finalStatus = await checkElementVisibility(element);
|
|
4729
4759
|
if (finalStatus.code === "VISIBLE") {
|
|
4730
|
-
|
|
4731
|
-
|
|
4760
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4761
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4732
4762
|
return { element, didScroll: true, restore: null };
|
|
4733
4763
|
}
|
|
4734
4764
|
} catch (fallbackError) {
|
|
4735
|
-
|
|
4765
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4736
4766
|
}
|
|
4737
|
-
|
|
4767
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4738
4768
|
return { element, didScroll, restore: null };
|
|
4739
4769
|
},
|
|
4740
4770
|
async humanClick(page, target, options = {}) {
|
|
@@ -4749,7 +4779,7 @@ var MobileHumanize = {
|
|
|
4749
4779
|
fallbackDomClickOnTapError = true
|
|
4750
4780
|
} = options;
|
|
4751
4781
|
const targetDesc = describeTarget(target);
|
|
4752
|
-
|
|
4782
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4753
4783
|
try {
|
|
4754
4784
|
if (target == null) {
|
|
4755
4785
|
const viewport = resolveViewport(page);
|
|
@@ -4761,12 +4791,12 @@ var MobileHumanize = {
|
|
|
4761
4791
|
timeoutMs: tapTimeoutMs,
|
|
4762
4792
|
mouseFallbackTimeoutMs
|
|
4763
4793
|
});
|
|
4764
|
-
|
|
4794
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4765
4795
|
return true;
|
|
4766
4796
|
}
|
|
4767
4797
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4768
4798
|
if (!element) {
|
|
4769
|
-
|
|
4799
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4770
4800
|
return false;
|
|
4771
4801
|
}
|
|
4772
4802
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4790,19 +4820,19 @@ var MobileHumanize = {
|
|
|
4790
4820
|
).catch(() => null);
|
|
4791
4821
|
}
|
|
4792
4822
|
if (fallback?.activated) {
|
|
4793
|
-
|
|
4823
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4794
4824
|
return true;
|
|
4795
4825
|
}
|
|
4796
4826
|
}
|
|
4797
4827
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4798
4828
|
if (throwOnMissing) throw new Error(message);
|
|
4799
|
-
|
|
4829
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4800
4830
|
return false;
|
|
4801
4831
|
}
|
|
4802
4832
|
const box = await element.boundingBox();
|
|
4803
4833
|
if (!box) {
|
|
4804
4834
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4805
|
-
|
|
4835
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4806
4836
|
return false;
|
|
4807
4837
|
}
|
|
4808
4838
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4823,13 +4853,13 @@ var MobileHumanize = {
|
|
|
4823
4853
|
"activation fallback"
|
|
4824
4854
|
).catch(() => null);
|
|
4825
4855
|
if (!fallback?.activated) throw tapError;
|
|
4826
|
-
|
|
4856
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4827
4857
|
}
|
|
4828
4858
|
await waitJitter(120, 0.35);
|
|
4829
|
-
|
|
4859
|
+
logger7.success("humanClick");
|
|
4830
4860
|
return true;
|
|
4831
4861
|
} catch (error) {
|
|
4832
|
-
|
|
4862
|
+
logger7.fail("humanClick", error);
|
|
4833
4863
|
throw error;
|
|
4834
4864
|
}
|
|
4835
4865
|
},
|
|
@@ -4882,7 +4912,7 @@ var MobileHumanize = {
|
|
|
4882
4912
|
keyboardOptions = {}
|
|
4883
4913
|
} = pressOptions || {};
|
|
4884
4914
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4885
|
-
|
|
4915
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4886
4916
|
try {
|
|
4887
4917
|
if (hasTarget) {
|
|
4888
4918
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4896,10 +4926,10 @@ var MobileHumanize = {
|
|
|
4896
4926
|
...keyboardOptions,
|
|
4897
4927
|
delay: jitterMs(holdDelay, 0.5)
|
|
4898
4928
|
});
|
|
4899
|
-
|
|
4929
|
+
logger7.success("humanPress");
|
|
4900
4930
|
return true;
|
|
4901
4931
|
} catch (error) {
|
|
4902
|
-
|
|
4932
|
+
logger7.fail("humanPress", error);
|
|
4903
4933
|
throw error;
|
|
4904
4934
|
}
|
|
4905
4935
|
},
|
|
@@ -4936,20 +4966,7 @@ var MobileHumanize = {
|
|
|
4936
4966
|
const durationMs = jitterMs(baseDuration, 0.4);
|
|
4937
4967
|
const startTime = Date.now();
|
|
4938
4968
|
while (Date.now() - startTime < durationMs) {
|
|
4939
|
-
|
|
4940
|
-
if (action < 0.5) {
|
|
4941
|
-
await dispatchTouchSwipe(page, 120 + Math.random() * 220, {
|
|
4942
|
-
durationMs: 240,
|
|
4943
|
-
steps: 5
|
|
4944
|
-
});
|
|
4945
|
-
} else if (action < 0.7) {
|
|
4946
|
-
await dispatchTouchSwipe(page, -(80 + Math.random() * 160), {
|
|
4947
|
-
durationMs: 220,
|
|
4948
|
-
steps: 4
|
|
4949
|
-
});
|
|
4950
|
-
} else {
|
|
4951
|
-
await waitJitter(560, 0.55);
|
|
4952
|
-
}
|
|
4969
|
+
await waitJitter(560, 0.55);
|
|
4953
4970
|
}
|
|
4954
4971
|
},
|
|
4955
4972
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
@@ -5058,7 +5075,7 @@ var import_fingerprint_injector = require("fingerprint-injector");
|
|
|
5058
5075
|
var import_playwright2 = require("playwright");
|
|
5059
5076
|
|
|
5060
5077
|
// src/proxy-bypass.js
|
|
5061
|
-
var
|
|
5078
|
+
var import_picomatch2 = __toESM(require("picomatch"), 1);
|
|
5062
5079
|
var normalizeByPassDomains = (domains) => {
|
|
5063
5080
|
if (!Array.isArray(domains)) return [];
|
|
5064
5081
|
return domains.map((item) => String(item || "").trim()).filter(Boolean);
|
|
@@ -5069,7 +5086,7 @@ var buildByPassDomainRule = (rawPattern) => {
|
|
|
5069
5086
|
if (!pattern) return null;
|
|
5070
5087
|
let matcher;
|
|
5071
5088
|
try {
|
|
5072
|
-
matcher = (0,
|
|
5089
|
+
matcher = (0, import_picomatch2.default)(pattern, { nocase: true });
|
|
5073
5090
|
} catch {
|
|
5074
5091
|
return null;
|
|
5075
5092
|
}
|
|
@@ -5138,7 +5155,7 @@ var ByPass = {
|
|
|
5138
5155
|
};
|
|
5139
5156
|
|
|
5140
5157
|
// src/internals/launch/traffic.js
|
|
5141
|
-
var
|
|
5158
|
+
var logger8 = createInternalLogger("Launch");
|
|
5142
5159
|
var normalizeObject = (value) => {
|
|
5143
5160
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5144
5161
|
return {};
|
|
@@ -5187,7 +5204,7 @@ var logLaunchTraffic = ({
|
|
|
5187
5204
|
} = {}) => {
|
|
5188
5205
|
if (!enabled) return;
|
|
5189
5206
|
if (explicitProxy) {
|
|
5190
|
-
|
|
5207
|
+
logger8.info("[\u4EE3\u7406\u5DF2\u542F\u7528] \u4F7F\u7528\u663E\u5F0F proxy \u914D\u7F6E\uFF0C\u8DF3\u8FC7 toolkit \u672C\u5730\u6D41\u91CF\u89C2\u6D4B");
|
|
5191
5208
|
return;
|
|
5192
5209
|
}
|
|
5193
5210
|
if (launchProxy) {
|
|
@@ -5197,18 +5214,18 @@ var logLaunchTraffic = ({
|
|
|
5197
5214
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5198
5215
|
} catch {
|
|
5199
5216
|
}
|
|
5200
|
-
|
|
5217
|
+
logger8.info(
|
|
5201
5218
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
5202
5219
|
);
|
|
5203
|
-
|
|
5220
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5204
5221
|
return;
|
|
5205
5222
|
}
|
|
5206
5223
|
if (enableProxy) {
|
|
5207
|
-
|
|
5224
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5208
5225
|
} else if (proxyUrl) {
|
|
5209
|
-
|
|
5226
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5210
5227
|
}
|
|
5211
|
-
|
|
5228
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5212
5229
|
};
|
|
5213
5230
|
var createLaunchTrafficHook = ({
|
|
5214
5231
|
byPassDomains = [],
|
|
@@ -5231,13 +5248,13 @@ var createLaunchTrafficHook = ({
|
|
|
5231
5248
|
}
|
|
5232
5249
|
if (!enabled || byPassDomains.length === 0) return;
|
|
5233
5250
|
if (!matched || !matched.rule) return;
|
|
5234
|
-
|
|
5251
|
+
logger8.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
5235
5252
|
});
|
|
5236
5253
|
};
|
|
5237
5254
|
};
|
|
5238
5255
|
|
|
5239
5256
|
// src/internals/launch/default.js
|
|
5240
|
-
var
|
|
5257
|
+
var logger9 = createInternalLogger("Launch");
|
|
5241
5258
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
5242
5259
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
5243
5260
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -5278,7 +5295,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5278
5295
|
});
|
|
5279
5296
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5280
5297
|
} catch (error) {
|
|
5281
|
-
|
|
5298
|
+
logger9.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5282
5299
|
}
|
|
5283
5300
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5284
5301
|
return detectedVersion;
|
|
@@ -5315,7 +5332,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5315
5332
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5316
5333
|
throw error;
|
|
5317
5334
|
}
|
|
5318
|
-
|
|
5335
|
+
logger9.warn(
|
|
5319
5336
|
`\u5F53\u524D\u6D4F\u89C8\u5668\u5927\u7248\u672C ${requestedBrowserMajorVersion} \u65E0\u53EF\u7528 strict \u6307\u7EB9\u6837\u672C\uFF0C\u9000\u56DE\u4E0D\u7ED1\u5B9A\u5927\u7248\u672C\u751F\u6210: ${error?.message || error}`
|
|
5320
5337
|
);
|
|
5321
5338
|
}
|
|
@@ -5361,7 +5378,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5361
5378
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5362
5379
|
};
|
|
5363
5380
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5364
|
-
|
|
5381
|
+
logger9.info(
|
|
5365
5382
|
`\u5DF2\u751F\u6210\u6D4F\u89C8\u5668\u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | device=${device} | version=${browserProfileCore.browser_major_version || "-"} | fingerprintVersion=${fingerprintBrowserMajorVersion || "-"} | exactVersion=${generated.exactBrowserMajorVersion ? "true" : "false"} | timezone=${timezoneId}`
|
|
5366
5383
|
);
|
|
5367
5384
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5548,7 +5565,7 @@ var DefaultLaunch = {
|
|
|
5548
5565
|
var import_node_child_process2 = require("node:child_process");
|
|
5549
5566
|
var import_node_crypto = require("node:crypto");
|
|
5550
5567
|
var import_node_util = require("node:util");
|
|
5551
|
-
var
|
|
5568
|
+
var logger10 = createInternalLogger("Launch");
|
|
5552
5569
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5553
5570
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5554
5571
|
maxConcurrency: 1,
|
|
@@ -5754,7 +5771,7 @@ var resolveReplayableCloakProfile = (runtimeState, { fingerprintPlatform = "", c
|
|
|
5754
5771
|
const nextCoreRaw = JSON.stringify(nextBrowserProfileCore);
|
|
5755
5772
|
if (currentCoreRaw !== nextCoreRaw) {
|
|
5756
5773
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, nextBrowserProfileCore);
|
|
5757
|
-
|
|
5774
|
+
logger10.info(
|
|
5758
5775
|
`\u5DF2\u540C\u6B65 Cloak \u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | seed=${fingerprintSeed} | platform=${resolvedFingerprintPlatform} | timezone=${timezone || "-"} | locale=${locale || "-"}`
|
|
5759
5776
|
);
|
|
5760
5777
|
}
|
|
@@ -5841,7 +5858,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5841
5858
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5842
5859
|
return;
|
|
5843
5860
|
}
|
|
5844
|
-
|
|
5861
|
+
logger10.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5845
5862
|
});
|
|
5846
5863
|
};
|
|
5847
5864
|
var CloakLaunch = {
|
|
@@ -6001,7 +6018,7 @@ var Launch = withModeReflect("Launch", launchStrategies);
|
|
|
6001
6018
|
// src/live-view.js
|
|
6002
6019
|
var import_express = __toESM(require("express"), 1);
|
|
6003
6020
|
var import_apify = require("apify");
|
|
6004
|
-
var
|
|
6021
|
+
var logger11 = createInternalLogger("LiveView");
|
|
6005
6022
|
async function startLiveViewServer(liveViewKey) {
|
|
6006
6023
|
const app = (0, import_express.default)();
|
|
6007
6024
|
app.get("/", async (req, res) => {
|
|
@@ -6026,13 +6043,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
6026
6043
|
</html>
|
|
6027
6044
|
`);
|
|
6028
6045
|
} catch (error) {
|
|
6029
|
-
|
|
6046
|
+
logger11.fail("Live View Server", error);
|
|
6030
6047
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
6031
6048
|
}
|
|
6032
6049
|
});
|
|
6033
6050
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
6034
6051
|
app.listen(port, () => {
|
|
6035
|
-
|
|
6052
|
+
logger11.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
6036
6053
|
});
|
|
6037
6054
|
}
|
|
6038
6055
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -6040,10 +6057,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
6040
6057
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
6041
6058
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
6042
6059
|
if (logMessage) {
|
|
6043
|
-
|
|
6060
|
+
logger11.info(`(\u622A\u56FE): ${logMessage}`);
|
|
6044
6061
|
}
|
|
6045
6062
|
} catch (e) {
|
|
6046
|
-
|
|
6063
|
+
logger11.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
6047
6064
|
}
|
|
6048
6065
|
}
|
|
6049
6066
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -6149,7 +6166,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
6149
6166
|
};
|
|
6150
6167
|
|
|
6151
6168
|
// src/internals/captcha/bytedance.js
|
|
6152
|
-
var
|
|
6169
|
+
var logger12 = createInternalLogger("Captcha");
|
|
6153
6170
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
6154
6171
|
apiType: "31234",
|
|
6155
6172
|
maxRetries: 3,
|
|
@@ -6281,7 +6298,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
6281
6298
|
}
|
|
6282
6299
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
6283
6300
|
}
|
|
6284
|
-
|
|
6301
|
+
logger12.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
6285
6302
|
};
|
|
6286
6303
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
6287
6304
|
if (!options.debugArtifacts) {
|
|
@@ -6318,14 +6335,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6318
6335
|
if (!isContainerVisible) {
|
|
6319
6336
|
return null;
|
|
6320
6337
|
}
|
|
6321
|
-
|
|
6338
|
+
logger12.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
6322
6339
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
6323
6340
|
let isIframeVisible = await waitForVisible(
|
|
6324
6341
|
iframeLocator,
|
|
6325
6342
|
options.iframeVisibleTimeoutMs
|
|
6326
6343
|
);
|
|
6327
6344
|
if (!isIframeVisible) {
|
|
6328
|
-
|
|
6345
|
+
logger12.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
6329
6346
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
6330
6347
|
isIframeVisible = await waitForVisible(
|
|
6331
6348
|
iframeLocator,
|
|
@@ -6335,7 +6352,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6335
6352
|
if (!isIframeVisible) {
|
|
6336
6353
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
6337
6354
|
}
|
|
6338
|
-
|
|
6355
|
+
logger12.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
6339
6356
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
6340
6357
|
if (!frame) {
|
|
6341
6358
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -6451,11 +6468,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
6451
6468
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
6452
6469
|
...options,
|
|
6453
6470
|
page,
|
|
6454
|
-
logger:
|
|
6471
|
+
logger: logger12,
|
|
6455
6472
|
forceMouse: true
|
|
6456
6473
|
}).catch(() => false);
|
|
6457
6474
|
if (!clicked) {
|
|
6458
|
-
|
|
6475
|
+
logger12.warn("Refresh button not found.");
|
|
6459
6476
|
return false;
|
|
6460
6477
|
}
|
|
6461
6478
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6486,24 +6503,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6486
6503
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6487
6504
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6488
6505
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6489
|
-
|
|
6506
|
+
logger12.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u64CD\u4F5C\u5F15\u5BFC\u5C42\uFF0C\u7B49\u5F85\u5176\u6D88\u5931\u540E\u518D\u5F00\u59CB\u8BC6\u522B\u3002");
|
|
6490
6507
|
hasLoggedGuideMask = true;
|
|
6491
6508
|
}
|
|
6492
6509
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6493
|
-
|
|
6510
|
+
logger12.info(
|
|
6494
6511
|
hasSeenGuideMask ? "\u9A8C\u8BC1\u7801\u56FE\u7247\u548C\u62D6\u62FD\u533A\u57DF\u5DF2\u5C31\u7EEA\uFF0C\u5F15\u5BFC\u5C42\u5DF2\u6D88\u5931\u3002" : hasSeenLoading ? "\u9A8C\u8BC1\u7801\u56FE\u7247\u5DF2\u52A0\u8F7D\u5B8C\u6210\u3002" : "\u9A8C\u8BC1\u7801\u56FE\u7247\u5DF2\u5C31\u7EEA\u3002"
|
|
6495
6512
|
);
|
|
6496
6513
|
return;
|
|
6497
6514
|
}
|
|
6498
6515
|
if (hasErrorTextVisible) {
|
|
6499
|
-
|
|
6516
|
+
logger12.warn("\u9A8C\u8BC1\u7801\u9762\u677F\u51FA\u73B0\u7F51\u7EDC\u5F02\u5E38\u6587\u6848\uFF0C\u5C1D\u8BD5\u7ACB\u5373\u5237\u65B0\u9898\u76EE\u3002");
|
|
6500
6517
|
await refreshCaptcha(page, frame, options);
|
|
6501
6518
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6502
6519
|
hasSeenLoading = false;
|
|
6503
6520
|
continue;
|
|
6504
6521
|
}
|
|
6505
6522
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6506
|
-
|
|
6523
|
+
logger12.warn(`\u9A8C\u8BC1\u7801\u9898\u76EE\u8D85\u8FC7 ${options.challengeReadyRefreshTimeoutMs}ms \u4ECD\u672A\u51C6\u5907\u597D\uFF0C\u5C1D\u8BD5\u5237\u65B0\u9898\u76EE\u3002`);
|
|
6507
6524
|
await refreshCaptcha(page, frame, options);
|
|
6508
6525
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6509
6526
|
hasSeenLoading = false;
|
|
@@ -6551,7 +6568,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6551
6568
|
accepted
|
|
6552
6569
|
};
|
|
6553
6570
|
dragAttempts.push(attemptInfo);
|
|
6554
|
-
|
|
6571
|
+
logger12.info(
|
|
6555
6572
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6556
6573
|
);
|
|
6557
6574
|
if (accepted) {
|
|
@@ -6569,7 +6586,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6569
6586
|
dragAttempts,
|
|
6570
6587
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6571
6588
|
}).catch((error) => {
|
|
6572
|
-
|
|
6589
|
+
logger12.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6573
6590
|
});
|
|
6574
6591
|
return {
|
|
6575
6592
|
accepted: false,
|
|
@@ -6586,16 +6603,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6586
6603
|
...options
|
|
6587
6604
|
};
|
|
6588
6605
|
if (!config.token) {
|
|
6589
|
-
|
|
6606
|
+
logger12.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6590
6607
|
return false;
|
|
6591
6608
|
}
|
|
6592
|
-
|
|
6609
|
+
logger12.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6593
6610
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6594
|
-
|
|
6611
|
+
logger12.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6595
6612
|
try {
|
|
6596
6613
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6597
6614
|
if (!captchaContext) {
|
|
6598
|
-
|
|
6615
|
+
logger12.info("Captcha container is not visible anymore.");
|
|
6599
6616
|
return true;
|
|
6600
6617
|
}
|
|
6601
6618
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6608,7 +6625,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6608
6625
|
"ready",
|
|
6609
6626
|
config
|
|
6610
6627
|
).catch((error) => {
|
|
6611
|
-
|
|
6628
|
+
logger12.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6612
6629
|
});
|
|
6613
6630
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6614
6631
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6620,16 +6637,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6620
6637
|
});
|
|
6621
6638
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6622
6639
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6623
|
-
|
|
6640
|
+
logger12.warn(
|
|
6624
6641
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6625
6642
|
);
|
|
6626
6643
|
await refreshCaptcha(page, frame, config);
|
|
6627
6644
|
continue;
|
|
6628
6645
|
}
|
|
6629
|
-
|
|
6646
|
+
logger12.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6630
6647
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6631
6648
|
if (!dropTarget) {
|
|
6632
|
-
|
|
6649
|
+
logger12.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6633
6650
|
await refreshCaptcha(page, frame, config);
|
|
6634
6651
|
continue;
|
|
6635
6652
|
}
|
|
@@ -6640,7 +6657,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6640
6657
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6641
6658
|
);
|
|
6642
6659
|
}
|
|
6643
|
-
|
|
6660
|
+
logger12.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6644
6661
|
for (const imageIndex of normalizedIndexes) {
|
|
6645
6662
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6646
6663
|
throw new Error(
|
|
@@ -6672,52 +6689,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6672
6689
|
}
|
|
6673
6690
|
}
|
|
6674
6691
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6675
|
-
|
|
6692
|
+
logger12.info(
|
|
6676
6693
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6677
6694
|
);
|
|
6678
6695
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6679
6696
|
...config,
|
|
6680
6697
|
page,
|
|
6681
|
-
logger:
|
|
6698
|
+
logger: logger12,
|
|
6682
6699
|
forceMouse: true,
|
|
6683
6700
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6684
6701
|
}).catch(() => false);
|
|
6685
6702
|
if (!submitted) {
|
|
6686
|
-
|
|
6703
|
+
logger12.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6687
6704
|
}
|
|
6688
6705
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6689
6706
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6690
|
-
|
|
6707
|
+
logger12.info(
|
|
6691
6708
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6692
6709
|
);
|
|
6693
6710
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6694
6711
|
if (!stillVisible) {
|
|
6695
|
-
|
|
6712
|
+
logger12.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6696
6713
|
return true;
|
|
6697
6714
|
}
|
|
6698
6715
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6699
6716
|
beforeSubmitState,
|
|
6700
6717
|
afterSubmitState
|
|
6701
6718
|
}).catch((error) => {
|
|
6702
|
-
|
|
6719
|
+
logger12.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6703
6720
|
});
|
|
6704
|
-
|
|
6721
|
+
logger12.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6705
6722
|
await page.waitForTimeout(2e3);
|
|
6706
6723
|
await refreshCaptcha(page, frame, config);
|
|
6707
6724
|
} catch (error) {
|
|
6708
|
-
|
|
6725
|
+
logger12.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6709
6726
|
}
|
|
6710
6727
|
if (attempt < config.maxRetries) {
|
|
6711
6728
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6712
6729
|
}
|
|
6713
6730
|
}
|
|
6714
|
-
|
|
6731
|
+
logger12.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6715
6732
|
return false;
|
|
6716
6733
|
}
|
|
6717
6734
|
var sloveCaptcha = solveCaptcha;
|
|
6718
6735
|
|
|
6719
6736
|
// src/chaptcha.js
|
|
6720
|
-
var
|
|
6737
|
+
var logger13 = createInternalLogger("Captcha");
|
|
6721
6738
|
var DOM_MONITOR_WAIT_TIMEOUT_MS = 1e3;
|
|
6722
6739
|
var DOM_MONITOR_POST_DETECT_HIDDEN_WAIT_MS = 300;
|
|
6723
6740
|
var DOM_MONITOR_RECOVERY_WAIT_MS = 100;
|
|
@@ -6792,7 +6809,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6792
6809
|
await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
|
|
6793
6810
|
continue;
|
|
6794
6811
|
}
|
|
6795
|
-
|
|
6812
|
+
logger13.warning(
|
|
6796
6813
|
"useCaptchaMonitor",
|
|
6797
6814
|
`DOM \u76D1\u63A7\u51FA\u73B0\u5F02\u5E38\uFF08\u7EE7\u7EED\u91CD\u8BD5\uFF09: selector=${domSelector}, error=${getErrorMessage(error)}`
|
|
6798
6815
|
);
|
|
@@ -6800,7 +6817,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6800
6817
|
}
|
|
6801
6818
|
}
|
|
6802
6819
|
})();
|
|
6803
|
-
|
|
6820
|
+
logger13.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6804
6821
|
cleanupFns.push(async () => {
|
|
6805
6822
|
await domMonitorTask?.catch(() => {
|
|
6806
6823
|
});
|
|
@@ -6817,7 +6834,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6817
6834
|
}
|
|
6818
6835
|
};
|
|
6819
6836
|
page.on("framenavigated", frameHandler);
|
|
6820
|
-
|
|
6837
|
+
logger13.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6821
6838
|
Promise.resolve().then(async () => {
|
|
6822
6839
|
if (!isStopped && page.url().includes(urlPattern)) {
|
|
6823
6840
|
await triggerDetected();
|
|
@@ -6830,7 +6847,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6830
6847
|
}
|
|
6831
6848
|
return {
|
|
6832
6849
|
stop: async () => {
|
|
6833
|
-
|
|
6850
|
+
logger13.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6834
6851
|
isStopped = true;
|
|
6835
6852
|
for (const fn of cleanupFns) {
|
|
6836
6853
|
await fn();
|
|
@@ -6869,7 +6886,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6869
6886
|
);
|
|
6870
6887
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6871
6888
|
callCaptchaRecognitionApi,
|
|
6872
|
-
logger:
|
|
6889
|
+
logger: logger13
|
|
6873
6890
|
});
|
|
6874
6891
|
}
|
|
6875
6892
|
var Captcha = {
|
|
@@ -6880,7 +6897,7 @@ var Captcha = {
|
|
|
6880
6897
|
// src/mutation.js
|
|
6881
6898
|
var import_node_crypto2 = require("node:crypto");
|
|
6882
6899
|
var import_uuid = require("uuid");
|
|
6883
|
-
var
|
|
6900
|
+
var logger14 = createInternalLogger("Mutation");
|
|
6884
6901
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6885
6902
|
Added: "added",
|
|
6886
6903
|
Changed: "changed",
|
|
@@ -6913,14 +6930,14 @@ var Mutation = {
|
|
|
6913
6930
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6914
6931
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6915
6932
|
const onMutation = options.onMutation;
|
|
6916
|
-
|
|
6933
|
+
logger14.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6917
6934
|
if (initialTimeout > 0) {
|
|
6918
6935
|
const selectorQuery = selectorList.join(",");
|
|
6919
6936
|
try {
|
|
6920
6937
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6921
|
-
|
|
6938
|
+
logger14.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6922
6939
|
} catch (e) {
|
|
6923
|
-
|
|
6940
|
+
logger14.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6924
6941
|
throw e;
|
|
6925
6942
|
}
|
|
6926
6943
|
}
|
|
@@ -6936,7 +6953,7 @@ var Mutation = {
|
|
|
6936
6953
|
return "__CONTINUE__";
|
|
6937
6954
|
}
|
|
6938
6955
|
});
|
|
6939
|
-
|
|
6956
|
+
logger14.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6940
6957
|
} catch (e) {
|
|
6941
6958
|
}
|
|
6942
6959
|
}
|
|
@@ -7051,9 +7068,9 @@ var Mutation = {
|
|
|
7051
7068
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
7052
7069
|
);
|
|
7053
7070
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
7054
|
-
|
|
7071
|
+
logger14.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7055
7072
|
}
|
|
7056
|
-
|
|
7073
|
+
logger14.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7057
7074
|
return result;
|
|
7058
7075
|
},
|
|
7059
7076
|
/**
|
|
@@ -7225,22 +7242,22 @@ var Mutation = {
|
|
|
7225
7242
|
return "__CONTINUE__";
|
|
7226
7243
|
}
|
|
7227
7244
|
};
|
|
7228
|
-
|
|
7245
|
+
logger14.start(
|
|
7229
7246
|
"waitForStableAcrossRoots",
|
|
7230
7247
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
7231
7248
|
);
|
|
7232
7249
|
if (initialTimeout > 0) {
|
|
7233
7250
|
try {
|
|
7234
7251
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
7235
|
-
|
|
7252
|
+
logger14.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
7236
7253
|
} catch (e) {
|
|
7237
|
-
|
|
7254
|
+
logger14.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
7238
7255
|
throw e;
|
|
7239
7256
|
}
|
|
7240
7257
|
}
|
|
7241
7258
|
let state2 = await buildState();
|
|
7242
7259
|
if (!state2?.hasMatched) {
|
|
7243
|
-
|
|
7260
|
+
logger14.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7244
7261
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
7245
7262
|
}
|
|
7246
7263
|
let mutationCount = 0;
|
|
@@ -7277,7 +7294,7 @@ var Mutation = {
|
|
|
7277
7294
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
7278
7295
|
lastSnapshotKey = lastState.snapshotKey;
|
|
7279
7296
|
mutationCount += 1;
|
|
7280
|
-
|
|
7297
|
+
logger14.info(
|
|
7281
7298
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
7282
7299
|
);
|
|
7283
7300
|
const signal = await invokeMutationCallback({
|
|
@@ -7290,7 +7307,7 @@ var Mutation = {
|
|
|
7290
7307
|
continue;
|
|
7291
7308
|
}
|
|
7292
7309
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
7293
|
-
|
|
7310
|
+
logger14.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7294
7311
|
return {
|
|
7295
7312
|
mutationCount,
|
|
7296
7313
|
stableTime: waitForStableTime,
|
|
@@ -7317,7 +7334,7 @@ var Mutation = {
|
|
|
7317
7334
|
const onMutation = options.onMutation;
|
|
7318
7335
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
7319
7336
|
const mode2 = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
7320
|
-
|
|
7337
|
+
logger14.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode2}`);
|
|
7321
7338
|
const monitorKey = generateKey("pk_mon");
|
|
7322
7339
|
const callbackName = generateKey("pk_mon_cb");
|
|
7323
7340
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7460,7 +7477,7 @@ var Mutation = {
|
|
|
7460
7477
|
return total;
|
|
7461
7478
|
};
|
|
7462
7479
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode: mode2 });
|
|
7463
|
-
|
|
7480
|
+
logger14.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7464
7481
|
return {
|
|
7465
7482
|
stop: async () => {
|
|
7466
7483
|
let totalMutations = 0;
|
|
@@ -7473,7 +7490,7 @@ var Mutation = {
|
|
|
7473
7490
|
}, cleanerName);
|
|
7474
7491
|
} catch (e) {
|
|
7475
7492
|
}
|
|
7476
|
-
|
|
7493
|
+
logger14.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7477
7494
|
return { totalMutations };
|
|
7478
7495
|
}
|
|
7479
7496
|
};
|
|
@@ -8342,7 +8359,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
8342
8359
|
};
|
|
8343
8360
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
8344
8361
|
var Logger = {
|
|
8345
|
-
setLogger: (
|
|
8362
|
+
setLogger: (logger18) => setDefaultLogger(logger18),
|
|
8346
8363
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
8347
8364
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
8348
8365
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -8350,8 +8367,8 @@ var Logger = {
|
|
|
8350
8367
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
8351
8368
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
8352
8369
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
8353
|
-
useTemplate: (
|
|
8354
|
-
if (
|
|
8370
|
+
useTemplate: (logger18) => {
|
|
8371
|
+
if (logger18) return createTemplateLogger(createBaseLogger("", logger18));
|
|
8355
8372
|
return createTemplateLogger();
|
|
8356
8373
|
}
|
|
8357
8374
|
};
|
|
@@ -8425,7 +8442,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
8425
8442
|
];
|
|
8426
8443
|
var cachedStripLogoSrcPromise = null;
|
|
8427
8444
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
8428
|
-
var
|
|
8445
|
+
var logger15 = createInternalLogger("Watermarkify");
|
|
8429
8446
|
var normalizeText2 = (value) => String(value || "").trim();
|
|
8430
8447
|
var toInline = (value, maxLen = 200) => {
|
|
8431
8448
|
const text = normalizeText2(value);
|
|
@@ -8667,9 +8684,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8667
8684
|
location: toInline(resolved.location, 80)
|
|
8668
8685
|
};
|
|
8669
8686
|
if (enrichment.ip || enrichment.location) {
|
|
8670
|
-
|
|
8687
|
+
logger15.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8671
8688
|
} else {
|
|
8672
|
-
|
|
8689
|
+
logger15.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8673
8690
|
}
|
|
8674
8691
|
return enrichment;
|
|
8675
8692
|
} finally {
|
|
@@ -8858,12 +8875,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8858
8875
|
};
|
|
8859
8876
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8860
8877
|
if (!page || typeof page.context !== "function") {
|
|
8861
|
-
|
|
8878
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8862
8879
|
return buffer;
|
|
8863
8880
|
}
|
|
8864
8881
|
const renderScope = await openProbePage(page);
|
|
8865
8882
|
if (!renderScope?.page) {
|
|
8866
|
-
|
|
8883
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8867
8884
|
return buffer;
|
|
8868
8885
|
}
|
|
8869
8886
|
try {
|
|
@@ -8928,13 +8945,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8928
8945
|
fullPage: true,
|
|
8929
8946
|
animations: "disabled"
|
|
8930
8947
|
}).catch((error) => {
|
|
8931
|
-
|
|
8948
|
+
logger15.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8932
8949
|
return null;
|
|
8933
8950
|
});
|
|
8934
8951
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8935
8952
|
return composed;
|
|
8936
8953
|
}
|
|
8937
|
-
|
|
8954
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8938
8955
|
return buffer;
|
|
8939
8956
|
} finally {
|
|
8940
8957
|
await renderScope.close().catch(() => {
|
|
@@ -8947,7 +8964,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8947
8964
|
}
|
|
8948
8965
|
const probeScope = await openProbePage(page);
|
|
8949
8966
|
if (!probeScope?.page) {
|
|
8950
|
-
|
|
8967
|
+
logger15.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8951
8968
|
return null;
|
|
8952
8969
|
}
|
|
8953
8970
|
const timeoutMs = Math.max(
|
|
@@ -8956,12 +8973,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8956
8973
|
);
|
|
8957
8974
|
try {
|
|
8958
8975
|
const probePage = probeScope.page;
|
|
8959
|
-
|
|
8976
|
+
logger15.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8960
8977
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8961
8978
|
waitUntil: "commit",
|
|
8962
8979
|
timeout: timeoutMs
|
|
8963
8980
|
}).catch((error) => {
|
|
8964
|
-
|
|
8981
|
+
logger15.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8965
8982
|
return null;
|
|
8966
8983
|
});
|
|
8967
8984
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8983,13 +9000,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8983
9000
|
}
|
|
8984
9001
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8985
9002
|
if (parsed?.ip || parsed?.location) {
|
|
8986
|
-
|
|
9003
|
+
logger15.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8987
9004
|
return parsed;
|
|
8988
9005
|
}
|
|
8989
|
-
|
|
9006
|
+
logger15.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8990
9007
|
return null;
|
|
8991
9008
|
} catch (error) {
|
|
8992
|
-
|
|
9009
|
+
logger15.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8993
9010
|
return null;
|
|
8994
9011
|
} finally {
|
|
8995
9012
|
await probeScope.close().catch(() => {
|
|
@@ -9003,10 +9020,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
9003
9020
|
ip: toInline(options.ip, 80),
|
|
9004
9021
|
location: toInline(options.location, 80)
|
|
9005
9022
|
};
|
|
9006
|
-
|
|
9023
|
+
logger15.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
9007
9024
|
if (!merged.ip || !merged.location) {
|
|
9008
9025
|
if (cached?.ip || cached?.location) {
|
|
9009
|
-
|
|
9026
|
+
logger15.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
9010
9027
|
}
|
|
9011
9028
|
fillEnrichment(merged, cached);
|
|
9012
9029
|
}
|
|
@@ -9030,15 +9047,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
9030
9047
|
"x-geo-country"
|
|
9031
9048
|
]), 80);
|
|
9032
9049
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
9033
|
-
|
|
9050
|
+
logger15.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
9034
9051
|
merged.location = headerLocation || merged.location;
|
|
9035
9052
|
}
|
|
9036
9053
|
}
|
|
9037
9054
|
writeCachedEnrichment(page, merged);
|
|
9038
9055
|
if (merged.ip || merged.location) {
|
|
9039
|
-
|
|
9056
|
+
logger15.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
9040
9057
|
} else {
|
|
9041
|
-
|
|
9058
|
+
logger15.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
9042
9059
|
}
|
|
9043
9060
|
return merged;
|
|
9044
9061
|
};
|
|
@@ -9851,7 +9868,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9851
9868
|
}
|
|
9852
9869
|
const imageInfo = readImageInfo(buffer);
|
|
9853
9870
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9854
|
-
|
|
9871
|
+
logger15.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9855
9872
|
return buffer;
|
|
9856
9873
|
}
|
|
9857
9874
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9869,7 +9886,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9869
9886
|
|
|
9870
9887
|
// src/internals/compression.js
|
|
9871
9888
|
var import_jimp2 = require("jimp");
|
|
9872
|
-
var
|
|
9889
|
+
var logger16 = createInternalLogger("Compression");
|
|
9873
9890
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9874
9891
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9875
9892
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9988,18 +10005,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9988
10005
|
return buffer.toString("base64");
|
|
9989
10006
|
}
|
|
9990
10007
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9991
|
-
|
|
10008
|
+
logger16.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9992
10009
|
return null;
|
|
9993
10010
|
});
|
|
9994
10011
|
if (!result?.buffer) {
|
|
9995
10012
|
return buffer.toString("base64");
|
|
9996
10013
|
}
|
|
9997
10014
|
if (result.withinLimit) {
|
|
9998
|
-
|
|
10015
|
+
logger16.info(
|
|
9999
10016
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
10000
10017
|
);
|
|
10001
10018
|
} else {
|
|
10002
|
-
|
|
10019
|
+
logger16.warning(
|
|
10003
10020
|
`captureScreen \u538B\u7F29\u540E\u4ECD\u8D85\u8FC7\u76EE\u6807: ${originalBytes} -> ${result.bytes} bytes, maxBytes=${compression.maxBytes}, format=${result.format}, quality=${result.quality}, scale=${result.scale}`
|
|
10004
10021
|
);
|
|
10005
10022
|
}
|
|
@@ -10007,7 +10024,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
10007
10024
|
};
|
|
10008
10025
|
|
|
10009
10026
|
// src/share.js
|
|
10010
|
-
var
|
|
10027
|
+
var logger17 = createInternalLogger("Share");
|
|
10011
10028
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
10012
10029
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
10013
10030
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -10144,7 +10161,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
10144
10161
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
10145
10162
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
10146
10163
|
let matched = false;
|
|
10147
|
-
|
|
10164
|
+
logger17.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode2}`);
|
|
10148
10165
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
10149
10166
|
mode: mode2,
|
|
10150
10167
|
onMutation: (context = {}) => {
|
|
@@ -10162,12 +10179,12 @@ ${text}`;
|
|
|
10162
10179
|
});
|
|
10163
10180
|
}
|
|
10164
10181
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
10165
|
-
|
|
10182
|
+
logger17.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
10166
10183
|
}
|
|
10167
10184
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
10168
10185
|
if (!candidate) return;
|
|
10169
10186
|
matched = true;
|
|
10170
|
-
|
|
10187
|
+
logger17.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
10171
10188
|
if (onMatch) {
|
|
10172
10189
|
onMatch({
|
|
10173
10190
|
link: candidate,
|
|
@@ -10183,7 +10200,7 @@ ${text}`;
|
|
|
10183
10200
|
return {
|
|
10184
10201
|
stop: async () => {
|
|
10185
10202
|
const result = await monitor.stop();
|
|
10186
|
-
|
|
10203
|
+
logger17.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
10187
10204
|
return result;
|
|
10188
10205
|
}
|
|
10189
10206
|
};
|
|
@@ -10232,8 +10249,8 @@ var Share = {
|
|
|
10232
10249
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
10233
10250
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
10234
10251
|
}
|
|
10235
|
-
|
|
10236
|
-
|
|
10252
|
+
logger17.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
10253
|
+
logger17.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
10237
10254
|
const stats = {
|
|
10238
10255
|
actionTimedOut: false,
|
|
10239
10256
|
domMutationCount: 0,
|
|
@@ -10245,7 +10262,7 @@ var Share = {
|
|
|
10245
10262
|
responseSampleUrls: []
|
|
10246
10263
|
};
|
|
10247
10264
|
if (isAborted()) {
|
|
10248
|
-
|
|
10265
|
+
logger17.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10249
10266
|
return {
|
|
10250
10267
|
link: null,
|
|
10251
10268
|
payloadText: "",
|
|
@@ -10268,7 +10285,7 @@ var Share = {
|
|
|
10268
10285
|
link: validated,
|
|
10269
10286
|
payloadText: String(payloadText || "")
|
|
10270
10287
|
};
|
|
10271
|
-
|
|
10288
|
+
logger17.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
10272
10289
|
return true;
|
|
10273
10290
|
};
|
|
10274
10291
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -10303,7 +10320,7 @@ var Share = {
|
|
|
10303
10320
|
try {
|
|
10304
10321
|
await monitor.stop();
|
|
10305
10322
|
} catch (error) {
|
|
10306
|
-
|
|
10323
|
+
logger17.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
10307
10324
|
}
|
|
10308
10325
|
};
|
|
10309
10326
|
const onResponse = async (response) => {
|
|
@@ -10317,29 +10334,29 @@ var Share = {
|
|
|
10317
10334
|
stats.responseSampleUrls.push(url);
|
|
10318
10335
|
}
|
|
10319
10336
|
if (stats.responseObserved <= 5) {
|
|
10320
|
-
|
|
10337
|
+
logger17.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
10321
10338
|
}
|
|
10322
10339
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
10323
10340
|
stats.responseMatched += 1;
|
|
10324
10341
|
stats.lastMatchedUrl = url;
|
|
10325
|
-
|
|
10342
|
+
logger17.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
10326
10343
|
const text = await response.text();
|
|
10327
10344
|
const hit = resolveResponseCandidate(text);
|
|
10328
10345
|
if (!hit?.link) {
|
|
10329
10346
|
if (stats.responseMatched <= 3) {
|
|
10330
|
-
|
|
10347
|
+
logger17.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
10331
10348
|
}
|
|
10332
10349
|
return;
|
|
10333
10350
|
}
|
|
10334
10351
|
stats.responseResolved += 1;
|
|
10335
|
-
|
|
10352
|
+
logger17.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
10336
10353
|
setCandidate("response", hit.link, hit.payloadText);
|
|
10337
10354
|
} catch (error) {
|
|
10338
|
-
|
|
10355
|
+
logger17.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
10339
10356
|
}
|
|
10340
10357
|
};
|
|
10341
10358
|
if (share.mode === "dom") {
|
|
10342
|
-
|
|
10359
|
+
logger17.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
10343
10360
|
domMonitor = await createDomShareMonitor(page, {
|
|
10344
10361
|
prefix: share.prefix,
|
|
10345
10362
|
selectors: domSelectors,
|
|
@@ -10354,17 +10371,17 @@ var Share = {
|
|
|
10354
10371
|
});
|
|
10355
10372
|
}
|
|
10356
10373
|
if (share.mode === "response") {
|
|
10357
|
-
|
|
10374
|
+
logger17.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
10358
10375
|
page.on("response", onResponse);
|
|
10359
10376
|
}
|
|
10360
10377
|
if (share.mode === "custom") {
|
|
10361
|
-
|
|
10378
|
+
logger17.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
10362
10379
|
}
|
|
10363
10380
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
10364
10381
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
10365
10382
|
try {
|
|
10366
10383
|
const actionTimeout = getRemainingMs();
|
|
10367
|
-
|
|
10384
|
+
logger17.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
10368
10385
|
let actionValue;
|
|
10369
10386
|
if (!isAborted() && actionTimeout > 0) {
|
|
10370
10387
|
let timer = null;
|
|
@@ -10377,30 +10394,30 @@ var Share = {
|
|
|
10377
10394
|
]);
|
|
10378
10395
|
if (timer) clearTimeout(timer);
|
|
10379
10396
|
if (actionResult.type === "error") {
|
|
10380
|
-
|
|
10397
|
+
logger17.fail("captureLink.performActions", actionResult.error);
|
|
10381
10398
|
throw actionResult.error;
|
|
10382
10399
|
}
|
|
10383
10400
|
if (actionResult.type === "timeout") {
|
|
10384
10401
|
stats.actionTimedOut = true;
|
|
10385
|
-
|
|
10402
|
+
logger17.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
10386
10403
|
} else {
|
|
10387
10404
|
actionValue = actionResult.result;
|
|
10388
|
-
|
|
10405
|
+
logger17.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
10389
10406
|
}
|
|
10390
10407
|
}
|
|
10391
10408
|
if (share.mode === "custom") {
|
|
10392
10409
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
10393
10410
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
10394
10411
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
10395
|
-
|
|
10412
|
+
logger17.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
10396
10413
|
} else {
|
|
10397
|
-
|
|
10414
|
+
logger17.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
10398
10415
|
}
|
|
10399
10416
|
}
|
|
10400
10417
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
10401
10418
|
while (true) {
|
|
10402
10419
|
if (isAborted()) {
|
|
10403
|
-
|
|
10420
|
+
logger17.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10404
10421
|
return {
|
|
10405
10422
|
link: null,
|
|
10406
10423
|
payloadText: "",
|
|
@@ -10410,7 +10427,7 @@ var Share = {
|
|
|
10410
10427
|
}
|
|
10411
10428
|
const selected = candidates[share.mode];
|
|
10412
10429
|
if (selected?.link) {
|
|
10413
|
-
|
|
10430
|
+
logger17.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
10414
10431
|
return {
|
|
10415
10432
|
link: selected.link,
|
|
10416
10433
|
payloadText: selected.payloadText,
|
|
@@ -10423,7 +10440,7 @@ var Share = {
|
|
|
10423
10440
|
if (remaining <= 0) break;
|
|
10424
10441
|
const now = Date.now();
|
|
10425
10442
|
if (now >= nextProgressLogTs) {
|
|
10426
|
-
|
|
10443
|
+
logger17.info(
|
|
10427
10444
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
10428
10445
|
);
|
|
10429
10446
|
nextProgressLogTs = now + 5e3;
|
|
@@ -10431,11 +10448,11 @@ var Share = {
|
|
|
10431
10448
|
await (0, import_delay5.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10432
10449
|
}
|
|
10433
10450
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10434
|
-
|
|
10451
|
+
logger17.warning(
|
|
10435
10452
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
10436
10453
|
);
|
|
10437
10454
|
}
|
|
10438
|
-
|
|
10455
|
+
logger17.warning(
|
|
10439
10456
|
`captureLink ${timeoutDisabled ? "\u672A\u62FF\u5230\u94FE\u63A5" : "\u8D85\u65F6\u672A\u62FF\u5230\u94FE\u63A5"}: mode=${share.mode}, actionTimedOut=${stats.actionTimedOut}, domMutationCount=${stats.domMutationCount}, responseObserved=${stats.responseObserved}, responseMatched=${stats.responseMatched}, lastMatchedUrl=${stats.lastMatchedUrl || "none"}`
|
|
10440
10457
|
);
|
|
10441
10458
|
return {
|
|
@@ -10447,7 +10464,7 @@ var Share = {
|
|
|
10447
10464
|
} finally {
|
|
10448
10465
|
if (share.mode === "response") {
|
|
10449
10466
|
page.off("response", onResponse);
|
|
10450
|
-
|
|
10467
|
+
logger17.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10451
10468
|
}
|
|
10452
10469
|
await stopDomMonitor();
|
|
10453
10470
|
}
|