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