@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.js
CHANGED
|
@@ -360,18 +360,18 @@ var fallbackLog = {
|
|
|
360
360
|
error: (...args) => console.error(...args),
|
|
361
361
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
362
362
|
};
|
|
363
|
-
var resolveLogMethod = (
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
363
|
+
var resolveLogMethod = (logger16, name) => {
|
|
364
|
+
if (logger16 && typeof logger16[name] === "function") {
|
|
365
|
+
return logger16[name].bind(logger16);
|
|
366
366
|
}
|
|
367
|
-
if (name === "warning" &&
|
|
368
|
-
return
|
|
367
|
+
if (name === "warning" && logger16 && typeof logger16.warn === "function") {
|
|
368
|
+
return logger16.warn.bind(logger16);
|
|
369
369
|
}
|
|
370
370
|
return fallbackLog[name];
|
|
371
371
|
};
|
|
372
372
|
var defaultLogger = null;
|
|
373
|
-
var setDefaultLogger = (
|
|
374
|
-
defaultLogger =
|
|
373
|
+
var setDefaultLogger = (logger16) => {
|
|
374
|
+
defaultLogger = logger16;
|
|
375
375
|
};
|
|
376
376
|
var resolveLogger = (explicitLogger) => {
|
|
377
377
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -398,8 +398,8 @@ var colorize = (text, color) => {
|
|
|
398
398
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
399
399
|
const name = prefix ? String(prefix) : "";
|
|
400
400
|
const dispatch = (methodName, icon, message, color) => {
|
|
401
|
-
const
|
|
402
|
-
const logFn = resolveLogMethod(
|
|
401
|
+
const logger16 = resolveLogger(explicitLogger);
|
|
402
|
+
const logFn = resolveLogMethod(logger16, methodName);
|
|
403
403
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
404
404
|
const line = formatLine(name, icon, message);
|
|
405
405
|
const coloredLine = colorize(line, color);
|
|
@@ -896,7 +896,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
896
896
|
viewportResized
|
|
897
897
|
};
|
|
898
898
|
};
|
|
899
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
899
|
+
var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
900
900
|
await page.evaluate((className) => {
|
|
901
901
|
const targets = new Set([
|
|
902
902
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -920,8 +920,8 @@ var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
|
920
920
|
el.classList.remove(className);
|
|
921
921
|
});
|
|
922
922
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
923
|
-
if (
|
|
924
|
-
await page.setViewportSize(
|
|
923
|
+
if (state2?.originalViewport && state2?.viewportResized) {
|
|
924
|
+
await page.setViewportSize(state2.originalViewport);
|
|
925
925
|
}
|
|
926
926
|
};
|
|
927
927
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -978,21 +978,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
978
978
|
}
|
|
979
979
|
};
|
|
980
980
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
981
|
-
const
|
|
981
|
+
const state2 = await prepareExpandedFullPageScreenshot(page, options);
|
|
982
982
|
try {
|
|
983
983
|
return await capturePageScreenshot(page, {
|
|
984
984
|
fullPage: true,
|
|
985
985
|
type: options.type || "png",
|
|
986
986
|
quality: options.quality,
|
|
987
987
|
timeout: options.timeout,
|
|
988
|
-
maxClipHeight:
|
|
988
|
+
maxClipHeight: state2.targetHeight
|
|
989
989
|
});
|
|
990
990
|
} finally {
|
|
991
991
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
992
992
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
993
993
|
});
|
|
994
994
|
if (options.restore) {
|
|
995
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
995
|
+
await restoreExpandedFullPageScreenshot(page, state2);
|
|
996
996
|
}
|
|
997
997
|
}
|
|
998
998
|
};
|
|
@@ -1887,8 +1887,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1887
1887
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1888
1888
|
};
|
|
1889
1889
|
};
|
|
1890
|
-
var rememberRuntimeState = (
|
|
1891
|
-
rememberedRuntimeState = deepClone(
|
|
1890
|
+
var rememberRuntimeState = (state2) => {
|
|
1891
|
+
rememberedRuntimeState = deepClone(state2);
|
|
1892
1892
|
return rememberedRuntimeState;
|
|
1893
1893
|
};
|
|
1894
1894
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1947,7 +1947,7 @@ var RuntimeEnv = {
|
|
|
1947
1947
|
} else {
|
|
1948
1948
|
delete normalizedRuntime.browser_profile;
|
|
1949
1949
|
}
|
|
1950
|
-
const
|
|
1950
|
+
const state2 = {
|
|
1951
1951
|
actor: resolvedActor,
|
|
1952
1952
|
device,
|
|
1953
1953
|
runtime: normalizedRuntime,
|
|
@@ -1961,73 +1961,73 @@ var RuntimeEnv = {
|
|
|
1961
1961
|
browserProfileCore: browserProfile.core,
|
|
1962
1962
|
browserProfileObserved: browserProfile.observed
|
|
1963
1963
|
};
|
|
1964
|
-
rememberRuntimeState(
|
|
1965
|
-
return
|
|
1964
|
+
rememberRuntimeState(state2);
|
|
1965
|
+
return state2;
|
|
1966
1966
|
},
|
|
1967
1967
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
1968
1968
|
buildEnvPatch(source = {}, actor = "") {
|
|
1969
|
-
const
|
|
1970
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
1969
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
1970
|
+
const browserProfile = buildBrowserProfilePayload(state2.browserProfileCore, state2.browserProfileObserved);
|
|
1971
1971
|
const envPatch = {
|
|
1972
|
-
...Array.isArray(
|
|
1973
|
-
...Object.keys(
|
|
1974
|
-
...Object.keys(
|
|
1972
|
+
...Array.isArray(state2.cookies) && state2.cookies.length > 0 ? { cookies: state2.cookies } : {},
|
|
1973
|
+
...Object.keys(state2.localStorage || {}).length > 0 ? { local_storage: state2.localStorage } : {},
|
|
1974
|
+
...Object.keys(state2.sessionStorage || {}).length > 0 ? { session_storage: state2.sessionStorage } : {},
|
|
1975
1975
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
1976
1976
|
};
|
|
1977
1977
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
1978
1978
|
},
|
|
1979
1979
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
1980
1980
|
hasLoginState(source = {}, actor = "") {
|
|
1981
|
-
const
|
|
1982
|
-
return isPlainObject(
|
|
1981
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
1982
|
+
return isPlainObject(state2.runtime) && Object.keys(state2.runtime || {}).length > 0;
|
|
1983
1983
|
},
|
|
1984
1984
|
rememberState(source = {}) {
|
|
1985
|
-
const
|
|
1986
|
-
rememberRuntimeState(
|
|
1985
|
+
const state2 = normalizeRuntimeState(source);
|
|
1986
|
+
rememberRuntimeState(state2);
|
|
1987
1987
|
return RuntimeEnv.peekRememberedState();
|
|
1988
1988
|
},
|
|
1989
1989
|
peekRememberedState() {
|
|
1990
1990
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
1991
1991
|
},
|
|
1992
1992
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
1993
|
-
const
|
|
1994
|
-
return deepClone(
|
|
1993
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
1994
|
+
return deepClone(state2.browserProfileCore || {});
|
|
1995
1995
|
},
|
|
1996
1996
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
1997
|
-
const
|
|
1997
|
+
const state2 = normalizeRuntimeState(source, actor);
|
|
1998
1998
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
1999
1999
|
...core,
|
|
2000
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2000
|
+
device: normalizeKnownDevice(core?.device) || state2.device
|
|
2001
2001
|
});
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
if (Object.keys(
|
|
2005
|
-
|
|
2002
|
+
state2.browserProfileCore = normalizedCore;
|
|
2003
|
+
state2.browserProfile = buildBrowserProfilePayload(normalizedCore, state2.browserProfileObserved);
|
|
2004
|
+
if (Object.keys(state2.browserProfile).length > 0) {
|
|
2005
|
+
state2.runtime.browser_profile = state2.browserProfile;
|
|
2006
2006
|
} else {
|
|
2007
|
-
delete
|
|
2007
|
+
delete state2.runtime.browser_profile;
|
|
2008
2008
|
}
|
|
2009
|
-
rememberRuntimeState(
|
|
2010
|
-
return
|
|
2009
|
+
rememberRuntimeState(state2);
|
|
2010
|
+
return state2;
|
|
2011
2011
|
},
|
|
2012
2012
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2013
2013
|
// cookies / localStorage / sessionStorage。
|
|
2014
2014
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2015
2015
|
async applyToPage(page, source = {}, options = {}) {
|
|
2016
2016
|
if (!page) return;
|
|
2017
|
-
let
|
|
2017
|
+
let state2 = normalizeRuntimeState(source, options?.actor || "");
|
|
2018
2018
|
if (typeof options?.preapply === "function") {
|
|
2019
|
-
|
|
2020
|
-
rememberRuntimeState(
|
|
2019
|
+
state2 = await options.preapply(state2) || state2;
|
|
2020
|
+
rememberRuntimeState(state2);
|
|
2021
2021
|
}
|
|
2022
2022
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2023
2023
|
configurable: true,
|
|
2024
2024
|
enumerable: false,
|
|
2025
2025
|
writable: true,
|
|
2026
|
-
value:
|
|
2026
|
+
value: state2
|
|
2027
2027
|
});
|
|
2028
|
-
const localStorage =
|
|
2029
|
-
const sessionStorage =
|
|
2030
|
-
const cookies = (
|
|
2028
|
+
const localStorage = state2.localStorage || {};
|
|
2029
|
+
const sessionStorage = state2.sessionStorage || {};
|
|
2030
|
+
const cookies = (state2.cookies || []).map((cookie) => {
|
|
2031
2031
|
const normalized = { ...cookie };
|
|
2032
2032
|
if (!normalized.path) {
|
|
2033
2033
|
normalized.path = "/";
|
|
@@ -2065,8 +2065,8 @@ var RuntimeEnv = {
|
|
|
2065
2065
|
},
|
|
2066
2066
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2067
2067
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2068
|
-
const
|
|
2069
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2068
|
+
const state2 = normalizeRuntimeState(source, options?.actor || "");
|
|
2069
|
+
const baseline = RuntimeEnv.buildEnvPatch(state2) || {};
|
|
2070
2070
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2071
2071
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2072
2072
|
}
|
|
@@ -2085,7 +2085,7 @@ var RuntimeEnv = {
|
|
|
2085
2085
|
cookies
|
|
2086
2086
|
},
|
|
2087
2087
|
{
|
|
2088
|
-
browserProfileCore:
|
|
2088
|
+
browserProfileCore: state2.browserProfileCore
|
|
2089
2089
|
}
|
|
2090
2090
|
);
|
|
2091
2091
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2099,11 +2099,11 @@ var RuntimeEnv = {
|
|
|
2099
2099
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2100
2100
|
var resolveRuntimeContext = (input) => {
|
|
2101
2101
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2102
|
-
const
|
|
2103
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2102
|
+
const state2 = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2103
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state2) || null;
|
|
2104
2104
|
return {
|
|
2105
|
-
actor:
|
|
2106
|
-
runtime:
|
|
2105
|
+
actor: state2.actor,
|
|
2106
|
+
runtime: state2.runtime,
|
|
2107
2107
|
envPatch
|
|
2108
2108
|
};
|
|
2109
2109
|
};
|
|
@@ -2462,6 +2462,57 @@ var Utils = {
|
|
|
2462
2462
|
}
|
|
2463
2463
|
};
|
|
2464
2464
|
|
|
2465
|
+
// src/internals/context.js
|
|
2466
|
+
var state = {
|
|
2467
|
+
mode: Mode.Default
|
|
2468
|
+
};
|
|
2469
|
+
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2470
|
+
var ToolkitContext = {
|
|
2471
|
+
get mode() {
|
|
2472
|
+
return state.mode;
|
|
2473
|
+
},
|
|
2474
|
+
setMode(mode = Mode.Default) {
|
|
2475
|
+
state.mode = normalizeMode(mode, Mode.Default);
|
|
2476
|
+
return state.mode;
|
|
2477
|
+
}
|
|
2478
|
+
};
|
|
2479
|
+
var getToolkitMode = () => state.mode;
|
|
2480
|
+
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2481
|
+
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2482
|
+
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2483
|
+
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2484
|
+
const delegate = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2485
|
+
return {
|
|
2486
|
+
mode: normalizedMode,
|
|
2487
|
+
delegate
|
|
2488
|
+
};
|
|
2489
|
+
};
|
|
2490
|
+
|
|
2491
|
+
// src/internals/delegate.js
|
|
2492
|
+
var normalizeMethodDefinition = (definition) => typeof definition === "string" ? { name: definition, enumerable: true } : {
|
|
2493
|
+
name: String(definition?.name || "").trim(),
|
|
2494
|
+
enumerable: definition?.enumerable !== false
|
|
2495
|
+
};
|
|
2496
|
+
var createMethodDescriptor = (namespace, methodName, enumerable, strategies) => ({
|
|
2497
|
+
enumerable,
|
|
2498
|
+
value: (...args) => {
|
|
2499
|
+
const { mode, delegate } = resolveModeStrategy(strategies);
|
|
2500
|
+
if (typeof delegate?.[methodName] !== "function") {
|
|
2501
|
+
throw new Error(`${namespace}.${methodName} is not available in ${mode} mode`);
|
|
2502
|
+
}
|
|
2503
|
+
return delegate[methodName](...args);
|
|
2504
|
+
}
|
|
2505
|
+
});
|
|
2506
|
+
var createDelegatedFacade = (namespace, strategies = {}, methods = []) => {
|
|
2507
|
+
const descriptors = Object.fromEntries(
|
|
2508
|
+
methods.map(normalizeMethodDefinition).filter((method) => method.name).map((method) => [
|
|
2509
|
+
method.name,
|
|
2510
|
+
createMethodDescriptor(namespace, method.name, method.enumerable, strategies)
|
|
2511
|
+
])
|
|
2512
|
+
);
|
|
2513
|
+
return Object.defineProperties({}, descriptors);
|
|
2514
|
+
};
|
|
2515
|
+
|
|
2465
2516
|
// src/internals/anti-cheat/default.js
|
|
2466
2517
|
var BASE_CONFIG = Object.freeze({
|
|
2467
2518
|
locale: "zh-CN",
|
|
@@ -2535,43 +2586,52 @@ var DefaultAntiCheat = {
|
|
|
2535
2586
|
};
|
|
2536
2587
|
|
|
2537
2588
|
// src/internals/anti-cheat/cloakbrowser.js
|
|
2538
|
-
var
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
var callAntiCheat = (method, ...args) => {
|
|
2551
|
-
const delegate = resolveAntiCheatDelegate();
|
|
2552
|
-
if (typeof delegate?.[method] !== "function") {
|
|
2553
|
-
throw new Error(`AntiCheat.${method} is not available in ${getToolkitMode()} mode`);
|
|
2554
|
-
}
|
|
2555
|
-
return delegate[method](...args);
|
|
2556
|
-
};
|
|
2557
|
-
var AntiCheat = {
|
|
2589
|
+
var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
2590
|
+
locale: "",
|
|
2591
|
+
acceptLanguage: "",
|
|
2592
|
+
timezoneId: "",
|
|
2593
|
+
timezoneOffset: null,
|
|
2594
|
+
geolocation: null
|
|
2595
|
+
});
|
|
2596
|
+
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2597
|
+
var CloakBrowserAntiCheat = {
|
|
2598
|
+
/**
|
|
2599
|
+
* CloakBrowser 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2600
|
+
*/
|
|
2558
2601
|
getBaseConfig() {
|
|
2559
|
-
return
|
|
2602
|
+
return { ...CLOAK_BROWSER_BASE_CONFIG };
|
|
2560
2603
|
},
|
|
2561
|
-
getFingerprintGeneratorOptions(
|
|
2562
|
-
return
|
|
2604
|
+
getFingerprintGeneratorOptions() {
|
|
2605
|
+
return {};
|
|
2563
2606
|
},
|
|
2564
|
-
getLaunchArgs(
|
|
2565
|
-
return
|
|
2607
|
+
getLaunchArgs() {
|
|
2608
|
+
return [];
|
|
2566
2609
|
},
|
|
2567
|
-
getTlsFingerprintOptions(
|
|
2568
|
-
return
|
|
2610
|
+
getTlsFingerprintOptions() {
|
|
2611
|
+
return {};
|
|
2569
2612
|
},
|
|
2570
2613
|
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2571
|
-
|
|
2614
|
+
const normalizedHeaders = normalizeHeaders(headers);
|
|
2615
|
+
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2616
|
+
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2617
|
+
}
|
|
2618
|
+
return normalizedHeaders;
|
|
2572
2619
|
}
|
|
2573
2620
|
};
|
|
2574
2621
|
|
|
2622
|
+
// src/anti-cheat.js
|
|
2623
|
+
var antiCheatStrategies = {
|
|
2624
|
+
[Mode.Default]: DefaultAntiCheat,
|
|
2625
|
+
[Mode.CloakBrowser]: CloakBrowserAntiCheat
|
|
2626
|
+
};
|
|
2627
|
+
var AntiCheat = createDelegatedFacade("AntiCheat", antiCheatStrategies, [
|
|
2628
|
+
"getBaseConfig",
|
|
2629
|
+
"getFingerprintGeneratorOptions",
|
|
2630
|
+
"getLaunchArgs",
|
|
2631
|
+
"getTlsFingerprintOptions",
|
|
2632
|
+
"applyLocaleHeaders"
|
|
2633
|
+
]);
|
|
2634
|
+
|
|
2575
2635
|
// src/device-input.js
|
|
2576
2636
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2577
2637
|
var assertPage = (page, method) => {
|
|
@@ -2971,12 +3031,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
2971
3031
|
}
|
|
2972
3032
|
return resolved;
|
|
2973
3033
|
};
|
|
2974
|
-
var attachRuntimeState = (page,
|
|
3034
|
+
var attachRuntimeState = (page, state2) => {
|
|
2975
3035
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2976
3036
|
configurable: true,
|
|
2977
3037
|
enumerable: false,
|
|
2978
3038
|
writable: true,
|
|
2979
|
-
value:
|
|
3039
|
+
value: state2
|
|
2980
3040
|
});
|
|
2981
3041
|
};
|
|
2982
3042
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -4030,7 +4090,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4030
4090
|
return;
|
|
4031
4091
|
}
|
|
4032
4092
|
await page.evaluate(
|
|
4033
|
-
(
|
|
4093
|
+
(state2) => window.scrollTo(state2.x, state2.y),
|
|
4034
4094
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4035
4095
|
).catch(() => {
|
|
4036
4096
|
});
|
|
@@ -4276,7 +4336,7 @@ var MobileHumanize = {
|
|
|
4276
4336
|
if (scrollRect && beforeWindowState) {
|
|
4277
4337
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4278
4338
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4279
|
-
await page.evaluate((
|
|
4339
|
+
await page.evaluate((state2) => window.scrollTo(state2.x, state2.y), beforeWindowState);
|
|
4280
4340
|
logger6.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4281
4341
|
}
|
|
4282
4342
|
}
|
|
@@ -4643,475 +4703,272 @@ var DefaultHumanize = {
|
|
|
4643
4703
|
|
|
4644
4704
|
// src/internals/humanize/cloakbrowser.js
|
|
4645
4705
|
import delay4 from "delay";
|
|
4646
|
-
var logger7 = createInternalLogger("Humanize.CloakBrowser");
|
|
4647
|
-
var humanizedPages = /* @__PURE__ */ new WeakSet();
|
|
4648
|
-
var cachedCloakHumanModulePromise = null;
|
|
4649
|
-
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4650
|
-
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4651
4706
|
var resolveDeviceFromPage3 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4652
4707
|
var isMobilePage = (page) => resolveDeviceFromPage3(page) === Device.Mobile;
|
|
4653
|
-
var
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
}
|
|
4662
|
-
return cachedCloakHumanModulePromise;
|
|
4708
|
+
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4709
|
+
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4710
|
+
var resolveNativeTarget2 = (page, target) => typeof target === "string" ? page.locator(target).first() : target;
|
|
4711
|
+
var getViewportCenter = (page) => {
|
|
4712
|
+
const viewport = page?.viewportSize?.() || { width: 1365, height: 900 };
|
|
4713
|
+
return {
|
|
4714
|
+
x: Math.round(viewport.width / 2),
|
|
4715
|
+
y: Math.round(viewport.height / 2)
|
|
4716
|
+
};
|
|
4663
4717
|
};
|
|
4664
|
-
var
|
|
4665
|
-
|
|
4666
|
-
if (
|
|
4667
|
-
|
|
4668
|
-
}
|
|
4669
|
-
if (Number.isFinite(Number(options.pauseProbability))) {
|
|
4670
|
-
humanConfig.typing_pause_chance = Number(options.pauseProbability);
|
|
4718
|
+
var readViewportScroll = async (page) => await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY })).catch(() => ({ x: 0, y: 0 }));
|
|
4719
|
+
var getTargetBox = async (target) => {
|
|
4720
|
+
if (!target || typeof target.boundingBox !== "function") {
|
|
4721
|
+
return null;
|
|
4671
4722
|
}
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
|
|
4723
|
+
return await target.boundingBox().catch(() => null);
|
|
4724
|
+
};
|
|
4725
|
+
var clickOptionsFrom = (options = {}) => {
|
|
4726
|
+
const nextOptions = {
|
|
4727
|
+
force: true
|
|
4728
|
+
};
|
|
4729
|
+
if (options.timeout != null) {
|
|
4730
|
+
nextOptions.timeout = options.timeout;
|
|
4678
4731
|
}
|
|
4679
|
-
return
|
|
4732
|
+
return nextOptions;
|
|
4680
4733
|
};
|
|
4681
|
-
var
|
|
4682
|
-
const
|
|
4683
|
-
if (options
|
|
4684
|
-
|
|
4734
|
+
var typeOptionsFrom = (options = {}) => {
|
|
4735
|
+
const nextOptions = {};
|
|
4736
|
+
if (options.timeout != null) {
|
|
4737
|
+
nextOptions.timeout = options.timeout;
|
|
4685
4738
|
}
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
if (humanConfig) {
|
|
4689
|
-
actionOptions.human_config = humanConfig;
|
|
4739
|
+
if (options.baseDelay != null) {
|
|
4740
|
+
nextOptions.delay = Math.max(0, Number(options.baseDelay) || 0);
|
|
4690
4741
|
}
|
|
4691
|
-
return
|
|
4692
|
-
};
|
|
4693
|
-
var ensureDesktopHumanized = async (page) => {
|
|
4694
|
-
if (!page || typeof page !== "object") {
|
|
4695
|
-
throw new Error("Humanize requires a Playwright page");
|
|
4696
|
-
}
|
|
4697
|
-
const humanModule = await loadCloakHumanModule();
|
|
4698
|
-
if (page._original && page._humanCursor) {
|
|
4699
|
-
humanizedPages.add(page);
|
|
4700
|
-
return humanModule;
|
|
4701
|
-
}
|
|
4702
|
-
if (humanizedPages.has(page)) {
|
|
4703
|
-
return humanModule;
|
|
4704
|
-
}
|
|
4705
|
-
const config = page._humanCfg || humanModule.resolveConfig?.("default") || humanModule.resolveConfig?.();
|
|
4706
|
-
const cursor = page._humanCursor || { x: 0, y: 0, initialized: false };
|
|
4707
|
-
humanModule.patchPage(page, config, cursor);
|
|
4708
|
-
humanizedPages.add(page);
|
|
4709
|
-
return humanModule;
|
|
4710
|
-
};
|
|
4711
|
-
var patchHandle = async (page, handle) => {
|
|
4712
|
-
if (!handle || typeof handle !== "object") return handle;
|
|
4713
|
-
const humanModule = await ensureDesktopHumanized(page);
|
|
4714
|
-
humanModule.patchSingleElementHandle(
|
|
4715
|
-
handle,
|
|
4716
|
-
page,
|
|
4717
|
-
page._humanCfg,
|
|
4718
|
-
page._humanCursor,
|
|
4719
|
-
page._humanRaw,
|
|
4720
|
-
page._humanRawKb,
|
|
4721
|
-
page._humanOriginals,
|
|
4722
|
-
page._stealth
|
|
4723
|
-
);
|
|
4724
|
-
return handle;
|
|
4742
|
+
return nextOptions;
|
|
4725
4743
|
};
|
|
4726
|
-
var
|
|
4727
|
-
|
|
4728
|
-
|
|
4744
|
+
var pressOptionsFrom = (options = {}) => {
|
|
4745
|
+
const nextOptions = {};
|
|
4746
|
+
if (options.timeout != null) {
|
|
4747
|
+
nextOptions.timeout = options.timeout;
|
|
4729
4748
|
}
|
|
4730
|
-
if (
|
|
4731
|
-
|
|
4732
|
-
if (!handle) {
|
|
4733
|
-
if (throwOnMissing) {
|
|
4734
|
-
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${String(target)}`);
|
|
4735
|
-
}
|
|
4736
|
-
return { target: null, dispose: null };
|
|
4737
|
-
}
|
|
4738
|
-
return { target: handle, dispose: null };
|
|
4749
|
+
if (options.holdDelay != null) {
|
|
4750
|
+
nextOptions.delay = Math.max(0, Number(options.holdDelay) || 0);
|
|
4739
4751
|
}
|
|
4740
|
-
|
|
4741
|
-
const handle = await target.elementHandle();
|
|
4742
|
-
if (!handle) {
|
|
4743
|
-
if (throwOnMissing) {
|
|
4744
|
-
throw new Error("\u627E\u4E0D\u5230 locator \u5BF9\u5E94\u7684\u5143\u7D20");
|
|
4745
|
-
}
|
|
4746
|
-
return { target: null, dispose: null };
|
|
4747
|
-
}
|
|
4748
|
-
await patchHandle(page, handle);
|
|
4749
|
-
return {
|
|
4750
|
-
target: handle,
|
|
4751
|
-
dispose: async () => {
|
|
4752
|
-
await handle.dispose().catch(() => {
|
|
4753
|
-
});
|
|
4754
|
-
}
|
|
4755
|
-
};
|
|
4756
|
-
}
|
|
4757
|
-
await patchHandle(page, target);
|
|
4758
|
-
return { target, dispose: null };
|
|
4752
|
+
return nextOptions;
|
|
4759
4753
|
};
|
|
4760
|
-
var
|
|
4754
|
+
var waitDesktopJitter = async (baseMs, jitterPercent = 0.3) => {
|
|
4761
4755
|
await delay4(jitterMs(baseMs, jitterPercent));
|
|
4762
4756
|
};
|
|
4763
|
-
var
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
await page.mouse.click(cursor.x || 0, cursor.y || 0);
|
|
4773
|
-
return true;
|
|
4774
|
-
}
|
|
4775
|
-
if (isPoint2(target)) {
|
|
4776
|
-
return humanMoveToPoint(page, target).then(async () => {
|
|
4777
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4778
|
-
return true;
|
|
4779
|
-
});
|
|
4780
|
-
}
|
|
4781
|
-
const throwOnMissing = options.throwOnMissing !== false;
|
|
4782
|
-
if (typeof target === "string") {
|
|
4783
|
-
if (!throwOnMissing) {
|
|
4784
|
-
const existingHandle = await page.$(target);
|
|
4785
|
-
if (!existingHandle) {
|
|
4786
|
-
return false;
|
|
4787
|
-
}
|
|
4788
|
-
await existingHandle.click(buildActionOptions(options));
|
|
4789
|
-
return true;
|
|
4790
|
-
}
|
|
4791
|
-
await page.click(target, buildActionOptions(options));
|
|
4792
|
-
return true;
|
|
4793
|
-
}
|
|
4794
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing });
|
|
4795
|
-
try {
|
|
4796
|
-
if (!resolvedTarget) {
|
|
4757
|
+
var DesktopCloakHumanize = {
|
|
4758
|
+
jitterMs(base, jitterPercent = 0.3) {
|
|
4759
|
+
return jitterMs(base, jitterPercent);
|
|
4760
|
+
},
|
|
4761
|
+
async initializeCursor(page) {
|
|
4762
|
+
return Boolean(page);
|
|
4763
|
+
},
|
|
4764
|
+
async humanMove(page, target) {
|
|
4765
|
+
if (target == null) {
|
|
4797
4766
|
return false;
|
|
4798
4767
|
}
|
|
4799
|
-
if (
|
|
4800
|
-
await
|
|
4768
|
+
if (isPoint2(target)) {
|
|
4769
|
+
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4801
4770
|
return true;
|
|
4802
4771
|
}
|
|
4803
|
-
const
|
|
4772
|
+
const resolvedTarget = resolveNativeTarget2(page, target);
|
|
4773
|
+
if (typeof resolvedTarget?.hover === "function") {
|
|
4774
|
+
await resolvedTarget.hover(clickOptionsFrom());
|
|
4775
|
+
return true;
|
|
4776
|
+
}
|
|
4777
|
+
const box = await getTargetBox(resolvedTarget);
|
|
4804
4778
|
if (!box) {
|
|
4805
|
-
if (throwOnMissing) {
|
|
4806
|
-
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4807
|
-
}
|
|
4808
4779
|
return false;
|
|
4809
4780
|
}
|
|
4810
|
-
await page.mouse.
|
|
4781
|
+
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
4811
4782
|
return true;
|
|
4812
|
-
} finally {
|
|
4813
|
-
if (typeof dispose === "function") {
|
|
4814
|
-
await dispose();
|
|
4815
|
-
}
|
|
4816
|
-
}
|
|
4817
|
-
};
|
|
4818
|
-
var CloakBrowserHumanize = {
|
|
4819
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4820
|
-
return jitterMs(base, jitterPercent);
|
|
4821
4783
|
},
|
|
4822
|
-
async
|
|
4823
|
-
|
|
4824
|
-
|
|
4784
|
+
async humanScroll(page, target) {
|
|
4785
|
+
const resolvedTarget = resolveNativeTarget2(page, target);
|
|
4786
|
+
if (!resolvedTarget) {
|
|
4787
|
+
return { element: null, didScroll: false, restore: null };
|
|
4825
4788
|
}
|
|
4826
|
-
await
|
|
4827
|
-
|
|
4789
|
+
const before = await readViewportScroll(page);
|
|
4790
|
+
await resolvedTarget.scrollIntoViewIfNeeded?.();
|
|
4791
|
+
const after = await readViewportScroll(page);
|
|
4792
|
+
return {
|
|
4793
|
+
element: resolvedTarget,
|
|
4794
|
+
didScroll: before.x !== after.x || before.y !== after.y,
|
|
4795
|
+
restore: null
|
|
4796
|
+
};
|
|
4828
4797
|
},
|
|
4829
|
-
async
|
|
4830
|
-
if (
|
|
4831
|
-
|
|
4798
|
+
async humanClick(page, target, options = {}) {
|
|
4799
|
+
if (target == null) {
|
|
4800
|
+
const center = getViewportCenter(page);
|
|
4801
|
+
await page.mouse.click(center.x, center.y);
|
|
4802
|
+
return true;
|
|
4832
4803
|
}
|
|
4833
|
-
await ensureDesktopHumanized(page);
|
|
4834
4804
|
if (isPoint2(target)) {
|
|
4835
|
-
|
|
4836
|
-
}
|
|
4837
|
-
const { target: resolvedTarget, dispose } = await resolvePatchedTarget(page, target, { throwOnMissing: false });
|
|
4838
|
-
try {
|
|
4839
|
-
if (!resolvedTarget) {
|
|
4840
|
-
return false;
|
|
4841
|
-
}
|
|
4842
|
-
if (typeof resolvedTarget.hover === "function") {
|
|
4843
|
-
await resolvedTarget.hover({ force: true });
|
|
4844
|
-
return true;
|
|
4845
|
-
}
|
|
4846
|
-
const box = await resolvedTarget.boundingBox?.();
|
|
4847
|
-
if (!box) {
|
|
4848
|
-
return false;
|
|
4849
|
-
}
|
|
4850
|
-
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
4805
|
+
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4851
4806
|
return true;
|
|
4852
|
-
} finally {
|
|
4853
|
-
if (typeof dispose === "function") {
|
|
4854
|
-
await dispose();
|
|
4855
|
-
}
|
|
4856
4807
|
}
|
|
4857
|
-
},
|
|
4858
|
-
async humanScroll(page, target, options = {}) {
|
|
4859
|
-
if (isMobilePage(page)) {
|
|
4860
|
-
return await MobileHumanize.humanScroll(page, target, options);
|
|
4861
|
-
}
|
|
4862
|
-
const humanModule = await ensureDesktopHumanized(page);
|
|
4863
4808
|
if (typeof target === "string") {
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
const result = await humanModule.scrollToElement(
|
|
4867
|
-
page,
|
|
4868
|
-
page._humanRaw,
|
|
4869
|
-
target,
|
|
4870
|
-
x,
|
|
4871
|
-
y,
|
|
4872
|
-
page._humanCfg,
|
|
4873
|
-
options.timeout
|
|
4874
|
-
);
|
|
4875
|
-
if (page._humanCursor) {
|
|
4876
|
-
page._humanCursor.x = result.cursorX;
|
|
4877
|
-
page._humanCursor.y = result.cursorY;
|
|
4878
|
-
}
|
|
4879
|
-
return {
|
|
4880
|
-
element: await page.$(target),
|
|
4881
|
-
didScroll: Boolean(result.didScroll),
|
|
4882
|
-
restore: null
|
|
4883
|
-
};
|
|
4884
|
-
} catch (error) {
|
|
4885
|
-
logger7.warn(`humanScroll: cloakbrowser \u6EDA\u52A8\u5931\u8D25\uFF0C\u8DF3\u8FC7 (${error?.message || error})`);
|
|
4886
|
-
return { element: null, didScroll: false, restore: null };
|
|
4887
|
-
}
|
|
4809
|
+
await page.click(target, clickOptionsFrom(options));
|
|
4810
|
+
return true;
|
|
4888
4811
|
}
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
return { element: null, didScroll: false, restore: null };
|
|
4893
|
-
}
|
|
4894
|
-
const before = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4895
|
-
await resolvedTarget.scrollIntoViewIfNeeded?.();
|
|
4896
|
-
const after = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4897
|
-
return {
|
|
4898
|
-
element: resolvedTarget,
|
|
4899
|
-
didScroll: before.x !== after.x || before.y !== after.y,
|
|
4900
|
-
restore: null
|
|
4901
|
-
};
|
|
4902
|
-
} finally {
|
|
4903
|
-
if (typeof dispose === "function") {
|
|
4904
|
-
await dispose();
|
|
4905
|
-
}
|
|
4812
|
+
if (typeof target?.click === "function") {
|
|
4813
|
+
await target.click(clickOptionsFrom(options));
|
|
4814
|
+
return true;
|
|
4906
4815
|
}
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
return await MobileHumanize.humanClick(page, target, options);
|
|
4816
|
+
const box = await getTargetBox(target);
|
|
4817
|
+
if (!box) {
|
|
4818
|
+
return false;
|
|
4911
4819
|
}
|
|
4912
|
-
|
|
4820
|
+
await page.mouse.click(box.x + box.width / 2, box.y + box.height / 2);
|
|
4821
|
+
return true;
|
|
4913
4822
|
},
|
|
4914
|
-
async randomSleep(
|
|
4915
|
-
|
|
4916
|
-
if (isMobilePage(pageOrBaseMs)) {
|
|
4917
|
-
return await MobileHumanize.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4918
|
-
}
|
|
4919
|
-
await jitterSleep(maybeBaseMs, maybeJitterPercent ?? 0.3);
|
|
4920
|
-
return;
|
|
4921
|
-
}
|
|
4922
|
-
await jitterSleep(pageOrBaseMs, maybeBaseMs ?? 0.3);
|
|
4823
|
+
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4824
|
+
await waitDesktopJitter(baseMs, jitterPercent);
|
|
4923
4825
|
},
|
|
4924
4826
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4925
|
-
if (isMobilePage(page)) {
|
|
4926
|
-
return await MobileHumanize.simulateGaze(page, baseDurationMs);
|
|
4927
|
-
}
|
|
4928
|
-
await ensureDesktopHumanized(page);
|
|
4929
4827
|
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4930
|
-
const
|
|
4931
|
-
const
|
|
4932
|
-
while (Date.now() -
|
|
4828
|
+
const startedAt = Date.now();
|
|
4829
|
+
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4830
|
+
while (Date.now() - startedAt < durationMs) {
|
|
4933
4831
|
await page.mouse.move(
|
|
4934
|
-
100 + Math.random() * Math.max(120,
|
|
4935
|
-
100 + Math.random() * Math.max(120,
|
|
4832
|
+
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4833
|
+
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4936
4834
|
);
|
|
4937
|
-
await
|
|
4835
|
+
await waitDesktopJitter(600, 0.5);
|
|
4938
4836
|
}
|
|
4939
4837
|
},
|
|
4940
4838
|
async humanType(page, selector, text, options = {}) {
|
|
4941
|
-
if (isMobilePage(page)) {
|
|
4942
|
-
return await MobileHumanize.humanType(page, selector, text, options);
|
|
4943
|
-
}
|
|
4944
|
-
await ensureDesktopHumanized(page);
|
|
4945
|
-
const actionOptions = buildActionOptions(options);
|
|
4946
4839
|
if (typeof selector === "string") {
|
|
4947
|
-
await page.type(selector, text,
|
|
4840
|
+
await page.type(selector, text, typeOptionsFrom(options));
|
|
4948
4841
|
return;
|
|
4949
4842
|
}
|
|
4950
|
-
|
|
4951
|
-
try {
|
|
4952
|
-
if (!resolvedTarget || typeof resolvedTarget.type !== "function") {
|
|
4953
|
-
throw new Error("\u76EE\u6807\u5143\u7D20\u4E0D\u652F\u6301 type()");
|
|
4954
|
-
}
|
|
4955
|
-
await resolvedTarget.type(text, actionOptions);
|
|
4956
|
-
} finally {
|
|
4957
|
-
if (typeof dispose === "function") {
|
|
4958
|
-
await dispose();
|
|
4959
|
-
}
|
|
4960
|
-
}
|
|
4843
|
+
await selector.type(text, typeOptionsFrom(options));
|
|
4961
4844
|
},
|
|
4962
4845
|
async humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4963
|
-
if (isMobilePage(page)) {
|
|
4964
|
-
return await MobileHumanize.humanPress(page, targetOrKey, maybeKey, options);
|
|
4965
|
-
}
|
|
4966
|
-
await ensureDesktopHumanized(page);
|
|
4967
4846
|
const hasTarget = typeof maybeKey === "string";
|
|
4968
4847
|
const key = hasTarget ? maybeKey : targetOrKey;
|
|
4969
4848
|
const pressOptions = hasTarget ? options : maybeKey || options;
|
|
4970
4849
|
if (!hasTarget) {
|
|
4971
|
-
await
|
|
4972
|
-
await page.keyboard.press(key, {
|
|
4973
|
-
...pressOptions.keyboardOptions || {},
|
|
4974
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
4975
|
-
});
|
|
4850
|
+
await page.keyboard.press(key, pressOptionsFrom(pressOptions));
|
|
4976
4851
|
return true;
|
|
4977
4852
|
}
|
|
4978
4853
|
if (typeof targetOrKey === "string") {
|
|
4979
|
-
await page.press(targetOrKey, key,
|
|
4854
|
+
await page.press(targetOrKey, key, pressOptionsFrom(pressOptions));
|
|
4980
4855
|
return true;
|
|
4981
4856
|
}
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
});
|
|
4985
|
-
try {
|
|
4986
|
-
if (!resolvedTarget) {
|
|
4987
|
-
return false;
|
|
4988
|
-
}
|
|
4989
|
-
if (typeof resolvedTarget.press === "function") {
|
|
4990
|
-
await resolvedTarget.press(key, buildActionOptions(pressOptions));
|
|
4991
|
-
return true;
|
|
4992
|
-
}
|
|
4993
|
-
await doDesktopHumanClick(page, targetOrKey, {
|
|
4994
|
-
...pressOptions,
|
|
4995
|
-
reactionDelay: pressOptions.focusDelay ?? 180
|
|
4996
|
-
});
|
|
4997
|
-
await jitterSleep(pressOptions.reactionDelay ?? 180, 0.45);
|
|
4998
|
-
await page.keyboard.press(key, {
|
|
4999
|
-
...pressOptions.keyboardOptions || {},
|
|
5000
|
-
delay: jitterMs(pressOptions.holdDelay ?? 45, 0.5)
|
|
5001
|
-
});
|
|
4857
|
+
if (typeof targetOrKey?.press === "function") {
|
|
4858
|
+
await targetOrKey.press(key, pressOptionsFrom(pressOptions));
|
|
5002
4859
|
return true;
|
|
5003
|
-
} finally {
|
|
5004
|
-
if (typeof dispose === "function") {
|
|
5005
|
-
await dispose();
|
|
5006
|
-
}
|
|
5007
4860
|
}
|
|
4861
|
+
await page.keyboard.press(key, pressOptionsFrom(pressOptions));
|
|
4862
|
+
return true;
|
|
5008
4863
|
},
|
|
5009
4864
|
async humanClear(page, selector) {
|
|
5010
|
-
if (
|
|
5011
|
-
|
|
4865
|
+
if (typeof selector === "string") {
|
|
4866
|
+
if (typeof page.clear === "function") {
|
|
4867
|
+
await page.clear(selector, clickOptionsFrom());
|
|
4868
|
+
return;
|
|
4869
|
+
}
|
|
4870
|
+
await page.fill(selector, "", clickOptionsFrom());
|
|
4871
|
+
return;
|
|
5012
4872
|
}
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
4873
|
+
if (typeof selector?.clear === "function") {
|
|
4874
|
+
await selector.clear(clickOptionsFrom());
|
|
4875
|
+
return;
|
|
4876
|
+
}
|
|
4877
|
+
if (typeof selector?.fill === "function") {
|
|
4878
|
+
await selector.fill("", clickOptionsFrom());
|
|
5016
4879
|
return;
|
|
5017
4880
|
}
|
|
5018
|
-
await page.fill(selector, "", { force: true });
|
|
5019
4881
|
},
|
|
5020
4882
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
5021
|
-
if (isMobilePage(page)) {
|
|
5022
|
-
return await MobileHumanize.warmUpBrowsing(page, baseDuration);
|
|
5023
|
-
}
|
|
5024
|
-
await ensureDesktopHumanized(page);
|
|
5025
4883
|
const durationMs = jitterMs(baseDuration, 0.4);
|
|
5026
|
-
const
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
await page.mouse.move(
|
|
5032
|
-
100 + Math.random() * Math.max(120, viewportSize.width - 200),
|
|
5033
|
-
100 + Math.random() * Math.max(120, viewportSize.height - 200)
|
|
5034
|
-
);
|
|
5035
|
-
await jitterSleep(350, 0.4);
|
|
5036
|
-
continue;
|
|
5037
|
-
}
|
|
5038
|
-
if (action < 0.7) {
|
|
5039
|
-
await page.mouse.wheel(0, (Math.random() - 0.5) * 220);
|
|
5040
|
-
await jitterSleep(500, 0.4);
|
|
5041
|
-
continue;
|
|
5042
|
-
}
|
|
5043
|
-
await jitterSleep(800, 0.5);
|
|
4884
|
+
const startedAt = Date.now();
|
|
4885
|
+
while (Date.now() - startedAt < durationMs) {
|
|
4886
|
+
await this.simulateGaze(page, 240);
|
|
4887
|
+
await this.naturalScroll(page, Math.random() > 0.4 ? "down" : "up", 160, 3);
|
|
4888
|
+
await waitDesktopJitter(250, 0.35);
|
|
5044
4889
|
}
|
|
5045
4890
|
},
|
|
5046
4891
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
}
|
|
5050
|
-
await ensureDesktopHumanized(page);
|
|
5051
|
-
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
5052
|
-
const actualDistance = jitterMs(distance, 0.15);
|
|
4892
|
+
const steps = Math.max(1, Number(baseSteps) || 1);
|
|
4893
|
+
const stepDistance = (Number(distance) || 0) / steps;
|
|
5053
4894
|
const sign = direction === "down" ? 1 : -1;
|
|
5054
|
-
const stepDistance = actualDistance / steps;
|
|
5055
4895
|
for (let index = 0; index < steps; index += 1) {
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
await page.mouse.wheel(0, stepDistance * factor * sign * jitter);
|
|
5059
|
-
await jitterSleep(60 + index * 25, 0.3);
|
|
4896
|
+
await page.mouse.wheel(0, stepDistance * sign);
|
|
4897
|
+
await waitDesktopJitter(60 + index * 20, 0.3);
|
|
5060
4898
|
}
|
|
5061
4899
|
}
|
|
5062
4900
|
};
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
const delegate = resolveHumanizeDelegate();
|
|
5068
|
-
if (typeof delegate?.[method] !== "function") {
|
|
5069
|
-
throw new Error(`Humanize.${method} is not available in ${getToolkitMode()} mode`);
|
|
5070
|
-
}
|
|
5071
|
-
return delegate[method](...args);
|
|
4901
|
+
var resolveDelegate2 = (page) => isMobilePage(page) ? MobileHumanize : DesktopCloakHumanize;
|
|
4902
|
+
var callDelegate2 = (method, page, args) => {
|
|
4903
|
+
const delegate = resolveDelegate2(page);
|
|
4904
|
+
return delegate[method](page, ...args);
|
|
5072
4905
|
};
|
|
5073
|
-
var
|
|
4906
|
+
var CloakBrowserHumanize = {
|
|
5074
4907
|
jitterMs(base, jitterPercent = 0.3) {
|
|
5075
|
-
return
|
|
4908
|
+
return jitterMs(base, jitterPercent);
|
|
5076
4909
|
},
|
|
5077
4910
|
initializeCursor(page) {
|
|
5078
|
-
return
|
|
4911
|
+
return callDelegate2("initializeCursor", page, []);
|
|
5079
4912
|
},
|
|
5080
4913
|
humanMove(page, target) {
|
|
5081
|
-
return
|
|
4914
|
+
return callDelegate2("humanMove", page, [target]);
|
|
5082
4915
|
},
|
|
5083
4916
|
humanScroll(page, target, options = {}) {
|
|
5084
|
-
return
|
|
4917
|
+
return callDelegate2("humanScroll", page, [target, options]);
|
|
5085
4918
|
},
|
|
5086
4919
|
humanClick(page, target, options = {}) {
|
|
5087
|
-
return
|
|
4920
|
+
return callDelegate2("humanClick", page, [target, options]);
|
|
5088
4921
|
},
|
|
5089
4922
|
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
5090
|
-
|
|
4923
|
+
if (isPageLike2(pageOrBaseMs)) {
|
|
4924
|
+
const delegate = resolveDelegate2(pageOrBaseMs);
|
|
4925
|
+
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4926
|
+
}
|
|
4927
|
+
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
5091
4928
|
},
|
|
5092
4929
|
simulateGaze(page, baseDurationMs = 2500) {
|
|
5093
|
-
return
|
|
4930
|
+
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
5094
4931
|
},
|
|
5095
4932
|
humanType(page, selector, text, options = {}) {
|
|
5096
|
-
return
|
|
4933
|
+
return callDelegate2("humanType", page, [selector, text, options]);
|
|
5097
4934
|
},
|
|
5098
4935
|
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
5099
4936
|
if (typeof maybeKey === "string") {
|
|
5100
|
-
return
|
|
4937
|
+
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
5101
4938
|
}
|
|
5102
|
-
return
|
|
4939
|
+
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
5103
4940
|
},
|
|
5104
4941
|
humanClear(page, selector) {
|
|
5105
|
-
return
|
|
4942
|
+
return callDelegate2("humanClear", page, [selector]);
|
|
5106
4943
|
},
|
|
5107
4944
|
warmUpBrowsing(page, baseDuration = 3500) {
|
|
5108
|
-
return
|
|
4945
|
+
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
5109
4946
|
},
|
|
5110
4947
|
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
5111
|
-
return
|
|
4948
|
+
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
5112
4949
|
}
|
|
5113
4950
|
};
|
|
5114
4951
|
|
|
4952
|
+
// src/humanize.js
|
|
4953
|
+
var humanizeStrategies = {
|
|
4954
|
+
[Mode.Default]: DefaultHumanize,
|
|
4955
|
+
[Mode.CloakBrowser]: CloakBrowserHumanize
|
|
4956
|
+
};
|
|
4957
|
+
var Humanize2 = createDelegatedFacade("Humanize", humanizeStrategies, [
|
|
4958
|
+
"jitterMs",
|
|
4959
|
+
"initializeCursor",
|
|
4960
|
+
"humanMove",
|
|
4961
|
+
"humanScroll",
|
|
4962
|
+
"humanClick",
|
|
4963
|
+
"randomSleep",
|
|
4964
|
+
"simulateGaze",
|
|
4965
|
+
"humanType",
|
|
4966
|
+
"humanPress",
|
|
4967
|
+
"humanClear",
|
|
4968
|
+
"warmUpBrowsing",
|
|
4969
|
+
"naturalScroll"
|
|
4970
|
+
]);
|
|
4971
|
+
|
|
5115
4972
|
// src/internals/launch/default.js
|
|
5116
4973
|
import { execFileSync } from "node:child_process";
|
|
5117
4974
|
import { FingerprintGenerator } from "fingerprint-generator";
|
|
@@ -5198,7 +5055,7 @@ var ByPass = {
|
|
|
5198
5055
|
};
|
|
5199
5056
|
|
|
5200
5057
|
// src/internals/launch/default.js
|
|
5201
|
-
var
|
|
5058
|
+
var logger7 = createInternalLogger("Launch");
|
|
5202
5059
|
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
5203
5060
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
5204
5061
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
@@ -5250,7 +5107,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5250
5107
|
});
|
|
5251
5108
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5252
5109
|
} catch (error) {
|
|
5253
|
-
|
|
5110
|
+
logger7.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5254
5111
|
}
|
|
5255
5112
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5256
5113
|
return detectedVersion;
|
|
@@ -5287,7 +5144,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5287
5144
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5288
5145
|
throw error;
|
|
5289
5146
|
}
|
|
5290
|
-
|
|
5147
|
+
logger7.warn(
|
|
5291
5148
|
`\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}`
|
|
5292
5149
|
);
|
|
5293
5150
|
}
|
|
@@ -5332,7 +5189,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5332
5189
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5333
5190
|
};
|
|
5334
5191
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5335
|
-
|
|
5192
|
+
logger7.info(
|
|
5336
5193
|
`\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}`
|
|
5337
5194
|
);
|
|
5338
5195
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5461,18 +5318,18 @@ var DefaultLaunch = {
|
|
|
5461
5318
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5462
5319
|
} catch {
|
|
5463
5320
|
}
|
|
5464
|
-
|
|
5321
|
+
logger7.info(
|
|
5465
5322
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5466
5323
|
);
|
|
5467
|
-
|
|
5324
|
+
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`);
|
|
5468
5325
|
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5469
|
-
|
|
5470
|
-
|
|
5326
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5327
|
+
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`);
|
|
5471
5328
|
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5472
|
-
|
|
5473
|
-
|
|
5329
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5330
|
+
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`);
|
|
5474
5331
|
} else if (enableByPassLogger) {
|
|
5475
|
-
|
|
5332
|
+
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`);
|
|
5476
5333
|
}
|
|
5477
5334
|
const onPageCreated = (page) => {
|
|
5478
5335
|
const recommendedGotoOptions = {
|
|
@@ -5494,7 +5351,7 @@ var DefaultLaunch = {
|
|
|
5494
5351
|
}
|
|
5495
5352
|
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5496
5353
|
if (!matched || !matched.rule) return;
|
|
5497
|
-
|
|
5354
|
+
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}`);
|
|
5498
5355
|
};
|
|
5499
5356
|
page.on("request", requestHandler);
|
|
5500
5357
|
return recommendedGotoOptions;
|
|
@@ -5551,7 +5408,7 @@ var DefaultLaunch = {
|
|
|
5551
5408
|
// src/internals/launch/cloakbrowser.js
|
|
5552
5409
|
import { execFile } from "node:child_process";
|
|
5553
5410
|
import { promisify } from "node:util";
|
|
5554
|
-
var
|
|
5411
|
+
var logger8 = createInternalLogger("CloakBrowser");
|
|
5555
5412
|
var execFileAsync = promisify(execFile);
|
|
5556
5413
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5557
5414
|
maxConcurrency: 1,
|
|
@@ -5687,7 +5544,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5687
5544
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5688
5545
|
return;
|
|
5689
5546
|
}
|
|
5690
|
-
|
|
5547
|
+
logger8.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5691
5548
|
});
|
|
5692
5549
|
};
|
|
5693
5550
|
var CloakBrowserLaunch = {
|
|
@@ -5701,8 +5558,21 @@ var CloakBrowserLaunch = {
|
|
|
5701
5558
|
return createStableGotoHook(recommendedGotoOptions);
|
|
5702
5559
|
},
|
|
5703
5560
|
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5704
|
-
const
|
|
5705
|
-
return crawlerOptions
|
|
5561
|
+
const runtime2 = await CloakBrowserLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5562
|
+
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5563
|
+
cleanup: {
|
|
5564
|
+
enumerable: false,
|
|
5565
|
+
value: runtime2.cleanup
|
|
5566
|
+
},
|
|
5567
|
+
closeActiveBrowsers: {
|
|
5568
|
+
enumerable: false,
|
|
5569
|
+
value: runtime2.closeActiveBrowsers
|
|
5570
|
+
},
|
|
5571
|
+
forceTerminateActiveProcesses: {
|
|
5572
|
+
enumerable: false,
|
|
5573
|
+
value: runtime2.forceTerminateActiveProcesses
|
|
5574
|
+
}
|
|
5575
|
+
});
|
|
5706
5576
|
},
|
|
5707
5577
|
async buildLaunchOptions(options = {}) {
|
|
5708
5578
|
return await buildCloakLaunchOptions(options);
|
|
@@ -5783,39 +5653,18 @@ var CloakBrowserLaunch = {
|
|
|
5783
5653
|
};
|
|
5784
5654
|
|
|
5785
5655
|
// src/launch.js
|
|
5786
|
-
var
|
|
5787
|
-
|
|
5788
|
-
|
|
5789
|
-
if (typeof delegate?.[method] !== "function") {
|
|
5790
|
-
throw new Error(`Launch.${method} is not available in ${getToolkitMode()} mode`);
|
|
5791
|
-
}
|
|
5792
|
-
return delegate[method](...args);
|
|
5793
|
-
};
|
|
5794
|
-
var Launch = {
|
|
5795
|
-
getPlaywrightCrawlerOptions(options = {}) {
|
|
5796
|
-
return callLaunch("getPlaywrightCrawlerOptions", options);
|
|
5797
|
-
},
|
|
5798
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5799
|
-
return callLaunch("resolveProxyConfiguration", proxyConfiguration);
|
|
5800
|
-
},
|
|
5801
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5802
|
-
return callLaunch("extractFingerprintArg", launchOptions);
|
|
5803
|
-
},
|
|
5804
|
-
createStableGotoHook(recommendedGotoOptions = {}) {
|
|
5805
|
-
return callLaunch("createStableGotoHook", recommendedGotoOptions);
|
|
5806
|
-
},
|
|
5807
|
-
buildLaunchOptions(options = {}) {
|
|
5808
|
-
return callLaunch("buildLaunchOptions", options);
|
|
5809
|
-
},
|
|
5810
|
-
createPlaywrightCrawlerRuntime(options = {}) {
|
|
5811
|
-
return callLaunch("createPlaywrightCrawlerRuntime", options);
|
|
5812
|
-
}
|
|
5656
|
+
var launchStrategies = {
|
|
5657
|
+
[Mode.Default]: DefaultLaunch,
|
|
5658
|
+
[Mode.CloakBrowser]: CloakBrowserLaunch
|
|
5813
5659
|
};
|
|
5660
|
+
var Launch = createDelegatedFacade("Launch", launchStrategies, [
|
|
5661
|
+
"getPlaywrightCrawlerOptions"
|
|
5662
|
+
]);
|
|
5814
5663
|
|
|
5815
5664
|
// src/live-view.js
|
|
5816
5665
|
import express from "express";
|
|
5817
5666
|
import { Actor } from "apify";
|
|
5818
|
-
var
|
|
5667
|
+
var logger9 = createInternalLogger("LiveView");
|
|
5819
5668
|
async function startLiveViewServer(liveViewKey) {
|
|
5820
5669
|
const app = express();
|
|
5821
5670
|
app.get("/", async (req, res) => {
|
|
@@ -5840,13 +5689,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5840
5689
|
</html>
|
|
5841
5690
|
`);
|
|
5842
5691
|
} catch (error) {
|
|
5843
|
-
|
|
5692
|
+
logger9.fail("Live View Server", error);
|
|
5844
5693
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5845
5694
|
}
|
|
5846
5695
|
});
|
|
5847
5696
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5848
5697
|
app.listen(port, () => {
|
|
5849
|
-
|
|
5698
|
+
logger9.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5850
5699
|
});
|
|
5851
5700
|
}
|
|
5852
5701
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5854,10 +5703,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5854
5703
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5855
5704
|
await Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5856
5705
|
if (logMessage) {
|
|
5857
|
-
|
|
5706
|
+
logger9.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5858
5707
|
}
|
|
5859
5708
|
} catch (e) {
|
|
5860
|
-
|
|
5709
|
+
logger9.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5861
5710
|
}
|
|
5862
5711
|
}
|
|
5863
5712
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5966,7 +5815,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5966
5815
|
};
|
|
5967
5816
|
|
|
5968
5817
|
// src/internals/captcha/bytedance.js
|
|
5969
|
-
var
|
|
5818
|
+
var logger10 = createInternalLogger("Captcha");
|
|
5970
5819
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5971
5820
|
apiType: "31234",
|
|
5972
5821
|
maxRetries: 3,
|
|
@@ -6098,7 +5947,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
6098
5947
|
}
|
|
6099
5948
|
await writeFile(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
6100
5949
|
}
|
|
6101
|
-
|
|
5950
|
+
logger10.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
6102
5951
|
};
|
|
6103
5952
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
6104
5953
|
if (!options.debugArtifacts) {
|
|
@@ -6135,14 +5984,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6135
5984
|
if (!isContainerVisible) {
|
|
6136
5985
|
return null;
|
|
6137
5986
|
}
|
|
6138
|
-
|
|
5987
|
+
logger10.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
6139
5988
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
6140
5989
|
let isIframeVisible = await waitForVisible(
|
|
6141
5990
|
iframeLocator,
|
|
6142
5991
|
options.iframeVisibleTimeoutMs
|
|
6143
5992
|
);
|
|
6144
5993
|
if (!isIframeVisible) {
|
|
6145
|
-
|
|
5994
|
+
logger10.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
6146
5995
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
6147
5996
|
isIframeVisible = await waitForVisible(
|
|
6148
5997
|
iframeLocator,
|
|
@@ -6152,7 +6001,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
6152
6001
|
if (!isIframeVisible) {
|
|
6153
6002
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
6154
6003
|
}
|
|
6155
|
-
|
|
6004
|
+
logger10.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
6156
6005
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
6157
6006
|
if (!frame) {
|
|
6158
6007
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -6268,11 +6117,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
6268
6117
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
6269
6118
|
...options,
|
|
6270
6119
|
page,
|
|
6271
|
-
logger:
|
|
6120
|
+
logger: logger10,
|
|
6272
6121
|
forceMouse: true
|
|
6273
6122
|
}).catch(() => false);
|
|
6274
6123
|
if (!clicked) {
|
|
6275
|
-
|
|
6124
|
+
logger10.warn("Refresh button not found.");
|
|
6276
6125
|
return false;
|
|
6277
6126
|
}
|
|
6278
6127
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6303,24 +6152,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6303
6152
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6304
6153
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6305
6154
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6306
|
-
|
|
6155
|
+
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");
|
|
6307
6156
|
hasLoggedGuideMask = true;
|
|
6308
6157
|
}
|
|
6309
6158
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6310
|
-
|
|
6159
|
+
logger10.info(
|
|
6311
6160
|
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"
|
|
6312
6161
|
);
|
|
6313
6162
|
return;
|
|
6314
6163
|
}
|
|
6315
6164
|
if (hasErrorTextVisible) {
|
|
6316
|
-
|
|
6165
|
+
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");
|
|
6317
6166
|
await refreshCaptcha(page, frame, options);
|
|
6318
6167
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6319
6168
|
hasSeenLoading = false;
|
|
6320
6169
|
continue;
|
|
6321
6170
|
}
|
|
6322
6171
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6323
|
-
|
|
6172
|
+
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`);
|
|
6324
6173
|
await refreshCaptcha(page, frame, options);
|
|
6325
6174
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6326
6175
|
hasSeenLoading = false;
|
|
@@ -6368,7 +6217,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6368
6217
|
accepted
|
|
6369
6218
|
};
|
|
6370
6219
|
dragAttempts.push(attemptInfo);
|
|
6371
|
-
|
|
6220
|
+
logger10.info(
|
|
6372
6221
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6373
6222
|
);
|
|
6374
6223
|
if (accepted) {
|
|
@@ -6386,7 +6235,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6386
6235
|
dragAttempts,
|
|
6387
6236
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6388
6237
|
}).catch((error) => {
|
|
6389
|
-
|
|
6238
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6390
6239
|
});
|
|
6391
6240
|
return {
|
|
6392
6241
|
accepted: false,
|
|
@@ -6403,16 +6252,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6403
6252
|
...options
|
|
6404
6253
|
};
|
|
6405
6254
|
if (!config.token) {
|
|
6406
|
-
|
|
6255
|
+
logger10.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6407
6256
|
return false;
|
|
6408
6257
|
}
|
|
6409
|
-
|
|
6258
|
+
logger10.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6410
6259
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6411
|
-
|
|
6260
|
+
logger10.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6412
6261
|
try {
|
|
6413
6262
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6414
6263
|
if (!captchaContext) {
|
|
6415
|
-
|
|
6264
|
+
logger10.info("Captcha container is not visible anymore.");
|
|
6416
6265
|
return true;
|
|
6417
6266
|
}
|
|
6418
6267
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6425,7 +6274,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6425
6274
|
"ready",
|
|
6426
6275
|
config
|
|
6427
6276
|
).catch((error) => {
|
|
6428
|
-
|
|
6277
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6429
6278
|
});
|
|
6430
6279
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6431
6280
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6437,16 +6286,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6437
6286
|
});
|
|
6438
6287
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6439
6288
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6440
|
-
|
|
6289
|
+
logger10.warn(
|
|
6441
6290
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6442
6291
|
);
|
|
6443
6292
|
await refreshCaptcha(page, frame, config);
|
|
6444
6293
|
continue;
|
|
6445
6294
|
}
|
|
6446
|
-
|
|
6295
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6447
6296
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6448
6297
|
if (!dropTarget) {
|
|
6449
|
-
|
|
6298
|
+
logger10.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6450
6299
|
await refreshCaptcha(page, frame, config);
|
|
6451
6300
|
continue;
|
|
6452
6301
|
}
|
|
@@ -6457,7 +6306,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6457
6306
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6458
6307
|
);
|
|
6459
6308
|
}
|
|
6460
|
-
|
|
6309
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6461
6310
|
for (const imageIndex of normalizedIndexes) {
|
|
6462
6311
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6463
6312
|
throw new Error(
|
|
@@ -6489,52 +6338,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6489
6338
|
}
|
|
6490
6339
|
}
|
|
6491
6340
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6492
|
-
|
|
6341
|
+
logger10.info(
|
|
6493
6342
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6494
6343
|
);
|
|
6495
6344
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6496
6345
|
...config,
|
|
6497
6346
|
page,
|
|
6498
|
-
logger:
|
|
6347
|
+
logger: logger10,
|
|
6499
6348
|
forceMouse: true,
|
|
6500
6349
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6501
6350
|
}).catch(() => false);
|
|
6502
6351
|
if (!submitted) {
|
|
6503
|
-
|
|
6352
|
+
logger10.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6504
6353
|
}
|
|
6505
6354
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6506
6355
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6507
|
-
|
|
6356
|
+
logger10.info(
|
|
6508
6357
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6509
6358
|
);
|
|
6510
6359
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6511
6360
|
if (!stillVisible) {
|
|
6512
|
-
|
|
6361
|
+
logger10.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6513
6362
|
return true;
|
|
6514
6363
|
}
|
|
6515
6364
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6516
6365
|
beforeSubmitState,
|
|
6517
6366
|
afterSubmitState
|
|
6518
6367
|
}).catch((error) => {
|
|
6519
|
-
|
|
6368
|
+
logger10.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6520
6369
|
});
|
|
6521
|
-
|
|
6370
|
+
logger10.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6522
6371
|
await page.waitForTimeout(2e3);
|
|
6523
6372
|
await refreshCaptcha(page, frame, config);
|
|
6524
6373
|
} catch (error) {
|
|
6525
|
-
|
|
6374
|
+
logger10.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6526
6375
|
}
|
|
6527
6376
|
if (attempt < config.maxRetries) {
|
|
6528
6377
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6529
6378
|
}
|
|
6530
6379
|
}
|
|
6531
|
-
|
|
6380
|
+
logger10.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6532
6381
|
return false;
|
|
6533
6382
|
}
|
|
6534
6383
|
var sloveCaptcha = solveCaptcha;
|
|
6535
6384
|
|
|
6536
6385
|
// src/chaptcha.js
|
|
6537
|
-
var
|
|
6386
|
+
var logger11 = createInternalLogger("Captcha");
|
|
6538
6387
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6539
6388
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6540
6389
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6621,7 +6470,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6621
6470
|
};
|
|
6622
6471
|
})();
|
|
6623
6472
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6624
|
-
|
|
6473
|
+
logger11.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6625
6474
|
cleanupFns.push(async () => {
|
|
6626
6475
|
try {
|
|
6627
6476
|
await page.evaluate((name) => {
|
|
@@ -6645,14 +6494,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
6645
6494
|
}
|
|
6646
6495
|
};
|
|
6647
6496
|
page.on("framenavigated", frameHandler);
|
|
6648
|
-
|
|
6497
|
+
logger11.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6649
6498
|
cleanupFns.push(async () => {
|
|
6650
6499
|
page.off("framenavigated", frameHandler);
|
|
6651
6500
|
});
|
|
6652
6501
|
}
|
|
6653
6502
|
return {
|
|
6654
6503
|
stop: async () => {
|
|
6655
|
-
|
|
6504
|
+
logger11.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6656
6505
|
for (const fn of cleanupFns) {
|
|
6657
6506
|
await fn();
|
|
6658
6507
|
}
|
|
@@ -6691,7 +6540,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6691
6540
|
);
|
|
6692
6541
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6693
6542
|
callCaptchaRecognitionApi,
|
|
6694
|
-
logger:
|
|
6543
|
+
logger: logger11
|
|
6695
6544
|
});
|
|
6696
6545
|
}
|
|
6697
6546
|
var Captcha = {
|
|
@@ -6702,7 +6551,7 @@ var Captcha = {
|
|
|
6702
6551
|
// src/mutation.js
|
|
6703
6552
|
import { createHash } from "node:crypto";
|
|
6704
6553
|
import { v4 as uuidv42 } from "uuid";
|
|
6705
|
-
var
|
|
6554
|
+
var logger12 = createInternalLogger("Mutation");
|
|
6706
6555
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6707
6556
|
Added: "added",
|
|
6708
6557
|
Changed: "changed",
|
|
@@ -6735,14 +6584,14 @@ var Mutation = {
|
|
|
6735
6584
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6736
6585
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6737
6586
|
const onMutation = options.onMutation;
|
|
6738
|
-
|
|
6587
|
+
logger12.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6739
6588
|
if (initialTimeout > 0) {
|
|
6740
6589
|
const selectorQuery = selectorList.join(",");
|
|
6741
6590
|
try {
|
|
6742
6591
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6743
|
-
|
|
6592
|
+
logger12.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6744
6593
|
} catch (e) {
|
|
6745
|
-
|
|
6594
|
+
logger12.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6746
6595
|
throw e;
|
|
6747
6596
|
}
|
|
6748
6597
|
}
|
|
@@ -6758,7 +6607,7 @@ var Mutation = {
|
|
|
6758
6607
|
return "__CONTINUE__";
|
|
6759
6608
|
}
|
|
6760
6609
|
});
|
|
6761
|
-
|
|
6610
|
+
logger12.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6762
6611
|
} catch (e) {
|
|
6763
6612
|
}
|
|
6764
6613
|
}
|
|
@@ -6873,9 +6722,9 @@ var Mutation = {
|
|
|
6873
6722
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6874
6723
|
);
|
|
6875
6724
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6876
|
-
|
|
6725
|
+
logger12.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6877
6726
|
}
|
|
6878
|
-
|
|
6727
|
+
logger12.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6879
6728
|
return result;
|
|
6880
6729
|
},
|
|
6881
6730
|
/**
|
|
@@ -7047,29 +6896,29 @@ var Mutation = {
|
|
|
7047
6896
|
return "__CONTINUE__";
|
|
7048
6897
|
}
|
|
7049
6898
|
};
|
|
7050
|
-
|
|
6899
|
+
logger12.start(
|
|
7051
6900
|
"waitForStableAcrossRoots",
|
|
7052
6901
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
7053
6902
|
);
|
|
7054
6903
|
if (initialTimeout > 0) {
|
|
7055
6904
|
try {
|
|
7056
6905
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
7057
|
-
|
|
6906
|
+
logger12.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
7058
6907
|
} catch (e) {
|
|
7059
|
-
|
|
6908
|
+
logger12.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
7060
6909
|
throw e;
|
|
7061
6910
|
}
|
|
7062
6911
|
}
|
|
7063
|
-
let
|
|
7064
|
-
if (!
|
|
7065
|
-
|
|
6912
|
+
let state2 = await buildState();
|
|
6913
|
+
if (!state2?.hasMatched) {
|
|
6914
|
+
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
7066
6915
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
7067
6916
|
}
|
|
7068
6917
|
let mutationCount = 0;
|
|
7069
6918
|
let stableSince = 0;
|
|
7070
6919
|
let isPaused = false;
|
|
7071
6920
|
let wasPaused = false;
|
|
7072
|
-
let lastSnapshotKey =
|
|
6921
|
+
let lastSnapshotKey = state2.snapshotKey;
|
|
7073
6922
|
const applyPauseSignal = (signal) => {
|
|
7074
6923
|
const nextPaused = signal === "__PAUSE__";
|
|
7075
6924
|
if (nextPaused) {
|
|
@@ -7083,13 +6932,13 @@ var Mutation = {
|
|
|
7083
6932
|
};
|
|
7084
6933
|
const initialSignal = await invokeMutationCallback({
|
|
7085
6934
|
mutationCount: 0,
|
|
7086
|
-
html:
|
|
7087
|
-
text:
|
|
7088
|
-
mutationNodes:
|
|
6935
|
+
html: state2.html || "",
|
|
6936
|
+
text: state2.text || "",
|
|
6937
|
+
mutationNodes: state2.mutationNodes || []
|
|
7089
6938
|
});
|
|
7090
6939
|
applyPauseSignal(initialSignal);
|
|
7091
6940
|
const deadline = Date.now() + overallTimeout;
|
|
7092
|
-
let lastState =
|
|
6941
|
+
let lastState = state2;
|
|
7093
6942
|
while (Date.now() < deadline) {
|
|
7094
6943
|
await sleep(pollInterval);
|
|
7095
6944
|
lastState = await buildState();
|
|
@@ -7099,7 +6948,7 @@ var Mutation = {
|
|
|
7099
6948
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
7100
6949
|
lastSnapshotKey = lastState.snapshotKey;
|
|
7101
6950
|
mutationCount += 1;
|
|
7102
|
-
|
|
6951
|
+
logger12.info(
|
|
7103
6952
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
7104
6953
|
);
|
|
7105
6954
|
const signal = await invokeMutationCallback({
|
|
@@ -7112,7 +6961,7 @@ var Mutation = {
|
|
|
7112
6961
|
continue;
|
|
7113
6962
|
}
|
|
7114
6963
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
7115
|
-
|
|
6964
|
+
logger12.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
7116
6965
|
return {
|
|
7117
6966
|
mutationCount,
|
|
7118
6967
|
stableTime: waitForStableTime,
|
|
@@ -7139,7 +6988,7 @@ var Mutation = {
|
|
|
7139
6988
|
const onMutation = options.onMutation;
|
|
7140
6989
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
7141
6990
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
7142
|
-
|
|
6991
|
+
logger12.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
7143
6992
|
const monitorKey = generateKey("pk_mon");
|
|
7144
6993
|
const callbackName = generateKey("pk_mon_cb");
|
|
7145
6994
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7282,7 +7131,7 @@ var Mutation = {
|
|
|
7282
7131
|
return total;
|
|
7283
7132
|
};
|
|
7284
7133
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7285
|
-
|
|
7134
|
+
logger12.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7286
7135
|
return {
|
|
7287
7136
|
stop: async () => {
|
|
7288
7137
|
let totalMutations = 0;
|
|
@@ -7295,7 +7144,7 @@ var Mutation = {
|
|
|
7295
7144
|
}, cleanerName);
|
|
7296
7145
|
} catch (e) {
|
|
7297
7146
|
}
|
|
7298
|
-
|
|
7147
|
+
logger12.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7299
7148
|
return { totalMutations };
|
|
7300
7149
|
}
|
|
7301
7150
|
};
|
|
@@ -8164,7 +8013,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
8164
8013
|
};
|
|
8165
8014
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
8166
8015
|
var Logger = {
|
|
8167
|
-
setLogger: (
|
|
8016
|
+
setLogger: (logger16) => setDefaultLogger(logger16),
|
|
8168
8017
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
8169
8018
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
8170
8019
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -8172,8 +8021,8 @@ var Logger = {
|
|
|
8172
8021
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
8173
8022
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
8174
8023
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
8175
|
-
useTemplate: (
|
|
8176
|
-
if (
|
|
8024
|
+
useTemplate: (logger16) => {
|
|
8025
|
+
if (logger16) return createTemplateLogger(createBaseLogger("", logger16));
|
|
8177
8026
|
return createTemplateLogger();
|
|
8178
8027
|
}
|
|
8179
8028
|
};
|
|
@@ -8247,7 +8096,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
8247
8096
|
];
|
|
8248
8097
|
var cachedStripLogoSrcPromise = null;
|
|
8249
8098
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
8250
|
-
var
|
|
8099
|
+
var logger13 = createInternalLogger("Watermarkify");
|
|
8251
8100
|
var normalizeText = (value) => String(value || "").trim();
|
|
8252
8101
|
var toInline = (value, maxLen = 200) => {
|
|
8253
8102
|
const text = normalizeText(value);
|
|
@@ -8489,9 +8338,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8489
8338
|
location: toInline(resolved.location, 80)
|
|
8490
8339
|
};
|
|
8491
8340
|
if (enrichment.ip || enrichment.location) {
|
|
8492
|
-
|
|
8341
|
+
logger13.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8493
8342
|
} else {
|
|
8494
|
-
|
|
8343
|
+
logger13.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8495
8344
|
}
|
|
8496
8345
|
return enrichment;
|
|
8497
8346
|
} finally {
|
|
@@ -8680,12 +8529,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8680
8529
|
};
|
|
8681
8530
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8682
8531
|
if (!page || typeof page.context !== "function") {
|
|
8683
|
-
|
|
8532
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8684
8533
|
return buffer;
|
|
8685
8534
|
}
|
|
8686
8535
|
const renderScope = await openProbePage(page);
|
|
8687
8536
|
if (!renderScope?.page) {
|
|
8688
|
-
|
|
8537
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8689
8538
|
return buffer;
|
|
8690
8539
|
}
|
|
8691
8540
|
try {
|
|
@@ -8750,13 +8599,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8750
8599
|
fullPage: true,
|
|
8751
8600
|
animations: "disabled"
|
|
8752
8601
|
}).catch((error) => {
|
|
8753
|
-
|
|
8602
|
+
logger13.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8754
8603
|
return null;
|
|
8755
8604
|
});
|
|
8756
8605
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8757
8606
|
return composed;
|
|
8758
8607
|
}
|
|
8759
|
-
|
|
8608
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8760
8609
|
return buffer;
|
|
8761
8610
|
} finally {
|
|
8762
8611
|
await renderScope.close().catch(() => {
|
|
@@ -8769,7 +8618,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8769
8618
|
}
|
|
8770
8619
|
const probeScope = await openProbePage(page);
|
|
8771
8620
|
if (!probeScope?.page) {
|
|
8772
|
-
|
|
8621
|
+
logger13.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8773
8622
|
return null;
|
|
8774
8623
|
}
|
|
8775
8624
|
const timeoutMs = Math.max(
|
|
@@ -8778,12 +8627,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8778
8627
|
);
|
|
8779
8628
|
try {
|
|
8780
8629
|
const probePage = probeScope.page;
|
|
8781
|
-
|
|
8630
|
+
logger13.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8782
8631
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8783
8632
|
waitUntil: "commit",
|
|
8784
8633
|
timeout: timeoutMs
|
|
8785
8634
|
}).catch((error) => {
|
|
8786
|
-
|
|
8635
|
+
logger13.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8787
8636
|
return null;
|
|
8788
8637
|
});
|
|
8789
8638
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8805,13 +8654,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8805
8654
|
}
|
|
8806
8655
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8807
8656
|
if (parsed?.ip || parsed?.location) {
|
|
8808
|
-
|
|
8657
|
+
logger13.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8809
8658
|
return parsed;
|
|
8810
8659
|
}
|
|
8811
|
-
|
|
8660
|
+
logger13.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8812
8661
|
return null;
|
|
8813
8662
|
} catch (error) {
|
|
8814
|
-
|
|
8663
|
+
logger13.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8815
8664
|
return null;
|
|
8816
8665
|
} finally {
|
|
8817
8666
|
await probeScope.close().catch(() => {
|
|
@@ -8825,10 +8674,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8825
8674
|
ip: toInline(options.ip, 80),
|
|
8826
8675
|
location: toInline(options.location, 80)
|
|
8827
8676
|
};
|
|
8828
|
-
|
|
8677
|
+
logger13.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8829
8678
|
if (!merged.ip || !merged.location) {
|
|
8830
8679
|
if (cached?.ip || cached?.location) {
|
|
8831
|
-
|
|
8680
|
+
logger13.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8832
8681
|
}
|
|
8833
8682
|
fillEnrichment(merged, cached);
|
|
8834
8683
|
}
|
|
@@ -8852,15 +8701,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8852
8701
|
"x-geo-country"
|
|
8853
8702
|
]), 80);
|
|
8854
8703
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8855
|
-
|
|
8704
|
+
logger13.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8856
8705
|
merged.location = headerLocation || merged.location;
|
|
8857
8706
|
}
|
|
8858
8707
|
}
|
|
8859
8708
|
writeCachedEnrichment(page, merged);
|
|
8860
8709
|
if (merged.ip || merged.location) {
|
|
8861
|
-
|
|
8710
|
+
logger13.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8862
8711
|
} else {
|
|
8863
|
-
|
|
8712
|
+
logger13.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8864
8713
|
}
|
|
8865
8714
|
return merged;
|
|
8866
8715
|
};
|
|
@@ -9673,7 +9522,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9673
9522
|
}
|
|
9674
9523
|
const imageInfo = readImageInfo(buffer);
|
|
9675
9524
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9676
|
-
|
|
9525
|
+
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9677
9526
|
return buffer;
|
|
9678
9527
|
}
|
|
9679
9528
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9691,7 +9540,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9691
9540
|
|
|
9692
9541
|
// src/internals/compression.js
|
|
9693
9542
|
import { Jimp, JimpMime, ResizeStrategy } from "jimp";
|
|
9694
|
-
var
|
|
9543
|
+
var logger14 = createInternalLogger("Compression");
|
|
9695
9544
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9696
9545
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9697
9546
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9810,18 +9659,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9810
9659
|
return buffer.toString("base64");
|
|
9811
9660
|
}
|
|
9812
9661
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9813
|
-
|
|
9662
|
+
logger14.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9814
9663
|
return null;
|
|
9815
9664
|
});
|
|
9816
9665
|
if (!result?.buffer) {
|
|
9817
9666
|
return buffer.toString("base64");
|
|
9818
9667
|
}
|
|
9819
9668
|
if (result.withinLimit) {
|
|
9820
|
-
|
|
9669
|
+
logger14.info(
|
|
9821
9670
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9822
9671
|
);
|
|
9823
9672
|
} else {
|
|
9824
|
-
|
|
9673
|
+
logger14.warning(
|
|
9825
9674
|
`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}`
|
|
9826
9675
|
);
|
|
9827
9676
|
}
|
|
@@ -9829,7 +9678,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9829
9678
|
};
|
|
9830
9679
|
|
|
9831
9680
|
// src/share.js
|
|
9832
|
-
var
|
|
9681
|
+
var logger15 = createInternalLogger("Share");
|
|
9833
9682
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9834
9683
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9835
9684
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9966,7 +9815,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9966
9815
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9967
9816
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9968
9817
|
let matched = false;
|
|
9969
|
-
|
|
9818
|
+
logger15.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9970
9819
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9971
9820
|
mode,
|
|
9972
9821
|
onMutation: (context = {}) => {
|
|
@@ -9984,12 +9833,12 @@ ${text}`;
|
|
|
9984
9833
|
});
|
|
9985
9834
|
}
|
|
9986
9835
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9987
|
-
|
|
9836
|
+
logger15.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9988
9837
|
}
|
|
9989
9838
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9990
9839
|
if (!candidate) return;
|
|
9991
9840
|
matched = true;
|
|
9992
|
-
|
|
9841
|
+
logger15.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9993
9842
|
if (onMatch) {
|
|
9994
9843
|
onMatch({
|
|
9995
9844
|
link: candidate,
|
|
@@ -10005,7 +9854,7 @@ ${text}`;
|
|
|
10005
9854
|
return {
|
|
10006
9855
|
stop: async () => {
|
|
10007
9856
|
const result = await monitor.stop();
|
|
10008
|
-
|
|
9857
|
+
logger15.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
10009
9858
|
return result;
|
|
10010
9859
|
}
|
|
10011
9860
|
};
|
|
@@ -10054,8 +9903,8 @@ var Share = {
|
|
|
10054
9903
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
10055
9904
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
10056
9905
|
}
|
|
10057
|
-
|
|
10058
|
-
|
|
9906
|
+
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9907
|
+
logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
10059
9908
|
const stats = {
|
|
10060
9909
|
actionTimedOut: false,
|
|
10061
9910
|
domMutationCount: 0,
|
|
@@ -10067,7 +9916,7 @@ var Share = {
|
|
|
10067
9916
|
responseSampleUrls: []
|
|
10068
9917
|
};
|
|
10069
9918
|
if (isAborted()) {
|
|
10070
|
-
|
|
9919
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10071
9920
|
return {
|
|
10072
9921
|
link: null,
|
|
10073
9922
|
payloadText: "",
|
|
@@ -10090,7 +9939,7 @@ var Share = {
|
|
|
10090
9939
|
link: validated,
|
|
10091
9940
|
payloadText: String(payloadText || "")
|
|
10092
9941
|
};
|
|
10093
|
-
|
|
9942
|
+
logger15.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
10094
9943
|
return true;
|
|
10095
9944
|
};
|
|
10096
9945
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -10125,7 +9974,7 @@ var Share = {
|
|
|
10125
9974
|
try {
|
|
10126
9975
|
await monitor.stop();
|
|
10127
9976
|
} catch (error) {
|
|
10128
|
-
|
|
9977
|
+
logger15.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
10129
9978
|
}
|
|
10130
9979
|
};
|
|
10131
9980
|
const onResponse = async (response) => {
|
|
@@ -10139,29 +9988,29 @@ var Share = {
|
|
|
10139
9988
|
stats.responseSampleUrls.push(url);
|
|
10140
9989
|
}
|
|
10141
9990
|
if (stats.responseObserved <= 5) {
|
|
10142
|
-
|
|
9991
|
+
logger15.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
10143
9992
|
}
|
|
10144
9993
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
10145
9994
|
stats.responseMatched += 1;
|
|
10146
9995
|
stats.lastMatchedUrl = url;
|
|
10147
|
-
|
|
9996
|
+
logger15.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
10148
9997
|
const text = await response.text();
|
|
10149
9998
|
const hit = resolveResponseCandidate(text);
|
|
10150
9999
|
if (!hit?.link) {
|
|
10151
10000
|
if (stats.responseMatched <= 3) {
|
|
10152
|
-
|
|
10001
|
+
logger15.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
10153
10002
|
}
|
|
10154
10003
|
return;
|
|
10155
10004
|
}
|
|
10156
10005
|
stats.responseResolved += 1;
|
|
10157
|
-
|
|
10006
|
+
logger15.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
10158
10007
|
setCandidate("response", hit.link, hit.payloadText);
|
|
10159
10008
|
} catch (error) {
|
|
10160
|
-
|
|
10009
|
+
logger15.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
10161
10010
|
}
|
|
10162
10011
|
};
|
|
10163
10012
|
if (share.mode === "dom") {
|
|
10164
|
-
|
|
10013
|
+
logger15.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
10165
10014
|
domMonitor = await createDomShareMonitor(page, {
|
|
10166
10015
|
prefix: share.prefix,
|
|
10167
10016
|
selectors: domSelectors,
|
|
@@ -10176,17 +10025,17 @@ var Share = {
|
|
|
10176
10025
|
});
|
|
10177
10026
|
}
|
|
10178
10027
|
if (share.mode === "response") {
|
|
10179
|
-
|
|
10028
|
+
logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
10180
10029
|
page.on("response", onResponse);
|
|
10181
10030
|
}
|
|
10182
10031
|
if (share.mode === "custom") {
|
|
10183
|
-
|
|
10032
|
+
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
10184
10033
|
}
|
|
10185
10034
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
10186
10035
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
10187
10036
|
try {
|
|
10188
10037
|
const actionTimeout = getRemainingMs();
|
|
10189
|
-
|
|
10038
|
+
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
10190
10039
|
let actionValue;
|
|
10191
10040
|
if (!isAborted() && actionTimeout > 0) {
|
|
10192
10041
|
let timer = null;
|
|
@@ -10199,30 +10048,30 @@ var Share = {
|
|
|
10199
10048
|
]);
|
|
10200
10049
|
if (timer) clearTimeout(timer);
|
|
10201
10050
|
if (actionResult.type === "error") {
|
|
10202
|
-
|
|
10051
|
+
logger15.fail("captureLink.performActions", actionResult.error);
|
|
10203
10052
|
throw actionResult.error;
|
|
10204
10053
|
}
|
|
10205
10054
|
if (actionResult.type === "timeout") {
|
|
10206
10055
|
stats.actionTimedOut = true;
|
|
10207
|
-
|
|
10056
|
+
logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
10208
10057
|
} else {
|
|
10209
10058
|
actionValue = actionResult.result;
|
|
10210
|
-
|
|
10059
|
+
logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
10211
10060
|
}
|
|
10212
10061
|
}
|
|
10213
10062
|
if (share.mode === "custom") {
|
|
10214
10063
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
10215
10064
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
10216
10065
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
10217
|
-
|
|
10066
|
+
logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
10218
10067
|
} else {
|
|
10219
|
-
|
|
10068
|
+
logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
10220
10069
|
}
|
|
10221
10070
|
}
|
|
10222
10071
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
10223
10072
|
while (true) {
|
|
10224
10073
|
if (isAborted()) {
|
|
10225
|
-
|
|
10074
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
10226
10075
|
return {
|
|
10227
10076
|
link: null,
|
|
10228
10077
|
payloadText: "",
|
|
@@ -10232,7 +10081,7 @@ var Share = {
|
|
|
10232
10081
|
}
|
|
10233
10082
|
const selected = candidates[share.mode];
|
|
10234
10083
|
if (selected?.link) {
|
|
10235
|
-
|
|
10084
|
+
logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
10236
10085
|
return {
|
|
10237
10086
|
link: selected.link,
|
|
10238
10087
|
payloadText: selected.payloadText,
|
|
@@ -10245,7 +10094,7 @@ var Share = {
|
|
|
10245
10094
|
if (remaining <= 0) break;
|
|
10246
10095
|
const now = Date.now();
|
|
10247
10096
|
if (now >= nextProgressLogTs) {
|
|
10248
|
-
|
|
10097
|
+
logger15.info(
|
|
10249
10098
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
10250
10099
|
);
|
|
10251
10100
|
nextProgressLogTs = now + 5e3;
|
|
@@ -10253,11 +10102,11 @@ var Share = {
|
|
|
10253
10102
|
await delay5(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10254
10103
|
}
|
|
10255
10104
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10256
|
-
|
|
10105
|
+
logger15.warning(
|
|
10257
10106
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
10258
10107
|
);
|
|
10259
10108
|
}
|
|
10260
|
-
|
|
10109
|
+
logger15.warning(
|
|
10261
10110
|
`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"}`
|
|
10262
10111
|
);
|
|
10263
10112
|
return {
|
|
@@ -10269,7 +10118,7 @@ var Share = {
|
|
|
10269
10118
|
} finally {
|
|
10270
10119
|
if (share.mode === "response") {
|
|
10271
10120
|
page.off("response", onResponse);
|
|
10272
|
-
|
|
10121
|
+
logger15.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10273
10122
|
}
|
|
10274
10123
|
await stopDomMonitor();
|
|
10275
10124
|
}
|