@skrillex1224/playwright-toolkit 3.0.35 → 3.0.37
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 +281 -247
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +281 -247
- 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 {
|
|
@@ -3981,9 +4015,9 @@ var Humanize = {
|
|
|
3981
4015
|
await (0, import_delay2.default)(this.jitterMs(800, 0.5));
|
|
3982
4016
|
}
|
|
3983
4017
|
}
|
|
3984
|
-
|
|
4018
|
+
logger6.success("warmUpBrowsing");
|
|
3985
4019
|
} catch (error) {
|
|
3986
|
-
|
|
4020
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3987
4021
|
throw error;
|
|
3988
4022
|
}
|
|
3989
4023
|
},
|
|
@@ -3997,7 +4031,7 @@ var Humanize = {
|
|
|
3997
4031
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3998
4032
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3999
4033
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
4000
|
-
|
|
4034
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
4001
4035
|
const sign = direction === "down" ? 1 : -1;
|
|
4002
4036
|
const stepDistance = actualDistance / steps;
|
|
4003
4037
|
try {
|
|
@@ -4009,9 +4043,9 @@ var Humanize = {
|
|
|
4009
4043
|
const baseDelay = 60 + i * 25;
|
|
4010
4044
|
await (0, import_delay2.default)(this.jitterMs(baseDelay, 0.3));
|
|
4011
4045
|
}
|
|
4012
|
-
|
|
4046
|
+
logger6.success("naturalScroll");
|
|
4013
4047
|
} catch (error) {
|
|
4014
|
-
|
|
4048
|
+
logger6.fail("naturalScroll", error);
|
|
4015
4049
|
throw error;
|
|
4016
4050
|
}
|
|
4017
4051
|
}
|
|
@@ -4040,7 +4074,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
4040
4074
|
var waitJitter = (base, jitterPercent = 0.3) => (0, import_delay3.default)(jitterMs(base, jitterPercent));
|
|
4041
4075
|
|
|
4042
4076
|
// src/internals/humanize/mobile.js
|
|
4043
|
-
var
|
|
4077
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
4044
4078
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
4045
4079
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
4046
4080
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4497,7 +4531,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4497
4531
|
}
|
|
4498
4532
|
return true;
|
|
4499
4533
|
} catch (error) {
|
|
4500
|
-
|
|
4534
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4501
4535
|
try {
|
|
4502
4536
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4503
4537
|
await waitJitter(120, 0.35);
|
|
@@ -4531,7 +4565,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4531
4565
|
);
|
|
4532
4566
|
return { method: "touchscreen" };
|
|
4533
4567
|
} catch (error) {
|
|
4534
|
-
|
|
4568
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4535
4569
|
if (!allowMouseFallback) throw error;
|
|
4536
4570
|
}
|
|
4537
4571
|
}
|
|
@@ -4547,10 +4581,10 @@ var MobileHumanize = {
|
|
|
4547
4581
|
async initializeCursor(page) {
|
|
4548
4582
|
if (initializedPages.has(page)) return;
|
|
4549
4583
|
initializedPages.add(page);
|
|
4550
|
-
|
|
4584
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4551
4585
|
},
|
|
4552
4586
|
async humanMove(page, target) {
|
|
4553
|
-
|
|
4587
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4554
4588
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4555
4589
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4556
4590
|
if (!element) {
|
|
@@ -4569,10 +4603,10 @@ var MobileHumanize = {
|
|
|
4569
4603
|
throwOnMissing = false
|
|
4570
4604
|
} = options;
|
|
4571
4605
|
const targetDesc = describeTarget(target);
|
|
4572
|
-
|
|
4606
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4573
4607
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4574
4608
|
if (!element) {
|
|
4575
|
-
|
|
4609
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4576
4610
|
return { element: null, didScroll: false, restore: null };
|
|
4577
4611
|
}
|
|
4578
4612
|
const startTime = Date.now();
|
|
@@ -4581,42 +4615,42 @@ var MobileHumanize = {
|
|
|
4581
4615
|
const status = await checkElementVisibility(element);
|
|
4582
4616
|
if (status.code === "VISIBLE") {
|
|
4583
4617
|
if (status.isFixed) {
|
|
4584
|
-
|
|
4618
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4585
4619
|
} else {
|
|
4586
|
-
|
|
4620
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4587
4621
|
}
|
|
4588
|
-
|
|
4622
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4589
4623
|
return { element, didScroll, restore: null };
|
|
4590
4624
|
}
|
|
4591
4625
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4592
|
-
|
|
4626
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4593
4627
|
return { element, didScroll, restore: null };
|
|
4594
4628
|
}
|
|
4595
4629
|
const scrollRect = await getScrollableRect(element);
|
|
4596
4630
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4597
|
-
|
|
4631
|
+
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
4632
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4599
4633
|
}
|
|
4600
4634
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4601
|
-
|
|
4635
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4602
4636
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4603
4637
|
}
|
|
4604
4638
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4605
4639
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4606
4640
|
if (moved.moved) {
|
|
4607
|
-
|
|
4641
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4608
4642
|
await waitJitter(90, 0.3);
|
|
4609
4643
|
didScroll = true;
|
|
4610
4644
|
continue;
|
|
4611
4645
|
}
|
|
4612
4646
|
}
|
|
4613
4647
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4614
|
-
|
|
4648
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4615
4649
|
return { element, didScroll, restore: null };
|
|
4616
4650
|
}
|
|
4617
4651
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4618
4652
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4619
|
-
|
|
4653
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4620
4654
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4621
4655
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4622
4656
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4657,7 +4691,7 @@ var MobileHumanize = {
|
|
|
4657
4691
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4658
4692
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4659
4693
|
await page.evaluate((state2) => window.scrollTo(state2.x, state2.y), beforeWindowState);
|
|
4660
|
-
|
|
4694
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4661
4695
|
}
|
|
4662
4696
|
}
|
|
4663
4697
|
let afterElementSnapshot = null;
|
|
@@ -4671,7 +4705,7 @@ var MobileHumanize = {
|
|
|
4671
4705
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4672
4706
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4673
4707
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4674
|
-
|
|
4708
|
+
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
4709
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4676
4710
|
}
|
|
4677
4711
|
}
|
|
@@ -4703,12 +4737,12 @@ var MobileHumanize = {
|
|
|
4703
4737
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4704
4738
|
if (!moved) {
|
|
4705
4739
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4706
|
-
|
|
4740
|
+
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
4741
|
} 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
4742
|
const residualDelta = expectedDelta - topDelta;
|
|
4709
4743
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4710
4744
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4711
|
-
|
|
4745
|
+
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
4746
|
}
|
|
4713
4747
|
}
|
|
4714
4748
|
}
|
|
@@ -4716,7 +4750,7 @@ var MobileHumanize = {
|
|
|
4716
4750
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4717
4751
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4718
4752
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4719
|
-
|
|
4753
|
+
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
4754
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4721
4755
|
}
|
|
4722
4756
|
}
|
|
@@ -4727,14 +4761,14 @@ var MobileHumanize = {
|
|
|
4727
4761
|
await waitJitter(80, 0.3);
|
|
4728
4762
|
const finalStatus = await checkElementVisibility(element);
|
|
4729
4763
|
if (finalStatus.code === "VISIBLE") {
|
|
4730
|
-
|
|
4731
|
-
|
|
4764
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4765
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4732
4766
|
return { element, didScroll: true, restore: null };
|
|
4733
4767
|
}
|
|
4734
4768
|
} catch (fallbackError) {
|
|
4735
|
-
|
|
4769
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4736
4770
|
}
|
|
4737
|
-
|
|
4771
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4738
4772
|
return { element, didScroll, restore: null };
|
|
4739
4773
|
},
|
|
4740
4774
|
async humanClick(page, target, options = {}) {
|
|
@@ -4749,7 +4783,7 @@ var MobileHumanize = {
|
|
|
4749
4783
|
fallbackDomClickOnTapError = true
|
|
4750
4784
|
} = options;
|
|
4751
4785
|
const targetDesc = describeTarget(target);
|
|
4752
|
-
|
|
4786
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4753
4787
|
try {
|
|
4754
4788
|
if (target == null) {
|
|
4755
4789
|
const viewport = resolveViewport(page);
|
|
@@ -4761,12 +4795,12 @@ var MobileHumanize = {
|
|
|
4761
4795
|
timeoutMs: tapTimeoutMs,
|
|
4762
4796
|
mouseFallbackTimeoutMs
|
|
4763
4797
|
});
|
|
4764
|
-
|
|
4798
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4765
4799
|
return true;
|
|
4766
4800
|
}
|
|
4767
4801
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4768
4802
|
if (!element) {
|
|
4769
|
-
|
|
4803
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4770
4804
|
return false;
|
|
4771
4805
|
}
|
|
4772
4806
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4790,19 +4824,19 @@ var MobileHumanize = {
|
|
|
4790
4824
|
).catch(() => null);
|
|
4791
4825
|
}
|
|
4792
4826
|
if (fallback?.activated) {
|
|
4793
|
-
|
|
4827
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4794
4828
|
return true;
|
|
4795
4829
|
}
|
|
4796
4830
|
}
|
|
4797
4831
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4798
4832
|
if (throwOnMissing) throw new Error(message);
|
|
4799
|
-
|
|
4833
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4800
4834
|
return false;
|
|
4801
4835
|
}
|
|
4802
4836
|
const box = await element.boundingBox();
|
|
4803
4837
|
if (!box) {
|
|
4804
4838
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4805
|
-
|
|
4839
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4806
4840
|
return false;
|
|
4807
4841
|
}
|
|
4808
4842
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4823,13 +4857,13 @@ var MobileHumanize = {
|
|
|
4823
4857
|
"activation fallback"
|
|
4824
4858
|
).catch(() => null);
|
|
4825
4859
|
if (!fallback?.activated) throw tapError;
|
|
4826
|
-
|
|
4860
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4827
4861
|
}
|
|
4828
4862
|
await waitJitter(120, 0.35);
|
|
4829
|
-
|
|
4863
|
+
logger7.success("humanClick");
|
|
4830
4864
|
return true;
|
|
4831
4865
|
} catch (error) {
|
|
4832
|
-
|
|
4866
|
+
logger7.fail("humanClick", error);
|
|
4833
4867
|
throw error;
|
|
4834
4868
|
}
|
|
4835
4869
|
},
|
|
@@ -4882,7 +4916,7 @@ var MobileHumanize = {
|
|
|
4882
4916
|
keyboardOptions = {}
|
|
4883
4917
|
} = pressOptions || {};
|
|
4884
4918
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4885
|
-
|
|
4919
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4886
4920
|
try {
|
|
4887
4921
|
if (hasTarget) {
|
|
4888
4922
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4896,10 +4930,10 @@ var MobileHumanize = {
|
|
|
4896
4930
|
...keyboardOptions,
|
|
4897
4931
|
delay: jitterMs(holdDelay, 0.5)
|
|
4898
4932
|
});
|
|
4899
|
-
|
|
4933
|
+
logger7.success("humanPress");
|
|
4900
4934
|
return true;
|
|
4901
4935
|
} catch (error) {
|
|
4902
|
-
|
|
4936
|
+
logger7.fail("humanPress", error);
|
|
4903
4937
|
throw error;
|
|
4904
4938
|
}
|
|
4905
4939
|
},
|
|
@@ -5058,7 +5092,7 @@ var import_fingerprint_injector = require("fingerprint-injector");
|
|
|
5058
5092
|
var import_playwright2 = require("playwright");
|
|
5059
5093
|
|
|
5060
5094
|
// src/proxy-bypass.js
|
|
5061
|
-
var
|
|
5095
|
+
var import_picomatch2 = __toESM(require("picomatch"), 1);
|
|
5062
5096
|
var normalizeByPassDomains = (domains) => {
|
|
5063
5097
|
if (!Array.isArray(domains)) return [];
|
|
5064
5098
|
return domains.map((item) => String(item || "").trim()).filter(Boolean);
|
|
@@ -5069,7 +5103,7 @@ var buildByPassDomainRule = (rawPattern) => {
|
|
|
5069
5103
|
if (!pattern) return null;
|
|
5070
5104
|
let matcher;
|
|
5071
5105
|
try {
|
|
5072
|
-
matcher = (0,
|
|
5106
|
+
matcher = (0, import_picomatch2.default)(pattern, { nocase: true });
|
|
5073
5107
|
} catch {
|
|
5074
5108
|
return null;
|
|
5075
5109
|
}
|
|
@@ -5138,7 +5172,7 @@ var ByPass = {
|
|
|
5138
5172
|
};
|
|
5139
5173
|
|
|
5140
5174
|
// src/internals/launch/traffic.js
|
|
5141
|
-
var
|
|
5175
|
+
var logger8 = createInternalLogger("Launch");
|
|
5142
5176
|
var normalizeObject = (value) => {
|
|
5143
5177
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5144
5178
|
return {};
|
|
@@ -5187,7 +5221,7 @@ var logLaunchTraffic = ({
|
|
|
5187
5221
|
} = {}) => {
|
|
5188
5222
|
if (!enabled) return;
|
|
5189
5223
|
if (explicitProxy) {
|
|
5190
|
-
|
|
5224
|
+
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
5225
|
return;
|
|
5192
5226
|
}
|
|
5193
5227
|
if (launchProxy) {
|
|
@@ -5197,18 +5231,18 @@ var logLaunchTraffic = ({
|
|
|
5197
5231
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5198
5232
|
} catch {
|
|
5199
5233
|
}
|
|
5200
|
-
|
|
5234
|
+
logger8.info(
|
|
5201
5235
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
5202
5236
|
);
|
|
5203
|
-
|
|
5237
|
+
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
5238
|
return;
|
|
5205
5239
|
}
|
|
5206
5240
|
if (enableProxy) {
|
|
5207
|
-
|
|
5241
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5208
5242
|
} else if (proxyUrl) {
|
|
5209
|
-
|
|
5243
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5210
5244
|
}
|
|
5211
|
-
|
|
5245
|
+
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
5246
|
};
|
|
5213
5247
|
var createLaunchTrafficHook = ({
|
|
5214
5248
|
byPassDomains = [],
|
|
@@ -5231,13 +5265,13 @@ var createLaunchTrafficHook = ({
|
|
|
5231
5265
|
}
|
|
5232
5266
|
if (!enabled || byPassDomains.length === 0) return;
|
|
5233
5267
|
if (!matched || !matched.rule) return;
|
|
5234
|
-
|
|
5268
|
+
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
5269
|
});
|
|
5236
5270
|
};
|
|
5237
5271
|
};
|
|
5238
5272
|
|
|
5239
5273
|
// src/internals/launch/default.js
|
|
5240
|
-
var
|
|
5274
|
+
var logger9 = createInternalLogger("Launch");
|
|
5241
5275
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
5242
5276
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
5243
5277
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -5278,7 +5312,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5278
5312
|
});
|
|
5279
5313
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5280
5314
|
} catch (error) {
|
|
5281
|
-
|
|
5315
|
+
logger9.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5282
5316
|
}
|
|
5283
5317
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5284
5318
|
return detectedVersion;
|
|
@@ -5315,7 +5349,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5315
5349
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5316
5350
|
throw error;
|
|
5317
5351
|
}
|
|
5318
|
-
|
|
5352
|
+
logger9.warn(
|
|
5319
5353
|
`\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
5354
|
);
|
|
5321
5355
|
}
|
|
@@ -5361,7 +5395,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5361
5395
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5362
5396
|
};
|
|
5363
5397
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5364
|
-
|
|
5398
|
+
logger9.info(
|
|
5365
5399
|
`\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
5400
|
);
|
|
5367
5401
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5548,7 +5582,7 @@ var DefaultLaunch = {
|
|
|
5548
5582
|
var import_node_child_process2 = require("node:child_process");
|
|
5549
5583
|
var import_node_crypto = require("node:crypto");
|
|
5550
5584
|
var import_node_util = require("node:util");
|
|
5551
|
-
var
|
|
5585
|
+
var logger10 = createInternalLogger("Launch");
|
|
5552
5586
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5553
5587
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5554
5588
|
maxConcurrency: 1,
|
|
@@ -5754,7 +5788,7 @@ var resolveReplayableCloakProfile = (runtimeState, { fingerprintPlatform = "", c
|
|
|
5754
5788
|
const nextCoreRaw = JSON.stringify(nextBrowserProfileCore);
|
|
5755
5789
|
if (currentCoreRaw !== nextCoreRaw) {
|
|
5756
5790
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, nextBrowserProfileCore);
|
|
5757
|
-
|
|
5791
|
+
logger10.info(
|
|
5758
5792
|
`\u5DF2\u540C\u6B65 Cloak \u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | seed=${fingerprintSeed} | platform=${resolvedFingerprintPlatform} | timezone=${timezone || "-"} | locale=${locale || "-"}`
|
|
5759
5793
|
);
|
|
5760
5794
|
}
|
|
@@ -5841,7 +5875,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5841
5875
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5842
5876
|
return;
|
|
5843
5877
|
}
|
|
5844
|
-
|
|
5878
|
+
logger10.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5845
5879
|
});
|
|
5846
5880
|
};
|
|
5847
5881
|
var CloakLaunch = {
|
|
@@ -6001,7 +6035,7 @@ var Launch = withModeReflect("Launch", launchStrategies);
|
|
|
6001
6035
|
// src/live-view.js
|
|
6002
6036
|
var import_express = __toESM(require("express"), 1);
|
|
6003
6037
|
var import_apify = require("apify");
|
|
6004
|
-
var
|
|
6038
|
+
var logger11 = createInternalLogger("LiveView");
|
|
6005
6039
|
async function startLiveViewServer(liveViewKey) {
|
|
6006
6040
|
const app = (0, import_express.default)();
|
|
6007
6041
|
app.get("/", async (req, res) => {
|
|
@@ -6026,13 +6060,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
6026
6060
|
</html>
|
|
6027
6061
|
`);
|
|
6028
6062
|
} catch (error) {
|
|
6029
|
-
|
|
6063
|
+
logger11.fail("Live View Server", error);
|
|
6030
6064
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
6031
6065
|
}
|
|
6032
6066
|
});
|
|
6033
6067
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
6034
6068
|
app.listen(port, () => {
|
|
6035
|
-
|
|
6069
|
+
logger11.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
6036
6070
|
});
|
|
6037
6071
|
}
|
|
6038
6072
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -6040,10 +6074,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
6040
6074
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
6041
6075
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
6042
6076
|
if (logMessage) {
|
|
6043
|
-
|
|
6077
|
+
logger11.info(`(\u622A\u56FE): ${logMessage}`);
|
|
6044
6078
|
}
|
|
6045
6079
|
} catch (e) {
|
|
6046
|
-
|
|
6080
|
+
logger11.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
6047
6081
|
}
|
|
6048
6082
|
}
|
|
6049
6083
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -6149,7 +6183,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
6149
6183
|
};
|
|
6150
6184
|
|
|
6151
6185
|
// src/internals/captcha/bytedance.js
|
|
6152
|
-
var
|
|
6186
|
+
var logger12 = createInternalLogger("Captcha");
|
|
6153
6187
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
6154
6188
|
apiType: "31234",
|
|
6155
6189
|
maxRetries: 3,
|
|
@@ -6281,7 +6315,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
6281
6315
|
}
|
|
6282
6316
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
6283
6317
|
}
|
|
6284
|
-
|
|
6318
|
+
logger12.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
6285
6319
|
};
|
|
6286
6320
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
6287
6321
|
if (!options.debugArtifacts) {
|
|
@@ -6318,14 +6352,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6318
6352
|
if (!isContainerVisible) {
|
|
6319
6353
|
return null;
|
|
6320
6354
|
}
|
|
6321
|
-
|
|
6355
|
+
logger12.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
6322
6356
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
6323
6357
|
let isIframeVisible = await waitForVisible(
|
|
6324
6358
|
iframeLocator,
|
|
6325
6359
|
options.iframeVisibleTimeoutMs
|
|
6326
6360
|
);
|
|
6327
6361
|
if (!isIframeVisible) {
|
|
6328
|
-
|
|
6362
|
+
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
6363
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
6330
6364
|
isIframeVisible = await waitForVisible(
|
|
6331
6365
|
iframeLocator,
|
|
@@ -6335,7 +6369,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6335
6369
|
if (!isIframeVisible) {
|
|
6336
6370
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
6337
6371
|
}
|
|
6338
|
-
|
|
6372
|
+
logger12.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
6339
6373
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
6340
6374
|
if (!frame) {
|
|
6341
6375
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -6451,11 +6485,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
6451
6485
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
6452
6486
|
...options,
|
|
6453
6487
|
page,
|
|
6454
|
-
logger:
|
|
6488
|
+
logger: logger12,
|
|
6455
6489
|
forceMouse: true
|
|
6456
6490
|
}).catch(() => false);
|
|
6457
6491
|
if (!clicked) {
|
|
6458
|
-
|
|
6492
|
+
logger12.warn("Refresh button not found.");
|
|
6459
6493
|
return false;
|
|
6460
6494
|
}
|
|
6461
6495
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6486,24 +6520,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6486
6520
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6487
6521
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6488
6522
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6489
|
-
|
|
6523
|
+
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
6524
|
hasLoggedGuideMask = true;
|
|
6491
6525
|
}
|
|
6492
6526
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6493
|
-
|
|
6527
|
+
logger12.info(
|
|
6494
6528
|
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
6529
|
);
|
|
6496
6530
|
return;
|
|
6497
6531
|
}
|
|
6498
6532
|
if (hasErrorTextVisible) {
|
|
6499
|
-
|
|
6533
|
+
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
6534
|
await refreshCaptcha(page, frame, options);
|
|
6501
6535
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6502
6536
|
hasSeenLoading = false;
|
|
6503
6537
|
continue;
|
|
6504
6538
|
}
|
|
6505
6539
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6506
|
-
|
|
6540
|
+
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
6541
|
await refreshCaptcha(page, frame, options);
|
|
6508
6542
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6509
6543
|
hasSeenLoading = false;
|
|
@@ -6551,7 +6585,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6551
6585
|
accepted
|
|
6552
6586
|
};
|
|
6553
6587
|
dragAttempts.push(attemptInfo);
|
|
6554
|
-
|
|
6588
|
+
logger12.info(
|
|
6555
6589
|
`\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
6590
|
);
|
|
6557
6591
|
if (accepted) {
|
|
@@ -6569,7 +6603,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6569
6603
|
dragAttempts,
|
|
6570
6604
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6571
6605
|
}).catch((error) => {
|
|
6572
|
-
|
|
6606
|
+
logger12.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6573
6607
|
});
|
|
6574
6608
|
return {
|
|
6575
6609
|
accepted: false,
|
|
@@ -6586,16 +6620,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6586
6620
|
...options
|
|
6587
6621
|
};
|
|
6588
6622
|
if (!config.token) {
|
|
6589
|
-
|
|
6623
|
+
logger12.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6590
6624
|
return false;
|
|
6591
6625
|
}
|
|
6592
|
-
|
|
6626
|
+
logger12.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6593
6627
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6594
|
-
|
|
6628
|
+
logger12.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6595
6629
|
try {
|
|
6596
6630
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6597
6631
|
if (!captchaContext) {
|
|
6598
|
-
|
|
6632
|
+
logger12.info("Captcha container is not visible anymore.");
|
|
6599
6633
|
return true;
|
|
6600
6634
|
}
|
|
6601
6635
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6608,7 +6642,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6608
6642
|
"ready",
|
|
6609
6643
|
config
|
|
6610
6644
|
).catch((error) => {
|
|
6611
|
-
|
|
6645
|
+
logger12.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6612
6646
|
});
|
|
6613
6647
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6614
6648
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6620,16 +6654,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6620
6654
|
});
|
|
6621
6655
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6622
6656
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6623
|
-
|
|
6657
|
+
logger12.warn(
|
|
6624
6658
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6625
6659
|
);
|
|
6626
6660
|
await refreshCaptcha(page, frame, config);
|
|
6627
6661
|
continue;
|
|
6628
6662
|
}
|
|
6629
|
-
|
|
6663
|
+
logger12.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6630
6664
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6631
6665
|
if (!dropTarget) {
|
|
6632
|
-
|
|
6666
|
+
logger12.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6633
6667
|
await refreshCaptcha(page, frame, config);
|
|
6634
6668
|
continue;
|
|
6635
6669
|
}
|
|
@@ -6640,7 +6674,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6640
6674
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6641
6675
|
);
|
|
6642
6676
|
}
|
|
6643
|
-
|
|
6677
|
+
logger12.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6644
6678
|
for (const imageIndex of normalizedIndexes) {
|
|
6645
6679
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6646
6680
|
throw new Error(
|
|
@@ -6672,52 +6706,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6672
6706
|
}
|
|
6673
6707
|
}
|
|
6674
6708
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6675
|
-
|
|
6709
|
+
logger12.info(
|
|
6676
6710
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6677
6711
|
);
|
|
6678
6712
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6679
6713
|
...config,
|
|
6680
6714
|
page,
|
|
6681
|
-
logger:
|
|
6715
|
+
logger: logger12,
|
|
6682
6716
|
forceMouse: true,
|
|
6683
6717
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6684
6718
|
}).catch(() => false);
|
|
6685
6719
|
if (!submitted) {
|
|
6686
|
-
|
|
6720
|
+
logger12.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6687
6721
|
}
|
|
6688
6722
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6689
6723
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6690
|
-
|
|
6724
|
+
logger12.info(
|
|
6691
6725
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6692
6726
|
);
|
|
6693
6727
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6694
6728
|
if (!stillVisible) {
|
|
6695
|
-
|
|
6729
|
+
logger12.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6696
6730
|
return true;
|
|
6697
6731
|
}
|
|
6698
6732
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6699
6733
|
beforeSubmitState,
|
|
6700
6734
|
afterSubmitState
|
|
6701
6735
|
}).catch((error) => {
|
|
6702
|
-
|
|
6736
|
+
logger12.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6703
6737
|
});
|
|
6704
|
-
|
|
6738
|
+
logger12.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6705
6739
|
await page.waitForTimeout(2e3);
|
|
6706
6740
|
await refreshCaptcha(page, frame, config);
|
|
6707
6741
|
} catch (error) {
|
|
6708
|
-
|
|
6742
|
+
logger12.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6709
6743
|
}
|
|
6710
6744
|
if (attempt < config.maxRetries) {
|
|
6711
6745
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6712
6746
|
}
|
|
6713
6747
|
}
|
|
6714
|
-
|
|
6748
|
+
logger12.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6715
6749
|
return false;
|
|
6716
6750
|
}
|
|
6717
6751
|
var sloveCaptcha = solveCaptcha;
|
|
6718
6752
|
|
|
6719
6753
|
// src/chaptcha.js
|
|
6720
|
-
var
|
|
6754
|
+
var logger13 = createInternalLogger("Captcha");
|
|
6721
6755
|
var DOM_MONITOR_WAIT_TIMEOUT_MS = 1e3;
|
|
6722
6756
|
var DOM_MONITOR_POST_DETECT_HIDDEN_WAIT_MS = 300;
|
|
6723
6757
|
var DOM_MONITOR_RECOVERY_WAIT_MS = 100;
|
|
@@ -6792,7 +6826,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6792
6826
|
await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
|
|
6793
6827
|
continue;
|
|
6794
6828
|
}
|
|
6795
|
-
|
|
6829
|
+
logger13.warning(
|
|
6796
6830
|
"useCaptchaMonitor",
|
|
6797
6831
|
`DOM \u76D1\u63A7\u51FA\u73B0\u5F02\u5E38\uFF08\u7EE7\u7EED\u91CD\u8BD5\uFF09: selector=${domSelector}, error=${getErrorMessage(error)}`
|
|
6798
6832
|
);
|
|
@@ -6800,7 +6834,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6800
6834
|
}
|
|
6801
6835
|
}
|
|
6802
6836
|
})();
|
|
6803
|
-
|
|
6837
|
+
logger13.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6804
6838
|
cleanupFns.push(async () => {
|
|
6805
6839
|
await domMonitorTask?.catch(() => {
|
|
6806
6840
|
});
|
|
@@ -6817,7 +6851,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6817
6851
|
}
|
|
6818
6852
|
};
|
|
6819
6853
|
page.on("framenavigated", frameHandler);
|
|
6820
|
-
|
|
6854
|
+
logger13.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6821
6855
|
Promise.resolve().then(async () => {
|
|
6822
6856
|
if (!isStopped && page.url().includes(urlPattern)) {
|
|
6823
6857
|
await triggerDetected();
|
|
@@ -6830,7 +6864,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6830
6864
|
}
|
|
6831
6865
|
return {
|
|
6832
6866
|
stop: async () => {
|
|
6833
|
-
|
|
6867
|
+
logger13.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6834
6868
|
isStopped = true;
|
|
6835
6869
|
for (const fn of cleanupFns) {
|
|
6836
6870
|
await fn();
|
|
@@ -6869,7 +6903,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6869
6903
|
);
|
|
6870
6904
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6871
6905
|
callCaptchaRecognitionApi,
|
|
6872
|
-
logger:
|
|
6906
|
+
logger: logger13
|
|
6873
6907
|
});
|
|
6874
6908
|
}
|
|
6875
6909
|
var Captcha = {
|
|
@@ -6880,7 +6914,7 @@ var Captcha = {
|
|
|
6880
6914
|
// src/mutation.js
|
|
6881
6915
|
var import_node_crypto2 = require("node:crypto");
|
|
6882
6916
|
var import_uuid = require("uuid");
|
|
6883
|
-
var
|
|
6917
|
+
var logger14 = createInternalLogger("Mutation");
|
|
6884
6918
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6885
6919
|
Added: "added",
|
|
6886
6920
|
Changed: "changed",
|
|
@@ -6913,14 +6947,14 @@ var Mutation = {
|
|
|
6913
6947
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6914
6948
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6915
6949
|
const onMutation = options.onMutation;
|
|
6916
|
-
|
|
6950
|
+
logger14.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6917
6951
|
if (initialTimeout > 0) {
|
|
6918
6952
|
const selectorQuery = selectorList.join(",");
|
|
6919
6953
|
try {
|
|
6920
6954
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6921
|
-
|
|
6955
|
+
logger14.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6922
6956
|
} catch (e) {
|
|
6923
|
-
|
|
6957
|
+
logger14.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6924
6958
|
throw e;
|
|
6925
6959
|
}
|
|
6926
6960
|
}
|
|
@@ -6936,7 +6970,7 @@ var Mutation = {
|
|
|
6936
6970
|
return "__CONTINUE__";
|
|
6937
6971
|
}
|
|
6938
6972
|
});
|
|
6939
|
-
|
|
6973
|
+
logger14.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6940
6974
|
} catch (e) {
|
|
6941
6975
|
}
|
|
6942
6976
|
}
|
|
@@ -7051,9 +7085,9 @@ var Mutation = {
|
|
|
7051
7085
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
7052
7086
|
);
|
|
7053
7087
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
7054
|
-
|
|
7088
|
+
logger14.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7055
7089
|
}
|
|
7056
|
-
|
|
7090
|
+
logger14.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7057
7091
|
return result;
|
|
7058
7092
|
},
|
|
7059
7093
|
/**
|
|
@@ -7225,22 +7259,22 @@ var Mutation = {
|
|
|
7225
7259
|
return "__CONTINUE__";
|
|
7226
7260
|
}
|
|
7227
7261
|
};
|
|
7228
|
-
|
|
7262
|
+
logger14.start(
|
|
7229
7263
|
"waitForStableAcrossRoots",
|
|
7230
7264
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
7231
7265
|
);
|
|
7232
7266
|
if (initialTimeout > 0) {
|
|
7233
7267
|
try {
|
|
7234
7268
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
7235
|
-
|
|
7269
|
+
logger14.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
7236
7270
|
} catch (e) {
|
|
7237
|
-
|
|
7271
|
+
logger14.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
7238
7272
|
throw e;
|
|
7239
7273
|
}
|
|
7240
7274
|
}
|
|
7241
7275
|
let state2 = await buildState();
|
|
7242
7276
|
if (!state2?.hasMatched) {
|
|
7243
|
-
|
|
7277
|
+
logger14.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7244
7278
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
7245
7279
|
}
|
|
7246
7280
|
let mutationCount = 0;
|
|
@@ -7277,7 +7311,7 @@ var Mutation = {
|
|
|
7277
7311
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
7278
7312
|
lastSnapshotKey = lastState.snapshotKey;
|
|
7279
7313
|
mutationCount += 1;
|
|
7280
|
-
|
|
7314
|
+
logger14.info(
|
|
7281
7315
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
7282
7316
|
);
|
|
7283
7317
|
const signal = await invokeMutationCallback({
|
|
@@ -7290,7 +7324,7 @@ var Mutation = {
|
|
|
7290
7324
|
continue;
|
|
7291
7325
|
}
|
|
7292
7326
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
7293
|
-
|
|
7327
|
+
logger14.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7294
7328
|
return {
|
|
7295
7329
|
mutationCount,
|
|
7296
7330
|
stableTime: waitForStableTime,
|
|
@@ -7317,7 +7351,7 @@ var Mutation = {
|
|
|
7317
7351
|
const onMutation = options.onMutation;
|
|
7318
7352
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
7319
7353
|
const mode2 = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
7320
|
-
|
|
7354
|
+
logger14.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode2}`);
|
|
7321
7355
|
const monitorKey = generateKey("pk_mon");
|
|
7322
7356
|
const callbackName = generateKey("pk_mon_cb");
|
|
7323
7357
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7460,7 +7494,7 @@ var Mutation = {
|
|
|
7460
7494
|
return total;
|
|
7461
7495
|
};
|
|
7462
7496
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode: mode2 });
|
|
7463
|
-
|
|
7497
|
+
logger14.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7464
7498
|
return {
|
|
7465
7499
|
stop: async () => {
|
|
7466
7500
|
let totalMutations = 0;
|
|
@@ -7473,7 +7507,7 @@ var Mutation = {
|
|
|
7473
7507
|
}, cleanerName);
|
|
7474
7508
|
} catch (e) {
|
|
7475
7509
|
}
|
|
7476
|
-
|
|
7510
|
+
logger14.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7477
7511
|
return { totalMutations };
|
|
7478
7512
|
}
|
|
7479
7513
|
};
|
|
@@ -8342,7 +8376,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
8342
8376
|
};
|
|
8343
8377
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
8344
8378
|
var Logger = {
|
|
8345
|
-
setLogger: (
|
|
8379
|
+
setLogger: (logger18) => setDefaultLogger(logger18),
|
|
8346
8380
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
8347
8381
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
8348
8382
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -8350,8 +8384,8 @@ var Logger = {
|
|
|
8350
8384
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
8351
8385
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
8352
8386
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
8353
|
-
useTemplate: (
|
|
8354
|
-
if (
|
|
8387
|
+
useTemplate: (logger18) => {
|
|
8388
|
+
if (logger18) return createTemplateLogger(createBaseLogger("", logger18));
|
|
8355
8389
|
return createTemplateLogger();
|
|
8356
8390
|
}
|
|
8357
8391
|
};
|
|
@@ -8425,7 +8459,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
8425
8459
|
];
|
|
8426
8460
|
var cachedStripLogoSrcPromise = null;
|
|
8427
8461
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
8428
|
-
var
|
|
8462
|
+
var logger15 = createInternalLogger("Watermarkify");
|
|
8429
8463
|
var normalizeText2 = (value) => String(value || "").trim();
|
|
8430
8464
|
var toInline = (value, maxLen = 200) => {
|
|
8431
8465
|
const text = normalizeText2(value);
|
|
@@ -8667,9 +8701,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8667
8701
|
location: toInline(resolved.location, 80)
|
|
8668
8702
|
};
|
|
8669
8703
|
if (enrichment.ip || enrichment.location) {
|
|
8670
|
-
|
|
8704
|
+
logger15.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8671
8705
|
} else {
|
|
8672
|
-
|
|
8706
|
+
logger15.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8673
8707
|
}
|
|
8674
8708
|
return enrichment;
|
|
8675
8709
|
} finally {
|
|
@@ -8858,12 +8892,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8858
8892
|
};
|
|
8859
8893
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8860
8894
|
if (!page || typeof page.context !== "function") {
|
|
8861
|
-
|
|
8895
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8862
8896
|
return buffer;
|
|
8863
8897
|
}
|
|
8864
8898
|
const renderScope = await openProbePage(page);
|
|
8865
8899
|
if (!renderScope?.page) {
|
|
8866
|
-
|
|
8900
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8867
8901
|
return buffer;
|
|
8868
8902
|
}
|
|
8869
8903
|
try {
|
|
@@ -8928,13 +8962,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8928
8962
|
fullPage: true,
|
|
8929
8963
|
animations: "disabled"
|
|
8930
8964
|
}).catch((error) => {
|
|
8931
|
-
|
|
8965
|
+
logger15.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8932
8966
|
return null;
|
|
8933
8967
|
});
|
|
8934
8968
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8935
8969
|
return composed;
|
|
8936
8970
|
}
|
|
8937
|
-
|
|
8971
|
+
logger15.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8938
8972
|
return buffer;
|
|
8939
8973
|
} finally {
|
|
8940
8974
|
await renderScope.close().catch(() => {
|
|
@@ -8947,7 +8981,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8947
8981
|
}
|
|
8948
8982
|
const probeScope = await openProbePage(page);
|
|
8949
8983
|
if (!probeScope?.page) {
|
|
8950
|
-
|
|
8984
|
+
logger15.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8951
8985
|
return null;
|
|
8952
8986
|
}
|
|
8953
8987
|
const timeoutMs = Math.max(
|
|
@@ -8956,12 +8990,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8956
8990
|
);
|
|
8957
8991
|
try {
|
|
8958
8992
|
const probePage = probeScope.page;
|
|
8959
|
-
|
|
8993
|
+
logger15.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8960
8994
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8961
8995
|
waitUntil: "commit",
|
|
8962
8996
|
timeout: timeoutMs
|
|
8963
8997
|
}).catch((error) => {
|
|
8964
|
-
|
|
8998
|
+
logger15.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8965
8999
|
return null;
|
|
8966
9000
|
});
|
|
8967
9001
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8983,13 +9017,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8983
9017
|
}
|
|
8984
9018
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8985
9019
|
if (parsed?.ip || parsed?.location) {
|
|
8986
|
-
|
|
9020
|
+
logger15.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8987
9021
|
return parsed;
|
|
8988
9022
|
}
|
|
8989
|
-
|
|
9023
|
+
logger15.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8990
9024
|
return null;
|
|
8991
9025
|
} catch (error) {
|
|
8992
|
-
|
|
9026
|
+
logger15.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8993
9027
|
return null;
|
|
8994
9028
|
} finally {
|
|
8995
9029
|
await probeScope.close().catch(() => {
|
|
@@ -9003,10 +9037,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
9003
9037
|
ip: toInline(options.ip, 80),
|
|
9004
9038
|
location: toInline(options.location, 80)
|
|
9005
9039
|
};
|
|
9006
|
-
|
|
9040
|
+
logger15.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
9007
9041
|
if (!merged.ip || !merged.location) {
|
|
9008
9042
|
if (cached?.ip || cached?.location) {
|
|
9009
|
-
|
|
9043
|
+
logger15.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
9010
9044
|
}
|
|
9011
9045
|
fillEnrichment(merged, cached);
|
|
9012
9046
|
}
|
|
@@ -9030,15 +9064,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
9030
9064
|
"x-geo-country"
|
|
9031
9065
|
]), 80);
|
|
9032
9066
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
9033
|
-
|
|
9067
|
+
logger15.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
9034
9068
|
merged.location = headerLocation || merged.location;
|
|
9035
9069
|
}
|
|
9036
9070
|
}
|
|
9037
9071
|
writeCachedEnrichment(page, merged);
|
|
9038
9072
|
if (merged.ip || merged.location) {
|
|
9039
|
-
|
|
9073
|
+
logger15.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
9040
9074
|
} else {
|
|
9041
|
-
|
|
9075
|
+
logger15.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
9042
9076
|
}
|
|
9043
9077
|
return merged;
|
|
9044
9078
|
};
|
|
@@ -9851,7 +9885,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9851
9885
|
}
|
|
9852
9886
|
const imageInfo = readImageInfo(buffer);
|
|
9853
9887
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9854
|
-
|
|
9888
|
+
logger15.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9855
9889
|
return buffer;
|
|
9856
9890
|
}
|
|
9857
9891
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9869,7 +9903,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9869
9903
|
|
|
9870
9904
|
// src/internals/compression.js
|
|
9871
9905
|
var import_jimp2 = require("jimp");
|
|
9872
|
-
var
|
|
9906
|
+
var logger16 = createInternalLogger("Compression");
|
|
9873
9907
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9874
9908
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9875
9909
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9988,18 +10022,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9988
10022
|
return buffer.toString("base64");
|
|
9989
10023
|
}
|
|
9990
10024
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9991
|
-
|
|
10025
|
+
logger16.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9992
10026
|
return null;
|
|
9993
10027
|
});
|
|
9994
10028
|
if (!result?.buffer) {
|
|
9995
10029
|
return buffer.toString("base64");
|
|
9996
10030
|
}
|
|
9997
10031
|
if (result.withinLimit) {
|
|
9998
|
-
|
|
10032
|
+
logger16.info(
|
|
9999
10033
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
10000
10034
|
);
|
|
10001
10035
|
} else {
|
|
10002
|
-
|
|
10036
|
+
logger16.warning(
|
|
10003
10037
|
`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
10038
|
);
|
|
10005
10039
|
}
|
|
@@ -10007,7 +10041,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
10007
10041
|
};
|
|
10008
10042
|
|
|
10009
10043
|
// src/share.js
|
|
10010
|
-
var
|
|
10044
|
+
var logger17 = createInternalLogger("Share");
|
|
10011
10045
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
10012
10046
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
10013
10047
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -10144,7 +10178,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
10144
10178
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
10145
10179
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
10146
10180
|
let matched = false;
|
|
10147
|
-
|
|
10181
|
+
logger17.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode2}`);
|
|
10148
10182
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
10149
10183
|
mode: mode2,
|
|
10150
10184
|
onMutation: (context = {}) => {
|
|
@@ -10162,12 +10196,12 @@ ${text}`;
|
|
|
10162
10196
|
});
|
|
10163
10197
|
}
|
|
10164
10198
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
10165
|
-
|
|
10199
|
+
logger17.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
10166
10200
|
}
|
|
10167
10201
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
10168
10202
|
if (!candidate) return;
|
|
10169
10203
|
matched = true;
|
|
10170
|
-
|
|
10204
|
+
logger17.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
10171
10205
|
if (onMatch) {
|
|
10172
10206
|
onMatch({
|
|
10173
10207
|
link: candidate,
|
|
@@ -10183,7 +10217,7 @@ ${text}`;
|
|
|
10183
10217
|
return {
|
|
10184
10218
|
stop: async () => {
|
|
10185
10219
|
const result = await monitor.stop();
|
|
10186
|
-
|
|
10220
|
+
logger17.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
10187
10221
|
return result;
|
|
10188
10222
|
}
|
|
10189
10223
|
};
|
|
@@ -10232,8 +10266,8 @@ var Share = {
|
|
|
10232
10266
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
10233
10267
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
10234
10268
|
}
|
|
10235
|
-
|
|
10236
|
-
|
|
10269
|
+
logger17.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
10270
|
+
logger17.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
10237
10271
|
const stats = {
|
|
10238
10272
|
actionTimedOut: false,
|
|
10239
10273
|
domMutationCount: 0,
|
|
@@ -10245,7 +10279,7 @@ var Share = {
|
|
|
10245
10279
|
responseSampleUrls: []
|
|
10246
10280
|
};
|
|
10247
10281
|
if (isAborted()) {
|
|
10248
|
-
|
|
10282
|
+
logger17.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10249
10283
|
return {
|
|
10250
10284
|
link: null,
|
|
10251
10285
|
payloadText: "",
|
|
@@ -10268,7 +10302,7 @@ var Share = {
|
|
|
10268
10302
|
link: validated,
|
|
10269
10303
|
payloadText: String(payloadText || "")
|
|
10270
10304
|
};
|
|
10271
|
-
|
|
10305
|
+
logger17.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
10272
10306
|
return true;
|
|
10273
10307
|
};
|
|
10274
10308
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -10303,7 +10337,7 @@ var Share = {
|
|
|
10303
10337
|
try {
|
|
10304
10338
|
await monitor.stop();
|
|
10305
10339
|
} catch (error) {
|
|
10306
|
-
|
|
10340
|
+
logger17.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
10307
10341
|
}
|
|
10308
10342
|
};
|
|
10309
10343
|
const onResponse = async (response) => {
|
|
@@ -10317,29 +10351,29 @@ var Share = {
|
|
|
10317
10351
|
stats.responseSampleUrls.push(url);
|
|
10318
10352
|
}
|
|
10319
10353
|
if (stats.responseObserved <= 5) {
|
|
10320
|
-
|
|
10354
|
+
logger17.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
10321
10355
|
}
|
|
10322
10356
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
10323
10357
|
stats.responseMatched += 1;
|
|
10324
10358
|
stats.lastMatchedUrl = url;
|
|
10325
|
-
|
|
10359
|
+
logger17.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
10326
10360
|
const text = await response.text();
|
|
10327
10361
|
const hit = resolveResponseCandidate(text);
|
|
10328
10362
|
if (!hit?.link) {
|
|
10329
10363
|
if (stats.responseMatched <= 3) {
|
|
10330
|
-
|
|
10364
|
+
logger17.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
10331
10365
|
}
|
|
10332
10366
|
return;
|
|
10333
10367
|
}
|
|
10334
10368
|
stats.responseResolved += 1;
|
|
10335
|
-
|
|
10369
|
+
logger17.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
10336
10370
|
setCandidate("response", hit.link, hit.payloadText);
|
|
10337
10371
|
} catch (error) {
|
|
10338
|
-
|
|
10372
|
+
logger17.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
10339
10373
|
}
|
|
10340
10374
|
};
|
|
10341
10375
|
if (share.mode === "dom") {
|
|
10342
|
-
|
|
10376
|
+
logger17.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
10343
10377
|
domMonitor = await createDomShareMonitor(page, {
|
|
10344
10378
|
prefix: share.prefix,
|
|
10345
10379
|
selectors: domSelectors,
|
|
@@ -10354,17 +10388,17 @@ var Share = {
|
|
|
10354
10388
|
});
|
|
10355
10389
|
}
|
|
10356
10390
|
if (share.mode === "response") {
|
|
10357
|
-
|
|
10391
|
+
logger17.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
10358
10392
|
page.on("response", onResponse);
|
|
10359
10393
|
}
|
|
10360
10394
|
if (share.mode === "custom") {
|
|
10361
|
-
|
|
10395
|
+
logger17.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
10362
10396
|
}
|
|
10363
10397
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
10364
10398
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
10365
10399
|
try {
|
|
10366
10400
|
const actionTimeout = getRemainingMs();
|
|
10367
|
-
|
|
10401
|
+
logger17.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
10368
10402
|
let actionValue;
|
|
10369
10403
|
if (!isAborted() && actionTimeout > 0) {
|
|
10370
10404
|
let timer = null;
|
|
@@ -10377,30 +10411,30 @@ var Share = {
|
|
|
10377
10411
|
]);
|
|
10378
10412
|
if (timer) clearTimeout(timer);
|
|
10379
10413
|
if (actionResult.type === "error") {
|
|
10380
|
-
|
|
10414
|
+
logger17.fail("captureLink.performActions", actionResult.error);
|
|
10381
10415
|
throw actionResult.error;
|
|
10382
10416
|
}
|
|
10383
10417
|
if (actionResult.type === "timeout") {
|
|
10384
10418
|
stats.actionTimedOut = true;
|
|
10385
|
-
|
|
10419
|
+
logger17.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
10386
10420
|
} else {
|
|
10387
10421
|
actionValue = actionResult.result;
|
|
10388
|
-
|
|
10422
|
+
logger17.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
10389
10423
|
}
|
|
10390
10424
|
}
|
|
10391
10425
|
if (share.mode === "custom") {
|
|
10392
10426
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
10393
10427
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
10394
10428
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
10395
|
-
|
|
10429
|
+
logger17.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
10396
10430
|
} else {
|
|
10397
|
-
|
|
10431
|
+
logger17.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
10398
10432
|
}
|
|
10399
10433
|
}
|
|
10400
10434
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
10401
10435
|
while (true) {
|
|
10402
10436
|
if (isAborted()) {
|
|
10403
|
-
|
|
10437
|
+
logger17.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10404
10438
|
return {
|
|
10405
10439
|
link: null,
|
|
10406
10440
|
payloadText: "",
|
|
@@ -10410,7 +10444,7 @@ var Share = {
|
|
|
10410
10444
|
}
|
|
10411
10445
|
const selected = candidates[share.mode];
|
|
10412
10446
|
if (selected?.link) {
|
|
10413
|
-
|
|
10447
|
+
logger17.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
10414
10448
|
return {
|
|
10415
10449
|
link: selected.link,
|
|
10416
10450
|
payloadText: selected.payloadText,
|
|
@@ -10423,7 +10457,7 @@ var Share = {
|
|
|
10423
10457
|
if (remaining <= 0) break;
|
|
10424
10458
|
const now = Date.now();
|
|
10425
10459
|
if (now >= nextProgressLogTs) {
|
|
10426
|
-
|
|
10460
|
+
logger17.info(
|
|
10427
10461
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
10428
10462
|
);
|
|
10429
10463
|
nextProgressLogTs = now + 5e3;
|
|
@@ -10431,11 +10465,11 @@ var Share = {
|
|
|
10431
10465
|
await (0, import_delay5.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10432
10466
|
}
|
|
10433
10467
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10434
|
-
|
|
10468
|
+
logger17.warning(
|
|
10435
10469
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
10436
10470
|
);
|
|
10437
10471
|
}
|
|
10438
|
-
|
|
10472
|
+
logger17.warning(
|
|
10439
10473
|
`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
10474
|
);
|
|
10441
10475
|
return {
|
|
@@ -10447,7 +10481,7 @@ var Share = {
|
|
|
10447
10481
|
} finally {
|
|
10448
10482
|
if (share.mode === "response") {
|
|
10449
10483
|
page.off("response", onResponse);
|
|
10450
|
-
|
|
10484
|
+
logger17.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10451
10485
|
}
|
|
10452
10486
|
await stopDomMonitor();
|
|
10453
10487
|
}
|