@skrillex1224/playwright-toolkit 2.1.279 → 2.1.281
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 +165 -157
- package/dist/browser.js.map +4 -4
- package/dist/index.cjs +464 -615
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +464 -615
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -387,18 +387,18 @@ var fallbackLog = {
|
|
|
387
387
|
error: (...args) => console.error(...args),
|
|
388
388
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
389
389
|
};
|
|
390
|
-
var resolveLogMethod = (
|
|
391
|
-
if (
|
|
392
|
-
return
|
|
390
|
+
var resolveLogMethod = (logger16, name) => {
|
|
391
|
+
if (logger16 && typeof logger16[name] === "function") {
|
|
392
|
+
return logger16[name].bind(logger16);
|
|
393
393
|
}
|
|
394
|
-
if (name === "warning" &&
|
|
395
|
-
return
|
|
394
|
+
if (name === "warning" && logger16 && typeof logger16.warn === "function") {
|
|
395
|
+
return logger16.warn.bind(logger16);
|
|
396
396
|
}
|
|
397
397
|
return fallbackLog[name];
|
|
398
398
|
};
|
|
399
399
|
var defaultLogger = null;
|
|
400
|
-
var setDefaultLogger = (
|
|
401
|
-
defaultLogger =
|
|
400
|
+
var setDefaultLogger = (logger16) => {
|
|
401
|
+
defaultLogger = logger16;
|
|
402
402
|
};
|
|
403
403
|
var resolveLogger = (explicitLogger) => {
|
|
404
404
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -425,8 +425,8 @@ var colorize = (text, color) => {
|
|
|
425
425
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
426
426
|
const name = prefix ? String(prefix) : "";
|
|
427
427
|
const dispatch = (methodName, icon, message, color) => {
|
|
428
|
-
const
|
|
429
|
-
const logFn = resolveLogMethod(
|
|
428
|
+
const logger16 = resolveLogger(explicitLogger);
|
|
429
|
+
const logFn = resolveLogMethod(logger16, methodName);
|
|
430
430
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
431
431
|
const line = formatLine(name, icon, message);
|
|
432
432
|
const coloredLine = colorize(line, color);
|
|
@@ -923,7 +923,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
923
923
|
viewportResized
|
|
924
924
|
};
|
|
925
925
|
};
|
|
926
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
926
|
+
var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
927
927
|
await page.evaluate((className) => {
|
|
928
928
|
const targets = new Set([
|
|
929
929
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -947,8 +947,8 @@ var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
|
947
947
|
el.classList.remove(className);
|
|
948
948
|
});
|
|
949
949
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
950
|
-
if (
|
|
951
|
-
await page.setViewportSize(
|
|
950
|
+
if (state2?.originalViewport && state2?.viewportResized) {
|
|
951
|
+
await page.setViewportSize(state2.originalViewport);
|
|
952
952
|
}
|
|
953
953
|
};
|
|
954
954
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -1005,21 +1005,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
};
|
|
1007
1007
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
1008
|
-
const
|
|
1008
|
+
const state2 = await prepareExpandedFullPageScreenshot(page, options);
|
|
1009
1009
|
try {
|
|
1010
1010
|
return await capturePageScreenshot(page, {
|
|
1011
1011
|
fullPage: true,
|
|
1012
1012
|
type: options.type || "png",
|
|
1013
1013
|
quality: options.quality,
|
|
1014
1014
|
timeout: options.timeout,
|
|
1015
|
-
maxClipHeight:
|
|
1015
|
+
maxClipHeight: state2.targetHeight
|
|
1016
1016
|
});
|
|
1017
1017
|
} finally {
|
|
1018
1018
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
1019
1019
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
1020
1020
|
});
|
|
1021
1021
|
if (options.restore) {
|
|
1022
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
1022
|
+
await restoreExpandedFullPageScreenshot(page, state2);
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
1025
|
};
|
|
@@ -1915,8 +1915,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1915
1915
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1916
1916
|
};
|
|
1917
1917
|
};
|
|
1918
|
-
var rememberRuntimeState = (
|
|
1919
|
-
rememberedRuntimeState = deepClone(
|
|
1918
|
+
var rememberRuntimeState = (state2) => {
|
|
1919
|
+
rememberedRuntimeState = deepClone(state2);
|
|
1920
1920
|
return rememberedRuntimeState;
|
|
1921
1921
|
};
|
|
1922
1922
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1975,7 +1975,7 @@ var RuntimeEnv = {
|
|
|
1975
1975
|
} else {
|
|
1976
1976
|
delete normalizedRuntime.browser_profile;
|
|
1977
1977
|
}
|
|
1978
|
-
const
|
|
1978
|
+
const state2 = {
|
|
1979
1979
|
actor: resolvedActor,
|
|
1980
1980
|
device,
|
|
1981
1981
|
runtime: normalizedRuntime,
|
|
@@ -1989,73 +1989,73 @@ var RuntimeEnv = {
|
|
|
1989
1989
|
browserProfileCore: browserProfile.core,
|
|
1990
1990
|
browserProfileObserved: browserProfile.observed
|
|
1991
1991
|
};
|
|
1992
|
-
rememberRuntimeState(
|
|
1993
|
-
return
|
|
1992
|
+
rememberRuntimeState(state2);
|
|
1993
|
+
return state2;
|
|
1994
1994
|
},
|
|
1995
1995
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
1996
1996
|
buildEnvPatch(source = {}, actor = "") {
|
|
1997
|
-
const
|
|
1998
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
1997
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
1998
|
+
const browserProfile = buildBrowserProfilePayload(state2.browserProfileCore, state2.browserProfileObserved);
|
|
1999
1999
|
const envPatch = {
|
|
2000
|
-
...Array.isArray(
|
|
2001
|
-
...Object.keys(
|
|
2002
|
-
...Object.keys(
|
|
2000
|
+
...Array.isArray(state2.cookies) && state2.cookies.length > 0 ? { cookies: state2.cookies } : {},
|
|
2001
|
+
...Object.keys(state2.localStorage || {}).length > 0 ? { local_storage: state2.localStorage } : {},
|
|
2002
|
+
...Object.keys(state2.sessionStorage || {}).length > 0 ? { session_storage: state2.sessionStorage } : {},
|
|
2003
2003
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
2004
2004
|
};
|
|
2005
2005
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
2006
2006
|
},
|
|
2007
2007
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
2008
2008
|
hasLoginState(source = {}, actor = "") {
|
|
2009
|
-
const
|
|
2010
|
-
return isPlainObject(
|
|
2009
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
2010
|
+
return isPlainObject(state2.runtime) && Object.keys(state2.runtime || {}).length > 0;
|
|
2011
2011
|
},
|
|
2012
2012
|
rememberState(source = {}) {
|
|
2013
|
-
const
|
|
2014
|
-
rememberRuntimeState(
|
|
2013
|
+
const state2 = normalizeRuntimeState(source);
|
|
2014
|
+
rememberRuntimeState(state2);
|
|
2015
2015
|
return RuntimeEnv.peekRememberedState();
|
|
2016
2016
|
},
|
|
2017
2017
|
peekRememberedState() {
|
|
2018
2018
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
2019
2019
|
},
|
|
2020
2020
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
2021
|
-
const
|
|
2022
|
-
return deepClone(
|
|
2021
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
2022
|
+
return deepClone(state2.browserProfileCore || {});
|
|
2023
2023
|
},
|
|
2024
2024
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
2025
|
-
const
|
|
2025
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
2026
2026
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
2027
2027
|
...core,
|
|
2028
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2028
|
+
device: normalizeKnownDevice(core?.device) || state2.device
|
|
2029
2029
|
});
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
if (Object.keys(
|
|
2033
|
-
|
|
2030
|
+
state2.browserProfileCore = normalizedCore;
|
|
2031
|
+
state2.browserProfile = buildBrowserProfilePayload(normalizedCore, state2.browserProfileObserved);
|
|
2032
|
+
if (Object.keys(state2.browserProfile).length > 0) {
|
|
2033
|
+
state2.runtime.browser_profile = state2.browserProfile;
|
|
2034
2034
|
} else {
|
|
2035
|
-
delete
|
|
2035
|
+
delete state2.runtime.browser_profile;
|
|
2036
2036
|
}
|
|
2037
|
-
rememberRuntimeState(
|
|
2038
|
-
return
|
|
2037
|
+
rememberRuntimeState(state2);
|
|
2038
|
+
return state2;
|
|
2039
2039
|
},
|
|
2040
2040
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2041
2041
|
// cookies / localStorage / sessionStorage。
|
|
2042
2042
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2043
2043
|
async applyToPage(page, source = {}, options = {}) {
|
|
2044
2044
|
if (!page) return;
|
|
2045
|
-
let
|
|
2045
|
+
let state2 = normalizeRuntimeState(source, options?.actor || "");
|
|
2046
2046
|
if (typeof options?.preapply === "function") {
|
|
2047
|
-
|
|
2048
|
-
rememberRuntimeState(
|
|
2047
|
+
state2 = await options.preapply(state2) || state2;
|
|
2048
|
+
rememberRuntimeState(state2);
|
|
2049
2049
|
}
|
|
2050
2050
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2051
2051
|
configurable: true,
|
|
2052
2052
|
enumerable: false,
|
|
2053
2053
|
writable: true,
|
|
2054
|
-
value:
|
|
2054
|
+
value: state2
|
|
2055
2055
|
});
|
|
2056
|
-
const localStorage =
|
|
2057
|
-
const sessionStorage =
|
|
2058
|
-
const cookies = (
|
|
2056
|
+
const localStorage = state2.localStorage || {};
|
|
2057
|
+
const sessionStorage = state2.sessionStorage || {};
|
|
2058
|
+
const cookies = (state2.cookies || []).map((cookie) => {
|
|
2059
2059
|
const normalized = { ...cookie };
|
|
2060
2060
|
if (!normalized.path) {
|
|
2061
2061
|
normalized.path = "/";
|
|
@@ -2093,8 +2093,8 @@ var RuntimeEnv = {
|
|
|
2093
2093
|
},
|
|
2094
2094
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2095
2095
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2096
|
-
const
|
|
2097
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2096
|
+
const state2 = normalizeRuntimeState(source, options?.actor || "");
|
|
2097
|
+
const baseline = RuntimeEnv.buildEnvPatch(state2) || {};
|
|
2098
2098
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2099
2099
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2100
2100
|
}
|
|
@@ -2113,7 +2113,7 @@ var RuntimeEnv = {
|
|
|
2113
2113
|
cookies
|
|
2114
2114
|
},
|
|
2115
2115
|
{
|
|
2116
|
-
browserProfileCore:
|
|
2116
|
+
browserProfileCore: state2.browserProfileCore
|
|
2117
2117
|
}
|
|
2118
2118
|
);
|
|
2119
2119
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2127,11 +2127,11 @@ var RuntimeEnv = {
|
|
|
2127
2127
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2128
2128
|
var resolveRuntimeContext = (input) => {
|
|
2129
2129
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2130
|
-
const
|
|
2131
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2130
|
+
const state2 = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2131
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state2) || null;
|
|
2132
2132
|
return {
|
|
2133
|
-
actor:
|
|
2134
|
-
runtime:
|
|
2133
|
+
actor: state2.actor,
|
|
2134
|
+
runtime: state2.runtime,
|
|
2135
2135
|
envPatch
|
|
2136
2136
|
};
|
|
2137
2137
|
};
|
|
@@ -2490,6 +2490,57 @@ var Utils = {
|
|
|
2490
2490
|
}
|
|
2491
2491
|
};
|
|
2492
2492
|
|
|
2493
|
+
// src/internals/context.js
|
|
2494
|
+
var state = {
|
|
2495
|
+
mode: Mode.Default
|
|
2496
|
+
};
|
|
2497
|
+
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2498
|
+
var ToolkitContext = {
|
|
2499
|
+
get mode() {
|
|
2500
|
+
return state.mode;
|
|
2501
|
+
},
|
|
2502
|
+
setMode(mode = Mode.Default) {
|
|
2503
|
+
state.mode = normalizeMode(mode, Mode.Default);
|
|
2504
|
+
return state.mode;
|
|
2505
|
+
}
|
|
2506
|
+
};
|
|
2507
|
+
var getToolkitMode = () => state.mode;
|
|
2508
|
+
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2509
|
+
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2510
|
+
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2511
|
+
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2512
|
+
const delegate = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2513
|
+
return {
|
|
2514
|
+
mode: normalizedMode,
|
|
2515
|
+
delegate
|
|
2516
|
+
};
|
|
2517
|
+
};
|
|
2518
|
+
|
|
2519
|
+
// src/internals/delegate.js
|
|
2520
|
+
var normalizeMethodDefinition = (definition) => typeof definition === "string" ? { name: definition, enumerable: true } : {
|
|
2521
|
+
name: String(definition?.name || "").trim(),
|
|
2522
|
+
enumerable: definition?.enumerable !== false
|
|
2523
|
+
};
|
|
2524
|
+
var createMethodDescriptor = (namespace, methodName, enumerable, strategies) => ({
|
|
2525
|
+
enumerable,
|
|
2526
|
+
value: (...args) => {
|
|
2527
|
+
const { mode, delegate } = resolveModeStrategy(strategies);
|
|
2528
|
+
if (typeof delegate?.[methodName] !== "function") {
|
|
2529
|
+
throw new Error(`${namespace}.${methodName} is not available in ${mode} mode`);
|
|
2530
|
+
}
|
|
2531
|
+
return delegate[methodName](...args);
|
|
2532
|
+
}
|
|
2533
|
+
});
|
|
2534
|
+
var createDelegatedFacade = (namespace, strategies = {}, methods = []) => {
|
|
2535
|
+
const descriptors = Object.fromEntries(
|
|
2536
|
+
methods.map(normalizeMethodDefinition).filter((method) => method.name).map((method) => [
|
|
2537
|
+
method.name,
|
|
2538
|
+
createMethodDescriptor(namespace, method.name, method.enumerable, strategies)
|
|
2539
|
+
])
|
|
2540
|
+
);
|
|
2541
|
+
return Object.defineProperties({}, descriptors);
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2493
2544
|
// src/internals/anti-cheat/default.js
|
|
2494
2545
|
var BASE_CONFIG = Object.freeze({
|
|
2495
2546
|
locale: "zh-CN",
|
|
@@ -2563,43 +2614,52 @@ var DefaultAntiCheat = {
|
|
|
2563
2614
|
};
|
|
2564
2615
|
|
|
2565
2616
|
// src/internals/anti-cheat/cloakbrowser.js
|
|
2566
|
-
var
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
var callAntiCheat = (method, ...args) => {
|
|
2579
|
-
const delegate = resolveAntiCheatDelegate();
|
|
2580
|
-
if (typeof delegate?.[method] !== "function") {
|
|
2581
|
-
throw new Error(`AntiCheat.${method} is not available in ${getToolkitMode()} mode`);
|
|
2582
|
-
}
|
|
2583
|
-
return delegate[method](...args);
|
|
2584
|
-
};
|
|
2585
|
-
var AntiCheat = {
|
|
2617
|
+
var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
2618
|
+
locale: "",
|
|
2619
|
+
acceptLanguage: "",
|
|
2620
|
+
timezoneId: "",
|
|
2621
|
+
timezoneOffset: null,
|
|
2622
|
+
geolocation: null
|
|
2623
|
+
});
|
|
2624
|
+
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2625
|
+
var CloakBrowserAntiCheat = {
|
|
2626
|
+
/**
|
|
2627
|
+
* CloakBrowser 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2628
|
+
*/
|
|
2586
2629
|
getBaseConfig() {
|
|
2587
|
-
return
|
|
2630
|
+
return { ...CLOAK_BROWSER_BASE_CONFIG };
|
|
2588
2631
|
},
|
|
2589
|
-
getFingerprintGeneratorOptions(
|
|
2590
|
-
return
|
|
2632
|
+
getFingerprintGeneratorOptions() {
|
|
2633
|
+
return {};
|
|
2591
2634
|
},
|
|
2592
|
-
getLaunchArgs(
|
|
2593
|
-
return
|
|
2635
|
+
getLaunchArgs() {
|
|
2636
|
+
return [];
|
|
2594
2637
|
},
|
|
2595
|
-
getTlsFingerprintOptions(
|
|
2596
|
-
return
|
|
2638
|
+
getTlsFingerprintOptions() {
|
|
2639
|
+
return {};
|
|
2597
2640
|
},
|
|
2598
2641
|
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2599
|
-
|
|
2642
|
+
const normalizedHeaders = normalizeHeaders(headers);
|
|
2643
|
+
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2644
|
+
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2645
|
+
}
|
|
2646
|
+
return normalizedHeaders;
|
|
2600
2647
|
}
|
|
2601
2648
|
};
|
|
2602
2649
|
|
|
2650
|
+
// src/anti-cheat.js
|
|
2651
|
+
var antiCheatStrategies = {
|
|
2652
|
+
[Mode.Default]: DefaultAntiCheat,
|
|
2653
|
+
[Mode.CloakBrowser]: CloakBrowserAntiCheat
|
|
2654
|
+
};
|
|
2655
|
+
var AntiCheat = createDelegatedFacade("AntiCheat", antiCheatStrategies, [
|
|
2656
|
+
"getBaseConfig",
|
|
2657
|
+
"getFingerprintGeneratorOptions",
|
|
2658
|
+
"getLaunchArgs",
|
|
2659
|
+
"getTlsFingerprintOptions",
|
|
2660
|
+
"applyLocaleHeaders"
|
|
2661
|
+
]);
|
|
2662
|
+
|
|
2603
2663
|
// src/device-input.js
|
|
2604
2664
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2605
2665
|
var assertPage = (page, method) => {
|
|
@@ -2999,12 +3059,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
2999
3059
|
}
|
|
3000
3060
|
return resolved;
|
|
3001
3061
|
};
|
|
3002
|
-
var attachRuntimeState = (page,
|
|
3062
|
+
var attachRuntimeState = (page, state2) => {
|
|
3003
3063
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
3004
3064
|
configurable: true,
|
|
3005
3065
|
enumerable: false,
|
|
3006
3066
|
writable: true,
|
|
3007
|
-
value:
|
|
3067
|
+
value: state2
|
|
3008
3068
|
});
|
|
3009
3069
|
};
|
|
3010
3070
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -4058,7 +4118,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4058
4118
|
return;
|
|
4059
4119
|
}
|
|
4060
4120
|
await page.evaluate(
|
|
4061
|
-
(
|
|
4121
|
+
(state2) => window.scrollTo(state2.x, state2.y),
|
|
4062
4122
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4063
4123
|
).catch(() => {
|
|
4064
4124
|
});
|
|
@@ -4304,7 +4364,7 @@ var MobileHumanize = {
|
|
|
4304
4364
|
if (scrollRect && beforeWindowState) {
|
|
4305
4365
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4306
4366
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4307
|
-
await page.evaluate((
|
|
4367
|
+
await page.evaluate((state2) => window.scrollTo(state2.x, state2.y), beforeWindowState);
|
|
4308
4368
|
logger6.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4309
4369
|
}
|
|
4310
4370
|
}
|
|
@@ -4671,475 +4731,272 @@ var DefaultHumanize = {
|
|
|
4671
4731
|
|
|
4672
4732
|
// src/internals/humanize/cloakbrowser.js
|
|
4673
4733
|
var import_delay4 = __toESM(require("delay"), 1);
|
|
4674
|
-
var logger7 = createInternalLogger("Humanize.CloakBrowser");
|
|
4675
|
-
var humanizedPages = /* @__PURE__ */ new WeakSet();
|
|
4676
|
-
var cachedCloakHumanModulePromise = null;
|
|
4677
|
-
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4678
|
-
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4679
4734
|
var resolveDeviceFromPage3 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4680
4735
|
var isMobilePage = (page) => resolveDeviceFromPage3(page) === Device.Mobile;
|
|
4681
|
-
var
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
}
|
|
4690
|
-
return cachedCloakHumanModulePromise;
|
|
4736
|
+
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4737
|
+
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4738
|
+
var resolveNativeTarget2 = (page, target) => typeof target === "string" ? page.locator(target).first() : target;
|
|
4739
|
+
var getViewportCenter = (page) => {
|
|
4740
|
+
const viewport = page?.viewportSize?.() || { width: 1365, height: 900 };
|
|
4741
|
+
return {
|
|
4742
|
+
x: Math.round(viewport.width / 2),
|
|
4743
|
+
y: Math.round(viewport.height / 2)
|
|
4744
|
+
};
|
|
4691
4745
|
};
|
|
4692
|
-
var
|
|
4693
|
-
|
|
4694
|
-
if (
|
|
4695
|
-
|
|
4696
|
-
}
|
|
4697
|
-
if (Number.isFinite(Number(options.pauseProbability))) {
|
|
4698
|
-
humanConfig.typing_pause_chance = Number(options.pauseProbability);
|
|
4746
|
+
var readViewportScroll = async (page) => await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY })).catch(() => ({ x: 0, y: 0 }));
|
|
4747
|
+
var getTargetBox = async (target) => {
|
|
4748
|
+
if (!target || typeof target.boundingBox !== "function") {
|
|
4749
|
+
return null;
|
|
4699
4750
|
}
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4751
|
+
return await target.boundingBox().catch(() => null);
|
|
4752
|
+
};
|
|
4753
|
+
var clickOptionsFrom = (options = {}) => {
|
|
4754
|
+
const nextOptions = {
|
|
4755
|
+
force: true
|
|
4756
|
+
};
|
|
4757
|
+
if (options.timeout != null) {
|
|
4758
|
+
nextOptions.timeout = options.timeout;
|
|
4706
4759
|
}
|
|
4707
|
-
return
|
|
4760
|
+
return nextOptions;
|
|
4708
4761
|
};
|
|
4709
|
-
var
|
|
4710
|
-
const
|
|
4711
|
-
if (options
|
|
4712
|
-
|
|
4762
|
+
var typeOptionsFrom = (options = {}) => {
|
|
4763
|
+
const nextOptions = {};
|
|
4764
|
+
if (options.timeout != null) {
|
|
4765
|
+
nextOptions.timeout = options.timeout;
|
|
4713
4766
|
}
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
if (humanConfig) {
|
|
4717
|
-
actionOptions.human_config = humanConfig;
|
|
4767
|
+
if (options.baseDelay != null) {
|
|
4768
|
+
nextOptions.delay = Math.max(0, Number(options.baseDelay) || 0);
|
|
4718
4769
|
}
|
|
4719
|
-
return
|
|
4720
|
-
};
|
|
4721
|
-
var ensureDesktopHumanized = async (page) => {
|
|
4722
|
-
if (!page || typeof page !== "object") {
|
|
4723
|
-
throw new Error("Humanize requires a Playwright page");
|
|
4724
|
-
}
|
|
4725
|
-
const humanModule = await loadCloakHumanModule();
|
|
4726
|
-
if (page._original && page._humanCursor) {
|
|
4727
|
-
humanizedPages.add(page);
|
|
4728
|
-
return humanModule;
|
|
4729
|
-
}
|
|
4730
|
-
if (humanizedPages.has(page)) {
|
|
4731
|
-
return humanModule;
|
|
4732
|
-
}
|
|
4733
|
-
const config = page._humanCfg || humanModule.resolveConfig?.("default") || humanModule.resolveConfig?.();
|
|
4734
|
-
const cursor = page._humanCursor || { x: 0, y: 0, initialized: false };
|
|
4735
|
-
humanModule.patchPage(page, config, cursor);
|
|
4736
|
-
humanizedPages.add(page);
|
|
4737
|
-
return humanModule;
|
|
4738
|
-
};
|
|
4739
|
-
var patchHandle = async (page, handle) => {
|
|
4740
|
-
if (!handle || typeof handle !== "object") return handle;
|
|
4741
|
-
const humanModule = await ensureDesktopHumanized(page);
|
|
4742
|
-
humanModule.patchSingleElementHandle(
|
|
4743
|
-
handle,
|
|
4744
|
-
page,
|
|
4745
|
-
page._humanCfg,
|
|
4746
|
-
page._humanCursor,
|
|
4747
|
-
page._humanRaw,
|
|
4748
|
-
page._humanRawKb,
|
|
4749
|
-
page._humanOriginals,
|
|
4750
|
-
page._stealth
|
|
4751
|
-
);
|
|
4752
|
-
return handle;
|
|
4770
|
+
return nextOptions;
|
|
4753
4771
|
};
|
|
4754
|
-
var
|
|
4755
|
-
|
|
4756
|
-
|
|
4772
|
+
var pressOptionsFrom = (options = {}) => {
|
|
4773
|
+
const nextOptions = {};
|
|
4774
|
+
if (options.timeout != null) {
|
|
4775
|
+
nextOptions.timeout = options.timeout;
|
|
4757
4776
|
}
|
|
4758
|
-
if (
|
|
4759
|
-
|
|
4760
|
-
if (!handle) {
|
|
4761
|
-
if (throwOnMissing) {
|
|
4762
|
-
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${String(target)}`);
|
|
4763
|
-
}
|
|
4764
|
-
return { target: null, dispose: null };
|
|
4765
|
-
}
|
|
4766
|
-
return { target: handle, dispose: null };
|
|
4777
|
+
if (options.holdDelay != null) {
|
|
4778
|
+
nextOptions.delay = Math.max(0, Number(options.holdDelay) || 0);
|
|
4767
4779
|
}
|
|
4768
|
-
|
|
4769
|
-
const handle = await target.elementHandle();
|
|
4770
|
-
if (!handle) {
|
|
4771
|
-
if (throwOnMissing) {
|
|
4772
|
-
throw new Error("\u627E\u4E0D\u5230 locator \u5BF9\u5E94\u7684\u5143\u7D20");
|
|
4773
|
-
}
|
|
4774
|
-
return { target: null, dispose: null };
|
|
4775
|
-
}
|
|
4776
|
-
await patchHandle(page, handle);
|
|
4777
|
-
return {
|
|
4778
|
-
target: handle,
|
|
4779
|
-
dispose: async () => {
|
|
4780
|
-
await handle.dispose().catch(() => {
|
|
4781
|
-
});
|
|
4782
|
-
}
|
|
4783
|
-
};
|
|
4784
|
-
}
|
|
4785
|
-
await patchHandle(page, target);
|
|
4786
|
-
return { target, dispose: null };
|
|
4780
|
+
return nextOptions;
|
|
4787
4781
|
};
|
|
4788
|
-
var
|
|
4782
|
+
var waitDesktopJitter = async (baseMs, jitterPercent = 0.3) => {
|
|
4789
4783
|
await (0, import_delay4.default)(jitterMs(baseMs, jitterPercent));
|
|
4790
4784
|
};
|
|
4791
|
-
var
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
await page.mouse.click(cursor.x || 0, cursor.y || 0);
|
|
4801
|
-
return true;
|
|
4802
|
-
}
|
|
4803
|
-
if (isPoint2(target)) {
|
|
4804
|
-
return humanMoveToPoint(page, target).then(async () => {
|
|
4805
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4806
|
-
return true;
|
|
4807
|
-
});
|
|
4808
|
-
}
|
|
4809
|
-
const throwOnMissing = options.throwOnMissing !== false;
|
|
4810
|
-
if (typeof target === "string") {
|
|
4811
|
-
if (!throwOnMissing) {
|
|
4812
|
-
const existingHandle = await page.$(target);
|
|
4813
|
-
if (!existingHandle) {
|
|
4814
|
-
return false;
|
|
4815
|
-
}
|
|
4816
|
-
await existingHandle.click(buildActionOptions(options));
|
|
4817
|
-
return true;
|
|
4818
|
-
}
|
|
4819
|
-
await page.click(target, buildActionOptions(options));
|
|
4820
|
-
return true;
|
|
4821
|
-
}
|
|
4822
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing });
|
|
4823
|
-
try {
|
|
4824
|
-
if (!resolvedTarget) {
|
|
4785
|
+
var DesktopCloakHumanize = {
|
|
4786
|
+
jitterMs(base, jitterPercent = 0.3) {
|
|
4787
|
+
return jitterMs(base, jitterPercent);
|
|
4788
|
+
},
|
|
4789
|
+
async initializeCursor(page) {
|
|
4790
|
+
return Boolean(page);
|
|
4791
|
+
},
|
|
4792
|
+
async humanMove(page, target) {
|
|
4793
|
+
if (target == null) {
|
|
4825
4794
|
return false;
|
|
4826
4795
|
}
|
|
4827
|
-
if (
|
|
4828
|
-
await
|
|
4796
|
+
if (isPoint2(target)) {
|
|
4797
|
+
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4829
4798
|
return true;
|
|
4830
4799
|
}
|
|
4831
|
-
const
|
|
4800
|
+
const resolvedTarget = resolveNativeTarget2(page, target);
|
|
4801
|
+
if (typeof resolvedTarget?.hover === "function") {
|
|
4802
|
+
await resolvedTarget.hover(clickOptionsFrom());
|
|
4803
|
+
return true;
|
|
4804
|
+
}
|
|
4805
|
+
const box = await getTargetBox(resolvedTarget);
|
|
4832
4806
|
if (!box) {
|
|
4833
|
-
if (throwOnMissing) {
|
|
4834
|
-
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4835
|
-
}
|
|
4836
4807
|
return false;
|
|
4837
4808
|
}
|
|
4838
|
-
await page.mouse.
|
|
4809
|
+
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
4839
4810
|
return true;
|
|
4840
|
-
} finally {
|
|
4841
|
-
if (typeof dispose === "function") {
|
|
4842
|
-
await dispose();
|
|
4843
|
-
}
|
|
4844
|
-
}
|
|
4845
|
-
};
|
|
4846
|
-
var CloakBrowserHumanize = {
|
|
4847
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4848
|
-
return jitterMs(base, jitterPercent);
|
|
4849
4811
|
},
|
|
4850
|
-
async
|
|
4851
|
-
|
|
4852
|
-
|
|
4812
|
+
async humanScroll(page, target) {
|
|
4813
|
+
const resolvedTarget = resolveNativeTarget2(page, target);
|
|
4814
|
+
if (!resolvedTarget) {
|
|
4815
|
+
return { element: null, didScroll: false, restore: null };
|
|
4853
4816
|
}
|
|
4854
|
-
await
|
|
4855
|
-
|
|
4817
|
+
const before = await readViewportScroll(page);
|
|
4818
|
+
await resolvedTarget.scrollIntoViewIfNeeded?.();
|
|
4819
|
+
const after = await readViewportScroll(page);
|
|
4820
|
+
return {
|
|
4821
|
+
element: resolvedTarget,
|
|
4822
|
+
didScroll: before.x !== after.x || before.y !== after.y,
|
|
4823
|
+
restore: null
|
|
4824
|
+
};
|
|
4856
4825
|
},
|
|
4857
|
-
async
|
|
4858
|
-
if (
|
|
4859
|
-
|
|
4826
|
+
async humanClick(page, target, options = {}) {
|
|
4827
|
+
if (target == null) {
|
|
4828
|
+
const center = getViewportCenter(page);
|
|
4829
|
+
await page.mouse.click(center.x, center.y);
|
|
4830
|
+
return true;
|
|
4860
4831
|
}
|
|
4861
|
-
await ensureDesktopHumanized(page);
|
|
4862
4832
|
if (isPoint2(target)) {
|
|
4863
|
-
|
|
4864
|
-
}
|
|
4865
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing: false });
|
|
4866
|
-
try {
|
|
4867
|
-
if (!resolvedTarget) {
|
|
4868
|
-
return false;
|
|
4869
|
-
}
|
|
4870
|
-
if (typeof resolvedTarget.hover === "function") {
|
|
4871
|
-
await resolvedTarget.hover({ force: true });
|
|
4872
|
-
return true;
|
|
4873
|
-
}
|
|
4874
|
-
const box = await resolvedTarget.boundingBox?.();
|
|
4875
|
-
if (!box) {
|
|
4876
|
-
return false;
|
|
4877
|
-
}
|
|
4878
|
-
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
4833
|
+
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4879
4834
|
return true;
|
|
4880
|
-
} finally {
|
|
4881
|
-
if (typeof dispose === "function") {
|
|
4882
|
-
await dispose();
|
|
4883
|
-
}
|
|
4884
4835
|
}
|
|
4885
|
-
},
|
|
4886
|
-
async humanScroll(page, target, options = {}) {
|
|
4887
|
-
if (isMobilePage(page)) {
|
|
4888
|
-
return await MobileHumanize.humanScroll(page, target, options);
|
|
4889
|
-
}
|
|
4890
|
-
const humanModule = await ensureDesktopHumanized(page);
|
|
4891
4836
|
if (typeof target === "string") {
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
const result = await humanModule.scrollToElement(
|
|
4895
|
-
page,
|
|
4896
|
-
page._humanRaw,
|
|
4897
|
-
target,
|
|
4898
|
-
x,
|
|
4899
|
-
y,
|
|
4900
|
-
page._humanCfg,
|
|
4901
|
-
options.timeout
|
|
4902
|
-
);
|
|
4903
|
-
if (page._humanCursor) {
|
|
4904
|
-
page._humanCursor.x = result.cursorX;
|
|
4905
|
-
page._humanCursor.y = result.cursorY;
|
|
4906
|
-
}
|
|
4907
|
-
return {
|
|
4908
|
-
element: await page.$(target),
|
|
4909
|
-
didScroll: Boolean(result.didScroll),
|
|
4910
|
-
restore: null
|
|
4911
|
-
};
|
|
4912
|
-
} catch (error) {
|
|
4913
|
-
logger7.warn(`humanScroll: cloakbrowser \u6EDA\u52A8\u5931\u8D25\uFF0C\u8DF3\u8FC7 (${error?.message || error})`);
|
|
4914
|
-
return { element: null, didScroll: false, restore: null };
|
|
4915
|
-
}
|
|
4837
|
+
await page.click(target, clickOptionsFrom(options));
|
|
4838
|
+
return true;
|
|
4916
4839
|
}
|
|
4917
|
-
|
|
4918
|
-
|
|
4919
|
-
|
|
4920
|
-
return { element: null, didScroll: false, restore: null };
|
|
4921
|
-
}
|
|
4922
|
-
const before = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4923
|
-
await resolvedTarget.scrollIntoViewIfNeeded?.();
|
|
4924
|
-
const after = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4925
|
-
return {
|
|
4926
|
-
element: resolvedTarget,
|
|
4927
|
-
didScroll: before.x !== after.x || before.y !== after.y,
|
|
4928
|
-
restore: null
|
|
4929
|
-
};
|
|
4930
|
-
} finally {
|
|
4931
|
-
if (typeof dispose === "function") {
|
|
4932
|
-
await dispose();
|
|
4933
|
-
}
|
|
4840
|
+
if (typeof target?.click === "function") {
|
|
4841
|
+
await target.click(clickOptionsFrom(options));
|
|
4842
|
+
return true;
|
|
4934
4843
|
}
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
return await MobileHumanize.humanClick(page, target, options);
|
|
4844
|
+
const box = await getTargetBox(target);
|
|
4845
|
+
if (!box) {
|
|
4846
|
+
return false;
|
|
4939
4847
|
}
|
|
4940
|
-
|
|
4848
|
+
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4849
|
+
return true;
|
|
4941
4850
|
},
|
|
4942
|
-
async randomSleep(
|
|
4943
|
-
|
|
4944
|
-
if (isMobilePage(pageOrBaseMs)) {
|
|
4945
|
-
return await MobileHumanize.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4946
|
-
}
|
|
4947
|
-
await jitterSleep(maybeBaseMs, maybeJitterPercent ?? 0.3);
|
|
4948
|
-
return;
|
|
4949
|
-
}
|
|
4950
|
-
await jitterSleep(pageOrBaseMs, maybeBaseMs ?? 0.3);
|
|
4851
|
+
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4852
|
+
await waitDesktopJitter(baseMs, jitterPercent);
|
|
4951
4853
|
},
|
|
4952
4854
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4953
|
-
if (isMobilePage(page)) {
|
|
4954
|
-
return await MobileHumanize.simulateGaze(page, baseDurationMs);
|
|
4955
|
-
}
|
|
4956
|
-
await ensureDesktopHumanized(page);
|
|
4957
4855
|
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4958
|
-
const
|
|
4959
|
-
const
|
|
4960
|
-
while (Date.now() -
|
|
4856
|
+
const startedAt = Date.now();
|
|
4857
|
+
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4858
|
+
while (Date.now() - startedAt < durationMs) {
|
|
4961
4859
|
await page.mouse.move(
|
|
4962
|
-
100 + Math.random() * Math.max(120,
|
|
4963
|
-
100 + Math.random() * Math.max(120,
|
|
4860
|
+
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4861
|
+
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4964
4862
|
);
|
|
4965
|
-
await
|
|
4863
|
+
await waitDesktopJitter(600, 0.5);
|
|
4966
4864
|
}
|
|
4967
4865
|
},
|
|
4968
4866
|
async humanType(page, selector, text, options = {}) {
|
|
4969
|
-
if (isMobilePage(page)) {
|
|
4970
|
-
return await MobileHumanize.humanType(page, selector, text, options);
|
|
4971
|
-
}
|
|
4972
|
-
await ensureDesktopHumanized(page);
|
|
4973
|
-
const actionOptions = buildActionOptions(options);
|
|
4974
4867
|
if (typeof selector === "string") {
|
|
4975
|
-
await page.type(selector, text,
|
|
4868
|
+
await page.type(selector, text, typeOptionsFrom(options));
|
|
4976
4869
|
return;
|
|
4977
4870
|
}
|
|
4978
|
-
|
|
4979
|
-
try {
|
|
4980
|
-
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
4981
|
-
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
4982
|
-
}
|
|
4983
|
-
await resolvedTarget.type(text, actionOptions);
|
|
4984
|
-
} finally {
|
|
4985
|
-
if (typeof dispose === "function") {
|
|
4986
|
-
await dispose();
|
|
4987
|
-
}
|
|
4988
|
-
}
|
|
4871
|
+
await selector.type(text, typeOptionsFrom(options));
|
|
4989
4872
|
},
|
|
4990
4873
|
async humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4991
|
-
if (isMobilePage(page)) {
|
|
4992
|
-
return await MobileHumanize.humanPress(page, targetOrKey, maybeKey, options);
|
|
4993
|
-
}
|
|
4994
|
-
await ensureDesktopHumanized(page);
|
|
4995
4874
|
const hasTarget = typeof maybeKey === "string";
|
|
4996
4875
|
const key = hasTarget ? maybeKey : targetOrKey;
|
|
4997
4876
|
const pressOptions = hasTarget ? options : maybeKey || options;
|
|
4998
4877
|
if (!hasTarget) {
|
|
4999
|
-
await
|
|
5000
|
-
await page.keyboard.press(key, {
|
|
5001
|
-
...pressOptions.keyboardOptions || {},
|
|
5002
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
5003
|
-
});
|
|
4878
|
+
await page.keyboard.press(key, pressOptionsFrom(pressOptions));
|
|
5004
4879
|
return true;
|
|
5005
4880
|
}
|
|
5006
4881
|
if (typeof targetOrKey === "string") {
|
|
5007
|
-
await page.press(targetOrKey, key,
|
|
4882
|
+
await page.press(targetOrKey, key, pressOptionsFrom(pressOptions));
|
|
5008
4883
|
return true;
|
|
5009
4884
|
}
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
});
|
|
5013
|
-
try {
|
|
5014
|
-
if (!resolvedTarget) {
|
|
5015
|
-
return false;
|
|
5016
|
-
}
|
|
5017
|
-
if (typeof resolvedTarget.press === "function") {
|
|
5018
|
-
await resolvedTarget.press(key, buildActionOptions(pressOptions));
|
|
5019
|
-
return true;
|
|
5020
|
-
}
|
|
5021
|
-
await doDesktopHumanClick(page, targetOrKey, {
|
|
5022
|
-
...pressOptions,
|
|
5023
|
-
reactionDelay: pressOptions.focusDelay ?? 180
|
|
5024
|
-
});
|
|
5025
|
-
await jitterSleep(pressOptions.reactionDelay ?? 180, 0.45);
|
|
5026
|
-
await page.keyboard.press(key, {
|
|
5027
|
-
...pressOptions.keyboardOptions || {},
|
|
5028
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
5029
|
-
});
|
|
4885
|
+
if (typeof targetOrKey?.press === "function") {
|
|
4886
|
+
await targetOrKey.press(key, pressOptionsFrom(pressOptions));
|
|
5030
4887
|
return true;
|
|
5031
|
-
} finally {
|
|
5032
|
-
if (typeof dispose === "function") {
|
|
5033
|
-
await dispose();
|
|
5034
|
-
}
|
|
5035
4888
|
}
|
|
4889
|
+
await page.keyboard.press(key, pressOptionsFrom(pressOptions));
|
|
4890
|
+
return true;
|
|
5036
4891
|
},
|
|
5037
4892
|
async humanClear(page, selector) {
|
|
5038
|
-
if (
|
|
5039
|
-
|
|
4893
|
+
if (typeof selector === "string") {
|
|
4894
|
+
if (typeof page.clear === "function") {
|
|
4895
|
+
await page.clear(selector, clickOptionsFrom());
|
|
4896
|
+
return;
|
|
4897
|
+
}
|
|
4898
|
+
await page.fill(selector, "", clickOptionsFrom());
|
|
4899
|
+
return;
|
|
5040
4900
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
4901
|
+
if (typeof selector?.clear === "function") {
|
|
4902
|
+
await selector.clear(clickOptionsFrom());
|
|
4903
|
+
return;
|
|
4904
|
+
}
|
|
4905
|
+
if (typeof selector?.fill === "function") {
|
|
4906
|
+
await selector.fill("", clickOptionsFrom());
|
|
5044
4907
|
return;
|
|
5045
4908
|
}
|
|
5046
|
-
await page.fill(selector, "", { force: true });
|
|
5047
4909
|
},
|
|
5048
4910
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
5049
|
-
if (isMobilePage(page)) {
|
|
5050
|
-
return await MobileHumanize.warmUpBrowsing(page, baseDuration);
|
|
5051
|
-
}
|
|
5052
|
-
await ensureDesktopHumanized(page);
|
|
5053
4911
|
const durationMs = jitterMs(baseDuration, 0.4);
|
|
5054
|
-
const
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
await page.mouse.move(
|
|
5060
|
-
100 + Math.random() * Math.max(120, viewportSize.width - 200),
|
|
5061
|
-
100 + Math.random() * Math.max(120, viewportSize.height - 200)
|
|
5062
|
-
);
|
|
5063
|
-
await jitterSleep(350, 0.4);
|
|
5064
|
-
continue;
|
|
5065
|
-
}
|
|
5066
|
-
if (action < 0.7) {
|
|
5067
|
-
await page.mouse.wheel(0, (Math.random() - 0.5) * 220);
|
|
5068
|
-
await jitterSleep(500, 0.4);
|
|
5069
|
-
continue;
|
|
5070
|
-
}
|
|
5071
|
-
await jitterSleep(800, 0.5);
|
|
4912
|
+
const startedAt = Date.now();
|
|
4913
|
+
while (Date.now() - startedAt < durationMs) {
|
|
4914
|
+
await this.simulateGaze(page, 240);
|
|
4915
|
+
await this.naturalScroll(page, Math.random() > 0.4 ? "down" : "up", 160, 3);
|
|
4916
|
+
await waitDesktopJitter(250, 0.35);
|
|
5072
4917
|
}
|
|
5073
4918
|
},
|
|
5074
4919
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
}
|
|
5078
|
-
await ensureDesktopHumanized(page);
|
|
5079
|
-
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
5080
|
-
const actualDistance = jitterMs(distance, 0.15);
|
|
4920
|
+
const steps = Math.max(1, Number(baseSteps) || 1);
|
|
4921
|
+
const stepDistance = (Number(distance) || 0) / steps;
|
|
5081
4922
|
const sign = direction === "down" ? 1 : -1;
|
|
5082
|
-
const stepDistance = actualDistance / steps;
|
|
5083
4923
|
for (let index = 0; index < steps; index += 1) {
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
await page.mouse.wheel(0, stepDistance * factor * sign * jitter);
|
|
5087
|
-
await jitterSleep(60 + index * 25, 0.3);
|
|
4924
|
+
await page.mouse.wheel(0, stepDistance * sign);
|
|
4925
|
+
await waitDesktopJitter(60 + index * 20, 0.3);
|
|
5088
4926
|
}
|
|
5089
4927
|
}
|
|
5090
4928
|
};
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
const delegate = resolveHumanizeDelegate();
|
|
5096
|
-
if (typeof delegate?.[method] !== "function") {
|
|
5097
|
-
throw new Error(`Humanize.${method} is not available in ${getToolkitMode()} mode`);
|
|
5098
|
-
}
|
|
5099
|
-
return delegate[method](...args);
|
|
4929
|
+
var resolveDelegate2 = (page) => isMobilePage(page) ? MobileHumanize : DesktopCloakHumanize;
|
|
4930
|
+
var callDelegate2 = (method, page, args) => {
|
|
4931
|
+
const delegate = resolveDelegate2(page);
|
|
4932
|
+
return delegate[method](page, ...args);
|
|
5100
4933
|
};
|
|
5101
|
-
var
|
|
4934
|
+
var CloakBrowserHumanize = {
|
|
5102
4935
|
jitterMs(base, jitterPercent = 0.3) {
|
|
5103
|
-
return
|
|
4936
|
+
return jitterMs(base, jitterPercent);
|
|
5104
4937
|
},
|
|
5105
4938
|
initializeCursor(page) {
|
|
5106
|
-
return
|
|
4939
|
+
return callDelegate2("initializeCursor", page, []);
|
|
5107
4940
|
},
|
|
5108
4941
|
humanMove(page, target) {
|
|
5109
|
-
return
|
|
4942
|
+
return callDelegate2("humanMove", page, [target]);
|
|
5110
4943
|
},
|
|
5111
4944
|
humanScroll(page, target, options = {}) {
|
|
5112
|
-
return
|
|
4945
|
+
return callDelegate2("humanScroll", page, [target, options]);
|
|
5113
4946
|
},
|
|
5114
4947
|
humanClick(page, target, options = {}) {
|
|
5115
|
-
return
|
|
4948
|
+
return callDelegate2("humanClick", page, [target, options]);
|
|
5116
4949
|
},
|
|
5117
4950
|
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
5118
|
-
|
|
4951
|
+
if (isPageLike2(pageOrBaseMs)) {
|
|
4952
|
+
const delegate = resolveDelegate2(pageOrBaseMs);
|
|
4953
|
+
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4954
|
+
}
|
|
4955
|
+
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
5119
4956
|
},
|
|
5120
4957
|
simulateGaze(page, baseDurationMs = 2500) {
|
|
5121
|
-
return
|
|
4958
|
+
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
5122
4959
|
},
|
|
5123
4960
|
humanType(page, selector, text, options = {}) {
|
|
5124
|
-
return
|
|
4961
|
+
return callDelegate2("humanType", page, [selector, text, options]);
|
|
5125
4962
|
},
|
|
5126
4963
|
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
5127
4964
|
if (typeof maybeKey === "string") {
|
|
5128
|
-
return
|
|
4965
|
+
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
5129
4966
|
}
|
|
5130
|
-
return
|
|
4967
|
+
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
5131
4968
|
},
|
|
5132
4969
|
humanClear(page, selector) {
|
|
5133
|
-
return
|
|
4970
|
+
return callDelegate2("humanClear", page, [selector]);
|
|
5134
4971
|
},
|
|
5135
4972
|
warmUpBrowsing(page, baseDuration = 3500) {
|
|
5136
|
-
return
|
|
4973
|
+
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
5137
4974
|
},
|
|
5138
4975
|
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
5139
|
-
return
|
|
4976
|
+
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
5140
4977
|
}
|
|
5141
4978
|
};
|
|
5142
4979
|
|
|
4980
|
+
// src/humanize.js
|
|
4981
|
+
var humanizeStrategies = {
|
|
4982
|
+
[Mode.Default]: DefaultHumanize,
|
|
4983
|
+
[Mode.CloakBrowser]: CloakBrowserHumanize
|
|
4984
|
+
};
|
|
4985
|
+
var Humanize2 = createDelegatedFacade("Humanize", humanizeStrategies, [
|
|
4986
|
+
"jitterMs",
|
|
4987
|
+
"initializeCursor",
|
|
4988
|
+
"humanMove",
|
|
4989
|
+
"humanScroll",
|
|
4990
|
+
"humanClick",
|
|
4991
|
+
"randomSleep",
|
|
4992
|
+
"simulateGaze",
|
|
4993
|
+
"humanType",
|
|
4994
|
+
"humanPress",
|
|
4995
|
+
"humanClear",
|
|
4996
|
+
"warmUpBrowsing",
|
|
4997
|
+
"naturalScroll"
|
|
4998
|
+
]);
|
|
4999
|
+
|
|
5143
5000
|
// src/internals/launch/default.js
|
|
5144
5001
|
var import_node_child_process = require("node:child_process");
|
|
5145
5002
|
var import_fingerprint_generator = require("fingerprint-generator");
|
|
@@ -5226,7 +5083,7 @@ var ByPass = {
|
|
|
5226
5083
|
};
|
|
5227
5084
|
|
|
5228
5085
|
// src/internals/launch/default.js
|
|
5229
|
-
var
|
|
5086
|
+
var logger7 = createInternalLogger("Launch");
|
|
5230
5087
|
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
5231
5088
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
5232
5089
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
@@ -5278,7 +5135,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5278
5135
|
});
|
|
5279
5136
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5280
5137
|
} catch (error) {
|
|
5281
|
-
|
|
5138
|
+
logger7.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5282
5139
|
}
|
|
5283
5140
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5284
5141
|
return detectedVersion;
|
|
@@ -5315,7 +5172,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5315
5172
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5316
5173
|
throw error;
|
|
5317
5174
|
}
|
|
5318
|
-
|
|
5175
|
+
logger7.warn(
|
|
5319
5176
|
`\u5F53\u524D\u6D4F\u89C8\u5668\u5927\u7248\u672C ${requestedBrowserMajorVersion} \u65E0\u53EF\u7528 strict \u6307\u7EB9\u6837\u672C\uFF0C\u9000\u56DE\u4E0D\u7ED1\u5B9A\u5927\u7248\u672C\u751F\u6210: ${error?.message || error}`
|
|
5320
5177
|
);
|
|
5321
5178
|
}
|
|
@@ -5360,7 +5217,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5360
5217
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5361
5218
|
};
|
|
5362
5219
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5363
|
-
|
|
5220
|
+
logger7.info(
|
|
5364
5221
|
`\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}`
|
|
5365
5222
|
);
|
|
5366
5223
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5489,18 +5346,18 @@ var DefaultLaunch = {
|
|
|
5489
5346
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5490
5347
|
} catch {
|
|
5491
5348
|
}
|
|
5492
|
-
|
|
5349
|
+
logger7.info(
|
|
5493
5350
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5494
5351
|
);
|
|
5495
|
-
|
|
5352
|
+
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`);
|
|
5496
5353
|
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5497
|
-
|
|
5498
|
-
|
|
5354
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5355
|
+
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`);
|
|
5499
5356
|
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5500
|
-
|
|
5501
|
-
|
|
5357
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5358
|
+
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`);
|
|
5502
5359
|
} else if (enableByPassLogger) {
|
|
5503
|
-
|
|
5360
|
+
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`);
|
|
5504
5361
|
}
|
|
5505
5362
|
const onPageCreated = (page) => {
|
|
5506
5363
|
const recommendedGotoOptions = {
|
|
@@ -5522,7 +5379,7 @@ var DefaultLaunch = {
|
|
|
5522
5379
|
}
|
|
5523
5380
|
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5524
5381
|
if (!matched || !matched.rule) return;
|
|
5525
|
-
|
|
5382
|
+
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}`);
|
|
5526
5383
|
};
|
|
5527
5384
|
page.on("request", requestHandler);
|
|
5528
5385
|
return recommendedGotoOptions;
|
|
@@ -5579,7 +5436,7 @@ var DefaultLaunch = {
|
|
|
5579
5436
|
// src/internals/launch/cloakbrowser.js
|
|
5580
5437
|
var import_node_child_process2 = require("node:child_process");
|
|
5581
5438
|
var import_node_util = require("node:util");
|
|
5582
|
-
var
|
|
5439
|
+
var logger8 = createInternalLogger("CloakBrowser");
|
|
5583
5440
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5584
5441
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5585
5442
|
maxConcurrency: 1,
|
|
@@ -5715,7 +5572,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5715
5572
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5716
5573
|
return;
|
|
5717
5574
|
}
|
|
5718
|
-
|
|
5575
|
+
logger8.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5719
5576
|
});
|
|
5720
5577
|
};
|
|
5721
5578
|
var CloakBrowserLaunch = {
|
|
@@ -5729,8 +5586,21 @@ var CloakBrowserLaunch = {
|
|
|
5729
5586
|
return createStableGotoHook(recommendedGotoOptions);
|
|
5730
5587
|
},
|
|
5731
5588
|
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5732
|
-
const
|
|
5733
|
-
return crawlerOptions
|
|
5589
|
+
const runtime2 = await CloakBrowserLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5590
|
+
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5591
|
+
cleanup: {
|
|
5592
|
+
enumerable: false,
|
|
5593
|
+
value: runtime2.cleanup
|
|
5594
|
+
},
|
|
5595
|
+
closeActiveBrowsers: {
|
|
5596
|
+
enumerable: false,
|
|
5597
|
+
value: runtime2.closeActiveBrowsers
|
|
5598
|
+
},
|
|
5599
|
+
forceTerminateActiveProcesses: {
|
|
5600
|
+
enumerable: false,
|
|
5601
|
+
value: runtime2.forceTerminateActiveProcesses
|
|
5602
|
+
}
|
|
5603
|
+
});
|
|
5734
5604
|
},
|
|
5735
5605
|
async buildLaunchOptions(options = {}) {
|
|
5736
5606
|
return await buildCloakLaunchOptions(options);
|
|
@@ -5811,39 +5681,18 @@ var CloakBrowserLaunch = {
|
|
|
5811
5681
|
};
|
|
5812
5682
|
|
|
5813
5683
|
// src/launch.js
|
|
5814
|
-
var
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
if (typeof delegate?.[method] !== "function") {
|
|
5818
|
-
throw new Error(`Launch.${method} is not available in ${getToolkitMode()} mode`);
|
|
5819
|
-
}
|
|
5820
|
-
return delegate[method](...args);
|
|
5821
|
-
};
|
|
5822
|
-
var Launch = {
|
|
5823
|
-
getPlaywrightCrawlerOptions(options = {}) {
|
|
5824
|
-
return callLaunch("getPlaywrightCrawlerOptions", options);
|
|
5825
|
-
},
|
|
5826
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5827
|
-
return callLaunch("resolveProxyConfiguration", proxyConfiguration);
|
|
5828
|
-
},
|
|
5829
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5830
|
-
return callLaunch("extractFingerprintArg", launchOptions);
|
|
5831
|
-
},
|
|
5832
|
-
createStableGotoHook(recommendedGotoOptions = {}) {
|
|
5833
|
-
return callLaunch("createStableGotoHook", recommendedGotoOptions);
|
|
5834
|
-
},
|
|
5835
|
-
buildLaunchOptions(options = {}) {
|
|
5836
|
-
return callLaunch("buildLaunchOptions", options);
|
|
5837
|
-
},
|
|
5838
|
-
createPlaywrightCrawlerRuntime(options = {}) {
|
|
5839
|
-
return callLaunch("createPlaywrightCrawlerRuntime", options);
|
|
5840
|
-
}
|
|
5684
|
+
var launchStrategies = {
|
|
5685
|
+
[Mode.Default]: DefaultLaunch,
|
|
5686
|
+
[Mode.CloakBrowser]: CloakBrowserLaunch
|
|
5841
5687
|
};
|
|
5688
|
+
var Launch = createDelegatedFacade("Launch", launchStrategies, [
|
|
5689
|
+
"getPlaywrightCrawlerOptions"
|
|
5690
|
+
]);
|
|
5842
5691
|
|
|
5843
5692
|
// src/live-view.js
|
|
5844
5693
|
var import_express = __toESM(require("express"), 1);
|
|
5845
5694
|
var import_apify = require("apify");
|
|
5846
|
-
var
|
|
5695
|
+
var logger9 = createInternalLogger("LiveView");
|
|
5847
5696
|
async function startLiveViewServer(liveViewKey) {
|
|
5848
5697
|
const app = (0, import_express.default)();
|
|
5849
5698
|
app.get("/", async (req, res) => {
|
|
@@ -5868,13 +5717,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5868
5717
|
</html>
|
|
5869
5718
|
`);
|
|
5870
5719
|
} catch (error) {
|
|
5871
|
-
|
|
5720
|
+
logger9.fail("Live View Server", error);
|
|
5872
5721
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5873
5722
|
}
|
|
5874
5723
|
});
|
|
5875
5724
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5876
5725
|
app.listen(port, () => {
|
|
5877
|
-
|
|
5726
|
+
logger9.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5878
5727
|
});
|
|
5879
5728
|
}
|
|
5880
5729
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5882,10 +5731,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5882
5731
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5883
5732
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5884
5733
|
if (logMessage) {
|
|
5885
|
-
|
|
5734
|
+
logger9.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5886
5735
|
}
|
|
5887
5736
|
} catch (e) {
|
|
5888
|
-
|
|
5737
|
+
logger9.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5889
5738
|
}
|
|
5890
5739
|
}
|
|
5891
5740
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5994,7 +5843,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5994
5843
|
};
|
|
5995
5844
|
|
|
5996
5845
|
// src/internals/captcha/bytedance.js
|
|
5997
|
-
var
|
|
5846
|
+
var logger10 = createInternalLogger("Captcha");
|
|
5998
5847
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5999
5848
|
apiType: "31234",
|
|
6000
5849
|
maxRetries: 3,
|
|
@@ -6126,7 +5975,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
6126
5975
|
}
|
|
6127
5976
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
6128
5977
|
}
|
|
6129
|
-
|
|
5978
|
+
logger10.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
6130
5979
|
};
|
|
6131
5980
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
6132
5981
|
if (!options.debugArtifacts) {
|
|
@@ -6163,14 +6012,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6163
6012
|
if (!isContainerVisible) {
|
|
6164
6013
|
return null;
|
|
6165
6014
|
}
|
|
6166
|
-
|
|
6015
|
+
logger10.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
6167
6016
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
6168
6017
|
let isIframeVisible = await waitForVisible(
|
|
6169
6018
|
iframeLocator,
|
|
6170
6019
|
options.iframeVisibleTimeoutMs
|
|
6171
6020
|
);
|
|
6172
6021
|
if (!isIframeVisible) {
|
|
6173
|
-
|
|
6022
|
+
logger10.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
6174
6023
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
6175
6024
|
isIframeVisible = await waitForVisible(
|
|
6176
6025
|
iframeLocator,
|
|
@@ -6180,7 +6029,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6180
6029
|
if (!isIframeVisible) {
|
|
6181
6030
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
6182
6031
|
}
|
|
6183
|
-
|
|
6032
|
+
logger10.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
6184
6033
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
6185
6034
|
if (!frame) {
|
|
6186
6035
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -6296,11 +6145,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
6296
6145
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
6297
6146
|
...options,
|
|
6298
6147
|
page,
|
|
6299
|
-
logger:
|
|
6148
|
+
logger: logger10,
|
|
6300
6149
|
forceMouse: true
|
|
6301
6150
|
}).catch(() => false);
|
|
6302
6151
|
if (!clicked) {
|
|
6303
|
-
|
|
6152
|
+
logger10.warn("Refresh button not found.");
|
|
6304
6153
|
return false;
|
|
6305
6154
|
}
|
|
6306
6155
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6331,24 +6180,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6331
6180
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6332
6181
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6333
6182
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6334
|
-
|
|
6183
|
+
logger10.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");
|
|
6335
6184
|
hasLoggedGuideMask = true;
|
|
6336
6185
|
}
|
|
6337
6186
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6338
|
-
|
|
6187
|
+
logger10.info(
|
|
6339
6188
|
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"
|
|
6340
6189
|
);
|
|
6341
6190
|
return;
|
|
6342
6191
|
}
|
|
6343
6192
|
if (hasErrorTextVisible) {
|
|
6344
|
-
|
|
6193
|
+
logger10.warn("\u9A8C\u8BC1\u7801\u9762\u677F\u51FA\u73B0\u7F51\u7EDC\u5F02\u5E38\u6587\u6848\uFF0C\u5C1D\u8BD5\u7ACB\u5373\u5237\u65B0\u9898\u76EE\u3002");
|
|
6345
6194
|
await refreshCaptcha(page, frame, options);
|
|
6346
6195
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6347
6196
|
hasSeenLoading = false;
|
|
6348
6197
|
continue;
|
|
6349
6198
|
}
|
|
6350
6199
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6351
|
-
|
|
6200
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u9898\u76EE\u8D85\u8FC7 ${options.challengeReadyRefreshTimeoutMs}ms \u4ECD\u672A\u51C6\u5907\u597D\uFF0C\u5C1D\u8BD5\u5237\u65B0\u9898\u76EE\u3002`);
|
|
6352
6201
|
await refreshCaptcha(page, frame, options);
|
|
6353
6202
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6354
6203
|
hasSeenLoading = false;
|
|
@@ -6396,7 +6245,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6396
6245
|
accepted
|
|
6397
6246
|
};
|
|
6398
6247
|
dragAttempts.push(attemptInfo);
|
|
6399
|
-
|
|
6248
|
+
logger10.info(
|
|
6400
6249
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6401
6250
|
);
|
|
6402
6251
|
if (accepted) {
|
|
@@ -6414,7 +6263,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6414
6263
|
dragAttempts,
|
|
6415
6264
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6416
6265
|
}).catch((error) => {
|
|
6417
|
-
|
|
6266
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6418
6267
|
});
|
|
6419
6268
|
return {
|
|
6420
6269
|
accepted: false,
|
|
@@ -6431,16 +6280,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6431
6280
|
...options
|
|
6432
6281
|
};
|
|
6433
6282
|
if (!config.token) {
|
|
6434
|
-
|
|
6283
|
+
logger10.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6435
6284
|
return false;
|
|
6436
6285
|
}
|
|
6437
|
-
|
|
6286
|
+
logger10.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6438
6287
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6439
|
-
|
|
6288
|
+
logger10.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6440
6289
|
try {
|
|
6441
6290
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6442
6291
|
if (!captchaContext) {
|
|
6443
|
-
|
|
6292
|
+
logger10.info("Captcha container is not visible anymore.");
|
|
6444
6293
|
return true;
|
|
6445
6294
|
}
|
|
6446
6295
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6453,7 +6302,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6453
6302
|
"ready",
|
|
6454
6303
|
config
|
|
6455
6304
|
).catch((error) => {
|
|
6456
|
-
|
|
6305
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6457
6306
|
});
|
|
6458
6307
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6459
6308
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6465,16 +6314,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6465
6314
|
});
|
|
6466
6315
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6467
6316
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6468
|
-
|
|
6317
|
+
logger10.warn(
|
|
6469
6318
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6470
6319
|
);
|
|
6471
6320
|
await refreshCaptcha(page, frame, config);
|
|
6472
6321
|
continue;
|
|
6473
6322
|
}
|
|
6474
|
-
|
|
6323
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6475
6324
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6476
6325
|
if (!dropTarget) {
|
|
6477
|
-
|
|
6326
|
+
logger10.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6478
6327
|
await refreshCaptcha(page, frame, config);
|
|
6479
6328
|
continue;
|
|
6480
6329
|
}
|
|
@@ -6485,7 +6334,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6485
6334
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6486
6335
|
);
|
|
6487
6336
|
}
|
|
6488
|
-
|
|
6337
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6489
6338
|
for (const imageIndex of normalizedIndexes) {
|
|
6490
6339
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6491
6340
|
throw new Error(
|
|
@@ -6517,52 +6366,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6517
6366
|
}
|
|
6518
6367
|
}
|
|
6519
6368
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6520
|
-
|
|
6369
|
+
logger10.info(
|
|
6521
6370
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6522
6371
|
);
|
|
6523
6372
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6524
6373
|
...config,
|
|
6525
6374
|
page,
|
|
6526
|
-
logger:
|
|
6375
|
+
logger: logger10,
|
|
6527
6376
|
forceMouse: true,
|
|
6528
6377
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6529
6378
|
}).catch(() => false);
|
|
6530
6379
|
if (!submitted) {
|
|
6531
|
-
|
|
6380
|
+
logger10.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6532
6381
|
}
|
|
6533
6382
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6534
6383
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6535
|
-
|
|
6384
|
+
logger10.info(
|
|
6536
6385
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6537
6386
|
);
|
|
6538
6387
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6539
6388
|
if (!stillVisible) {
|
|
6540
|
-
|
|
6389
|
+
logger10.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6541
6390
|
return true;
|
|
6542
6391
|
}
|
|
6543
6392
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6544
6393
|
beforeSubmitState,
|
|
6545
6394
|
afterSubmitState
|
|
6546
6395
|
}).catch((error) => {
|
|
6547
|
-
|
|
6396
|
+
logger10.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6548
6397
|
});
|
|
6549
|
-
|
|
6398
|
+
logger10.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6550
6399
|
await page.waitForTimeout(2e3);
|
|
6551
6400
|
await refreshCaptcha(page, frame, config);
|
|
6552
6401
|
} catch (error) {
|
|
6553
|
-
|
|
6402
|
+
logger10.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6554
6403
|
}
|
|
6555
6404
|
if (attempt < config.maxRetries) {
|
|
6556
6405
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6557
6406
|
}
|
|
6558
6407
|
}
|
|
6559
|
-
|
|
6408
|
+
logger10.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6560
6409
|
return false;
|
|
6561
6410
|
}
|
|
6562
6411
|
var sloveCaptcha = solveCaptcha;
|
|
6563
6412
|
|
|
6564
6413
|
// src/chaptcha.js
|
|
6565
|
-
var
|
|
6414
|
+
var logger11 = createInternalLogger("Captcha");
|
|
6566
6415
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6567
6416
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6568
6417
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6649,7 +6498,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6649
6498
|
};
|
|
6650
6499
|
})();
|
|
6651
6500
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6652
|
-
|
|
6501
|
+
logger11.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6653
6502
|
cleanupFns.push(async () => {
|
|
6654
6503
|
try {
|
|
6655
6504
|
await page.evaluate((name) => {
|
|
@@ -6673,14 +6522,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
6673
6522
|
}
|
|
6674
6523
|
};
|
|
6675
6524
|
page.on("framenavigated", frameHandler);
|
|
6676
|
-
|
|
6525
|
+
logger11.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6677
6526
|
cleanupFns.push(async () => {
|
|
6678
6527
|
page.off("framenavigated", frameHandler);
|
|
6679
6528
|
});
|
|
6680
6529
|
}
|
|
6681
6530
|
return {
|
|
6682
6531
|
stop: async () => {
|
|
6683
|
-
|
|
6532
|
+
logger11.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6684
6533
|
for (const fn of cleanupFns) {
|
|
6685
6534
|
await fn();
|
|
6686
6535
|
}
|
|
@@ -6719,7 +6568,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6719
6568
|
);
|
|
6720
6569
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6721
6570
|
callCaptchaRecognitionApi,
|
|
6722
|
-
logger:
|
|
6571
|
+
logger: logger11
|
|
6723
6572
|
});
|
|
6724
6573
|
}
|
|
6725
6574
|
var Captcha = {
|
|
@@ -6730,7 +6579,7 @@ var Captcha = {
|
|
|
6730
6579
|
// src/mutation.js
|
|
6731
6580
|
var import_node_crypto = require("node:crypto");
|
|
6732
6581
|
var import_uuid2 = require("uuid");
|
|
6733
|
-
var
|
|
6582
|
+
var logger12 = createInternalLogger("Mutation");
|
|
6734
6583
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6735
6584
|
Added: "added",
|
|
6736
6585
|
Changed: "changed",
|
|
@@ -6763,14 +6612,14 @@ var Mutation = {
|
|
|
6763
6612
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6764
6613
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6765
6614
|
const onMutation = options.onMutation;
|
|
6766
|
-
|
|
6615
|
+
logger12.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6767
6616
|
if (initialTimeout > 0) {
|
|
6768
6617
|
const selectorQuery = selectorList.join(",");
|
|
6769
6618
|
try {
|
|
6770
6619
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6771
|
-
|
|
6620
|
+
logger12.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6772
6621
|
} catch (e) {
|
|
6773
|
-
|
|
6622
|
+
logger12.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6774
6623
|
throw e;
|
|
6775
6624
|
}
|
|
6776
6625
|
}
|
|
@@ -6786,7 +6635,7 @@ var Mutation = {
|
|
|
6786
6635
|
return "__CONTINUE__";
|
|
6787
6636
|
}
|
|
6788
6637
|
});
|
|
6789
|
-
|
|
6638
|
+
logger12.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6790
6639
|
} catch (e) {
|
|
6791
6640
|
}
|
|
6792
6641
|
}
|
|
@@ -6901,9 +6750,9 @@ var Mutation = {
|
|
|
6901
6750
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6902
6751
|
);
|
|
6903
6752
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6904
|
-
|
|
6753
|
+
logger12.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6905
6754
|
}
|
|
6906
|
-
|
|
6755
|
+
logger12.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6907
6756
|
return result;
|
|
6908
6757
|
},
|
|
6909
6758
|
/**
|
|
@@ -7075,29 +6924,29 @@ var Mutation = {
|
|
|
7075
6924
|
return "__CONTINUE__";
|
|
7076
6925
|
}
|
|
7077
6926
|
};
|
|
7078
|
-
|
|
6927
|
+
logger12.start(
|
|
7079
6928
|
"waitForStableAcrossRoots",
|
|
7080
6929
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
7081
6930
|
);
|
|
7082
6931
|
if (initialTimeout > 0) {
|
|
7083
6932
|
try {
|
|
7084
6933
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
7085
|
-
|
|
6934
|
+
logger12.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
7086
6935
|
} catch (e) {
|
|
7087
|
-
|
|
6936
|
+
logger12.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
7088
6937
|
throw e;
|
|
7089
6938
|
}
|
|
7090
6939
|
}
|
|
7091
|
-
let
|
|
7092
|
-
if (!
|
|
7093
|
-
|
|
6940
|
+
let state2 = await buildState();
|
|
6941
|
+
if (!state2?.hasMatched) {
|
|
6942
|
+
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7094
6943
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
7095
6944
|
}
|
|
7096
6945
|
let mutationCount = 0;
|
|
7097
6946
|
let stableSince = 0;
|
|
7098
6947
|
let isPaused = false;
|
|
7099
6948
|
let wasPaused = false;
|
|
7100
|
-
let lastSnapshotKey =
|
|
6949
|
+
let lastSnapshotKey = state2.snapshotKey;
|
|
7101
6950
|
const applyPauseSignal = (signal) => {
|
|
7102
6951
|
const nextPaused = signal === "__PAUSE__";
|
|
7103
6952
|
if (nextPaused) {
|
|
@@ -7111,13 +6960,13 @@ var Mutation = {
|
|
|
7111
6960
|
};
|
|
7112
6961
|
const initialSignal = await invokeMutationCallback({
|
|
7113
6962
|
mutationCount: 0,
|
|
7114
|
-
html:
|
|
7115
|
-
text:
|
|
7116
|
-
mutationNodes:
|
|
6963
|
+
html: state2.html || "",
|
|
6964
|
+
text: state2.text || "",
|
|
6965
|
+
mutationNodes: state2.mutationNodes || []
|
|
7117
6966
|
});
|
|
7118
6967
|
applyPauseSignal(initialSignal);
|
|
7119
6968
|
const deadline = Date.now() + overallTimeout;
|
|
7120
|
-
let lastState =
|
|
6969
|
+
let lastState = state2;
|
|
7121
6970
|
while (Date.now() < deadline) {
|
|
7122
6971
|
await sleep(pollInterval);
|
|
7123
6972
|
lastState = await buildState();
|
|
@@ -7127,7 +6976,7 @@ var Mutation = {
|
|
|
7127
6976
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
7128
6977
|
lastSnapshotKey = lastState.snapshotKey;
|
|
7129
6978
|
mutationCount += 1;
|
|
7130
|
-
|
|
6979
|
+
logger12.info(
|
|
7131
6980
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
7132
6981
|
);
|
|
7133
6982
|
const signal = await invokeMutationCallback({
|
|
@@ -7140,7 +6989,7 @@ var Mutation = {
|
|
|
7140
6989
|
continue;
|
|
7141
6990
|
}
|
|
7142
6991
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
7143
|
-
|
|
6992
|
+
logger12.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7144
6993
|
return {
|
|
7145
6994
|
mutationCount,
|
|
7146
6995
|
stableTime: waitForStableTime,
|
|
@@ -7167,7 +7016,7 @@ var Mutation = {
|
|
|
7167
7016
|
const onMutation = options.onMutation;
|
|
7168
7017
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
7169
7018
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
7170
|
-
|
|
7019
|
+
logger12.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
7171
7020
|
const monitorKey = generateKey("pk_mon");
|
|
7172
7021
|
const callbackName = generateKey("pk_mon_cb");
|
|
7173
7022
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7310,7 +7159,7 @@ var Mutation = {
|
|
|
7310
7159
|
return total;
|
|
7311
7160
|
};
|
|
7312
7161
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7313
|
-
|
|
7162
|
+
logger12.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7314
7163
|
return {
|
|
7315
7164
|
stop: async () => {
|
|
7316
7165
|
let totalMutations = 0;
|
|
@@ -7323,7 +7172,7 @@ var Mutation = {
|
|
|
7323
7172
|
}, cleanerName);
|
|
7324
7173
|
} catch (e) {
|
|
7325
7174
|
}
|
|
7326
|
-
|
|
7175
|
+
logger12.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7327
7176
|
return { totalMutations };
|
|
7328
7177
|
}
|
|
7329
7178
|
};
|
|
@@ -8192,7 +8041,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
8192
8041
|
};
|
|
8193
8042
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
8194
8043
|
var Logger = {
|
|
8195
|
-
setLogger: (
|
|
8044
|
+
setLogger: (logger16) => setDefaultLogger(logger16),
|
|
8196
8045
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
8197
8046
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
8198
8047
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -8200,8 +8049,8 @@ var Logger = {
|
|
|
8200
8049
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
8201
8050
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
8202
8051
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
8203
|
-
useTemplate: (
|
|
8204
|
-
if (
|
|
8052
|
+
useTemplate: (logger16) => {
|
|
8053
|
+
if (logger16) return createTemplateLogger(createBaseLogger("", logger16));
|
|
8205
8054
|
return createTemplateLogger();
|
|
8206
8055
|
}
|
|
8207
8056
|
};
|
|
@@ -8275,7 +8124,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
8275
8124
|
];
|
|
8276
8125
|
var cachedStripLogoSrcPromise = null;
|
|
8277
8126
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
8278
|
-
var
|
|
8127
|
+
var logger13 = createInternalLogger("Watermarkify");
|
|
8279
8128
|
var normalizeText = (value) => String(value || "").trim();
|
|
8280
8129
|
var toInline = (value, maxLen = 200) => {
|
|
8281
8130
|
const text = normalizeText(value);
|
|
@@ -8517,9 +8366,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8517
8366
|
location: toInline(resolved.location, 80)
|
|
8518
8367
|
};
|
|
8519
8368
|
if (enrichment.ip || enrichment.location) {
|
|
8520
|
-
|
|
8369
|
+
logger13.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8521
8370
|
} else {
|
|
8522
|
-
|
|
8371
|
+
logger13.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8523
8372
|
}
|
|
8524
8373
|
return enrichment;
|
|
8525
8374
|
} finally {
|
|
@@ -8708,12 +8557,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8708
8557
|
};
|
|
8709
8558
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8710
8559
|
if (!page || typeof page.context !== "function") {
|
|
8711
|
-
|
|
8560
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8712
8561
|
return buffer;
|
|
8713
8562
|
}
|
|
8714
8563
|
const renderScope = await openProbePage(page);
|
|
8715
8564
|
if (!renderScope?.page) {
|
|
8716
|
-
|
|
8565
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8717
8566
|
return buffer;
|
|
8718
8567
|
}
|
|
8719
8568
|
try {
|
|
@@ -8778,13 +8627,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8778
8627
|
fullPage: true,
|
|
8779
8628
|
animations: "disabled"
|
|
8780
8629
|
}).catch((error) => {
|
|
8781
|
-
|
|
8630
|
+
logger13.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8782
8631
|
return null;
|
|
8783
8632
|
});
|
|
8784
8633
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8785
8634
|
return composed;
|
|
8786
8635
|
}
|
|
8787
|
-
|
|
8636
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8788
8637
|
return buffer;
|
|
8789
8638
|
} finally {
|
|
8790
8639
|
await renderScope.close().catch(() => {
|
|
@@ -8797,7 +8646,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8797
8646
|
}
|
|
8798
8647
|
const probeScope = await openProbePage(page);
|
|
8799
8648
|
if (!probeScope?.page) {
|
|
8800
|
-
|
|
8649
|
+
logger13.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8801
8650
|
return null;
|
|
8802
8651
|
}
|
|
8803
8652
|
const timeoutMs = Math.max(
|
|
@@ -8806,12 +8655,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8806
8655
|
);
|
|
8807
8656
|
try {
|
|
8808
8657
|
const probePage = probeScope.page;
|
|
8809
|
-
|
|
8658
|
+
logger13.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8810
8659
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8811
8660
|
waitUntil: "commit",
|
|
8812
8661
|
timeout: timeoutMs
|
|
8813
8662
|
}).catch((error) => {
|
|
8814
|
-
|
|
8663
|
+
logger13.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8815
8664
|
return null;
|
|
8816
8665
|
});
|
|
8817
8666
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8833,13 +8682,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8833
8682
|
}
|
|
8834
8683
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8835
8684
|
if (parsed?.ip || parsed?.location) {
|
|
8836
|
-
|
|
8685
|
+
logger13.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8837
8686
|
return parsed;
|
|
8838
8687
|
}
|
|
8839
|
-
|
|
8688
|
+
logger13.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8840
8689
|
return null;
|
|
8841
8690
|
} catch (error) {
|
|
8842
|
-
|
|
8691
|
+
logger13.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8843
8692
|
return null;
|
|
8844
8693
|
} finally {
|
|
8845
8694
|
await probeScope.close().catch(() => {
|
|
@@ -8853,10 +8702,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8853
8702
|
ip: toInline(options.ip, 80),
|
|
8854
8703
|
location: toInline(options.location, 80)
|
|
8855
8704
|
};
|
|
8856
|
-
|
|
8705
|
+
logger13.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8857
8706
|
if (!merged.ip || !merged.location) {
|
|
8858
8707
|
if (cached?.ip || cached?.location) {
|
|
8859
|
-
|
|
8708
|
+
logger13.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8860
8709
|
}
|
|
8861
8710
|
fillEnrichment(merged, cached);
|
|
8862
8711
|
}
|
|
@@ -8880,15 +8729,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8880
8729
|
"x-geo-country"
|
|
8881
8730
|
]), 80);
|
|
8882
8731
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8883
|
-
|
|
8732
|
+
logger13.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8884
8733
|
merged.location = headerLocation || merged.location;
|
|
8885
8734
|
}
|
|
8886
8735
|
}
|
|
8887
8736
|
writeCachedEnrichment(page, merged);
|
|
8888
8737
|
if (merged.ip || merged.location) {
|
|
8889
|
-
|
|
8738
|
+
logger13.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8890
8739
|
} else {
|
|
8891
|
-
|
|
8740
|
+
logger13.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8892
8741
|
}
|
|
8893
8742
|
return merged;
|
|
8894
8743
|
};
|
|
@@ -9701,7 +9550,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9701
9550
|
}
|
|
9702
9551
|
const imageInfo = readImageInfo(buffer);
|
|
9703
9552
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9704
|
-
|
|
9553
|
+
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9705
9554
|
return buffer;
|
|
9706
9555
|
}
|
|
9707
9556
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9719,7 +9568,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9719
9568
|
|
|
9720
9569
|
// src/internals/compression.js
|
|
9721
9570
|
var import_jimp = require("jimp");
|
|
9722
|
-
var
|
|
9571
|
+
var logger14 = createInternalLogger("Compression");
|
|
9723
9572
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9724
9573
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9725
9574
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9838,18 +9687,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9838
9687
|
return buffer.toString("base64");
|
|
9839
9688
|
}
|
|
9840
9689
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9841
|
-
|
|
9690
|
+
logger14.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9842
9691
|
return null;
|
|
9843
9692
|
});
|
|
9844
9693
|
if (!result?.buffer) {
|
|
9845
9694
|
return buffer.toString("base64");
|
|
9846
9695
|
}
|
|
9847
9696
|
if (result.withinLimit) {
|
|
9848
|
-
|
|
9697
|
+
logger14.info(
|
|
9849
9698
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9850
9699
|
);
|
|
9851
9700
|
} else {
|
|
9852
|
-
|
|
9701
|
+
logger14.warning(
|
|
9853
9702
|
`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}`
|
|
9854
9703
|
);
|
|
9855
9704
|
}
|
|
@@ -9857,7 +9706,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9857
9706
|
};
|
|
9858
9707
|
|
|
9859
9708
|
// src/share.js
|
|
9860
|
-
var
|
|
9709
|
+
var logger15 = createInternalLogger("Share");
|
|
9861
9710
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9862
9711
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9863
9712
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9994,7 +9843,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9994
9843
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9995
9844
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9996
9845
|
let matched = false;
|
|
9997
|
-
|
|
9846
|
+
logger15.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9998
9847
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9999
9848
|
mode,
|
|
10000
9849
|
onMutation: (context = {}) => {
|
|
@@ -10012,12 +9861,12 @@ ${text}`;
|
|
|
10012
9861
|
});
|
|
10013
9862
|
}
|
|
10014
9863
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
10015
|
-
|
|
9864
|
+
logger15.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
10016
9865
|
}
|
|
10017
9866
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
10018
9867
|
if (!candidate) return;
|
|
10019
9868
|
matched = true;
|
|
10020
|
-
|
|
9869
|
+
logger15.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
10021
9870
|
if (onMatch) {
|
|
10022
9871
|
onMatch({
|
|
10023
9872
|
link: candidate,
|
|
@@ -10033,7 +9882,7 @@ ${text}`;
|
|
|
10033
9882
|
return {
|
|
10034
9883
|
stop: async () => {
|
|
10035
9884
|
const result = await monitor.stop();
|
|
10036
|
-
|
|
9885
|
+
logger15.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
10037
9886
|
return result;
|
|
10038
9887
|
}
|
|
10039
9888
|
};
|
|
@@ -10082,8 +9931,8 @@ var Share = {
|
|
|
10082
9931
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
10083
9932
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
10084
9933
|
}
|
|
10085
|
-
|
|
10086
|
-
|
|
9934
|
+
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9935
|
+
logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
10087
9936
|
const stats = {
|
|
10088
9937
|
actionTimedOut: false,
|
|
10089
9938
|
domMutationCount: 0,
|
|
@@ -10095,7 +9944,7 @@ var Share = {
|
|
|
10095
9944
|
responseSampleUrls: []
|
|
10096
9945
|
};
|
|
10097
9946
|
if (isAborted()) {
|
|
10098
|
-
|
|
9947
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10099
9948
|
return {
|
|
10100
9949
|
link: null,
|
|
10101
9950
|
payloadText: "",
|
|
@@ -10118,7 +9967,7 @@ var Share = {
|
|
|
10118
9967
|
link: validated,
|
|
10119
9968
|
payloadText: String(payloadText || "")
|
|
10120
9969
|
};
|
|
10121
|
-
|
|
9970
|
+
logger15.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
10122
9971
|
return true;
|
|
10123
9972
|
};
|
|
10124
9973
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -10153,7 +10002,7 @@ var Share = {
|
|
|
10153
10002
|
try {
|
|
10154
10003
|
await monitor.stop();
|
|
10155
10004
|
} catch (error) {
|
|
10156
|
-
|
|
10005
|
+
logger15.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
10157
10006
|
}
|
|
10158
10007
|
};
|
|
10159
10008
|
const onResponse = async (response) => {
|
|
@@ -10167,29 +10016,29 @@ var Share = {
|
|
|
10167
10016
|
stats.responseSampleUrls.push(url);
|
|
10168
10017
|
}
|
|
10169
10018
|
if (stats.responseObserved <= 5) {
|
|
10170
|
-
|
|
10019
|
+
logger15.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
10171
10020
|
}
|
|
10172
10021
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
10173
10022
|
stats.responseMatched += 1;
|
|
10174
10023
|
stats.lastMatchedUrl = url;
|
|
10175
|
-
|
|
10024
|
+
logger15.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
10176
10025
|
const text = await response.text();
|
|
10177
10026
|
const hit = resolveResponseCandidate(text);
|
|
10178
10027
|
if (!hit?.link) {
|
|
10179
10028
|
if (stats.responseMatched <= 3) {
|
|
10180
|
-
|
|
10029
|
+
logger15.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
10181
10030
|
}
|
|
10182
10031
|
return;
|
|
10183
10032
|
}
|
|
10184
10033
|
stats.responseResolved += 1;
|
|
10185
|
-
|
|
10034
|
+
logger15.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
10186
10035
|
setCandidate("response", hit.link, hit.payloadText);
|
|
10187
10036
|
} catch (error) {
|
|
10188
|
-
|
|
10037
|
+
logger15.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
10189
10038
|
}
|
|
10190
10039
|
};
|
|
10191
10040
|
if (share.mode === "dom") {
|
|
10192
|
-
|
|
10041
|
+
logger15.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
10193
10042
|
domMonitor = await createDomShareMonitor(page, {
|
|
10194
10043
|
prefix: share.prefix,
|
|
10195
10044
|
selectors: domSelectors,
|
|
@@ -10204,17 +10053,17 @@ var Share = {
|
|
|
10204
10053
|
});
|
|
10205
10054
|
}
|
|
10206
10055
|
if (share.mode === "response") {
|
|
10207
|
-
|
|
10056
|
+
logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
10208
10057
|
page.on("response", onResponse);
|
|
10209
10058
|
}
|
|
10210
10059
|
if (share.mode === "custom") {
|
|
10211
|
-
|
|
10060
|
+
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
10212
10061
|
}
|
|
10213
10062
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
10214
10063
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
10215
10064
|
try {
|
|
10216
10065
|
const actionTimeout = getRemainingMs();
|
|
10217
|
-
|
|
10066
|
+
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
10218
10067
|
let actionValue;
|
|
10219
10068
|
if (!isAborted() && actionTimeout > 0) {
|
|
10220
10069
|
let timer = null;
|
|
@@ -10227,30 +10076,30 @@ var Share = {
|
|
|
10227
10076
|
]);
|
|
10228
10077
|
if (timer) clearTimeout(timer);
|
|
10229
10078
|
if (actionResult.type === "error") {
|
|
10230
|
-
|
|
10079
|
+
logger15.fail("captureLink.performActions", actionResult.error);
|
|
10231
10080
|
throw actionResult.error;
|
|
10232
10081
|
}
|
|
10233
10082
|
if (actionResult.type === "timeout") {
|
|
10234
10083
|
stats.actionTimedOut = true;
|
|
10235
|
-
|
|
10084
|
+
logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
10236
10085
|
} else {
|
|
10237
10086
|
actionValue = actionResult.result;
|
|
10238
|
-
|
|
10087
|
+
logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
10239
10088
|
}
|
|
10240
10089
|
}
|
|
10241
10090
|
if (share.mode === "custom") {
|
|
10242
10091
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
10243
10092
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
10244
10093
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
10245
|
-
|
|
10094
|
+
logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
10246
10095
|
} else {
|
|
10247
|
-
|
|
10096
|
+
logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
10248
10097
|
}
|
|
10249
10098
|
}
|
|
10250
10099
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
10251
10100
|
while (true) {
|
|
10252
10101
|
if (isAborted()) {
|
|
10253
|
-
|
|
10102
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10254
10103
|
return {
|
|
10255
10104
|
link: null,
|
|
10256
10105
|
payloadText: "",
|
|
@@ -10260,7 +10109,7 @@ var Share = {
|
|
|
10260
10109
|
}
|
|
10261
10110
|
const selected = candidates[share.mode];
|
|
10262
10111
|
if (selected?.link) {
|
|
10263
|
-
|
|
10112
|
+
logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
10264
10113
|
return {
|
|
10265
10114
|
link: selected.link,
|
|
10266
10115
|
payloadText: selected.payloadText,
|
|
@@ -10273,7 +10122,7 @@ var Share = {
|
|
|
10273
10122
|
if (remaining <= 0) break;
|
|
10274
10123
|
const now = Date.now();
|
|
10275
10124
|
if (now >= nextProgressLogTs) {
|
|
10276
|
-
|
|
10125
|
+
logger15.info(
|
|
10277
10126
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
10278
10127
|
);
|
|
10279
10128
|
nextProgressLogTs = now + 5e3;
|
|
@@ -10281,11 +10130,11 @@ var Share = {
|
|
|
10281
10130
|
await (0, import_delay5.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10282
10131
|
}
|
|
10283
10132
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10284
|
-
|
|
10133
|
+
logger15.warning(
|
|
10285
10134
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
10286
10135
|
);
|
|
10287
10136
|
}
|
|
10288
|
-
|
|
10137
|
+
logger15.warning(
|
|
10289
10138
|
`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"}`
|
|
10290
10139
|
);
|
|
10291
10140
|
return {
|
|
@@ -10297,7 +10146,7 @@ var Share = {
|
|
|
10297
10146
|
} finally {
|
|
10298
10147
|
if (share.mode === "response") {
|
|
10299
10148
|
page.off("response", onResponse);
|
|
10300
|
-
|
|
10149
|
+
logger15.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10301
10150
|
}
|
|
10302
10151
|
await stopDomMonitor();
|
|
10303
10152
|
}
|