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