@skrillex1224/playwright-toolkit 3.0.13 → 3.0.15
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 +161 -409
- package/dist/browser.js.map +4 -4
- package/dist/index.cjs +479 -976
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +479 -976
- package/dist/index.js.map +4 -4
- package/index.d.ts +9 -40
- package/package.json +1 -7
package/dist/index.cjs
CHANGED
|
@@ -40,11 +40,9 @@ __export(constants_exports, {
|
|
|
40
40
|
ActorInfo: () => ActorInfo,
|
|
41
41
|
Code: () => Code,
|
|
42
42
|
Device: () => Device,
|
|
43
|
-
Mode: () => Mode,
|
|
44
43
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
45
44
|
Status: () => Status,
|
|
46
|
-
normalizeDevice: () => normalizeDevice
|
|
47
|
-
normalizeMode: () => normalizeMode
|
|
45
|
+
normalizeDevice: () => normalizeDevice
|
|
48
46
|
});
|
|
49
47
|
var Code = {
|
|
50
48
|
Success: 0,
|
|
@@ -64,10 +62,6 @@ var Device = Object.freeze({
|
|
|
64
62
|
Desktop: "desktop",
|
|
65
63
|
Mobile: "mobile"
|
|
66
64
|
});
|
|
67
|
-
var Mode = Object.freeze({
|
|
68
|
-
Default: "default",
|
|
69
|
-
Cloak: "cloak"
|
|
70
|
-
});
|
|
71
65
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
72
66
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
73
67
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -75,13 +69,6 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
75
69
|
if (raw === Device.Desktop) return Device.Desktop;
|
|
76
70
|
return normalizedFallback;
|
|
77
71
|
};
|
|
78
|
-
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
79
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
80
|
-
const raw = String(value || "").trim().toLowerCase();
|
|
81
|
-
if (raw === Mode.Cloak) return Mode.Cloak;
|
|
82
|
-
if (raw === Mode.Default) return Mode.Default;
|
|
83
|
-
return normalizedFallback;
|
|
84
|
-
};
|
|
85
72
|
var createActorInfo = (info) => {
|
|
86
73
|
const normalizeDomain = (value) => {
|
|
87
74
|
if (!value) return "";
|
|
@@ -149,6 +136,7 @@ var createActorInfo = (info) => {
|
|
|
149
136
|
const buildLandingUrl = ({ protocol: protocol2, domain: domain2, path: path4 }) => {
|
|
150
137
|
const safeProtocol = String(protocol2).trim();
|
|
151
138
|
const safeDomain = normalizeDomain(domain2);
|
|
139
|
+
if (!safeDomain) return "";
|
|
152
140
|
const safePath = normalizePath(path4);
|
|
153
141
|
return `${safeProtocol}://${safeDomain}${safePath}`;
|
|
154
142
|
};
|
|
@@ -356,6 +344,18 @@ var ActorInfo = {
|
|
|
356
344
|
prefix: "",
|
|
357
345
|
xurl: []
|
|
358
346
|
}
|
|
347
|
+
}),
|
|
348
|
+
// 通用网页抓取 Actor:入口 URL 来自 query,因此这里只声明统一的 Actor 元信息。
|
|
349
|
+
webpage: createActorInfo({
|
|
350
|
+
key: "webpage",
|
|
351
|
+
name: "\u901A\u7528\u7F51\u9875",
|
|
352
|
+
domain: "",
|
|
353
|
+
path: "/",
|
|
354
|
+
share: {
|
|
355
|
+
mode: "dom",
|
|
356
|
+
prefix: "",
|
|
357
|
+
xurl: []
|
|
358
|
+
}
|
|
359
359
|
})
|
|
360
360
|
};
|
|
361
361
|
|
|
@@ -387,18 +387,18 @@ var fallbackLog = {
|
|
|
387
387
|
error: (...args) => console.error(...args),
|
|
388
388
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
389
389
|
};
|
|
390
|
-
var resolveLogMethod = (
|
|
391
|
-
if (
|
|
392
|
-
return
|
|
390
|
+
var resolveLogMethod = (logger16, name) => {
|
|
391
|
+
if (logger16 && typeof logger16[name] === "function") {
|
|
392
|
+
return logger16[name].bind(logger16);
|
|
393
393
|
}
|
|
394
|
-
if (name === "warning" &&
|
|
395
|
-
return
|
|
394
|
+
if (name === "warning" && logger16 && typeof logger16.warn === "function") {
|
|
395
|
+
return logger16.warn.bind(logger16);
|
|
396
396
|
}
|
|
397
397
|
return fallbackLog[name];
|
|
398
398
|
};
|
|
399
399
|
var defaultLogger = null;
|
|
400
|
-
var setDefaultLogger = (
|
|
401
|
-
defaultLogger =
|
|
400
|
+
var setDefaultLogger = (logger16) => {
|
|
401
|
+
defaultLogger = logger16;
|
|
402
402
|
};
|
|
403
403
|
var resolveLogger = (explicitLogger) => {
|
|
404
404
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -425,8 +425,8 @@ var colorize = (text, color) => {
|
|
|
425
425
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
426
426
|
const name = prefix ? String(prefix) : "";
|
|
427
427
|
const dispatch = (methodName, icon, message, color) => {
|
|
428
|
-
const
|
|
429
|
-
const logFn = resolveLogMethod(
|
|
428
|
+
const logger16 = resolveLogger(explicitLogger);
|
|
429
|
+
const logFn = resolveLogMethod(logger16, methodName);
|
|
430
430
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
431
431
|
const line = formatLine(name, icon, message);
|
|
432
432
|
const coloredLine = colorize(line, color);
|
|
@@ -780,7 +780,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
780
780
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
781
781
|
return 0;
|
|
782
782
|
}
|
|
783
|
-
const
|
|
783
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
784
784
|
const isVisible = (el, style, rect) => {
|
|
785
785
|
if (!el || !style || !rect) return false;
|
|
786
786
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -820,7 +820,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
820
820
|
return true;
|
|
821
821
|
});
|
|
822
822
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
823
|
-
if (!
|
|
823
|
+
if (!hasOwn(el.dataset, "pkAffixedAdjusted")) {
|
|
824
824
|
el.dataset.pkAffixedAdjusted = "1";
|
|
825
825
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
826
826
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -851,7 +851,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
851
851
|
};
|
|
852
852
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
853
853
|
await page.evaluate((className) => {
|
|
854
|
-
const
|
|
854
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
855
855
|
const expansionKeys = [
|
|
856
856
|
"pkOrigOverflow",
|
|
857
857
|
"pkOrigHeight",
|
|
@@ -859,28 +859,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
859
859
|
"pkOrigMaxHeight"
|
|
860
860
|
];
|
|
861
861
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
862
|
-
if (
|
|
862
|
+
if (hasOwn(el.dataset, "pkOrigPosition")) {
|
|
863
863
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
864
864
|
delete el.dataset.pkOrigPosition;
|
|
865
865
|
delete el.dataset.pkOrigPositionPriority;
|
|
866
866
|
}
|
|
867
|
-
if (
|
|
867
|
+
if (hasOwn(el.dataset, "pkOrigTop")) {
|
|
868
868
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
869
869
|
delete el.dataset.pkOrigTop;
|
|
870
870
|
delete el.dataset.pkOrigTopPriority;
|
|
871
871
|
}
|
|
872
|
-
if (
|
|
872
|
+
if (hasOwn(el.dataset, "pkOrigBottom")) {
|
|
873
873
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
874
874
|
delete el.dataset.pkOrigBottom;
|
|
875
875
|
delete el.dataset.pkOrigBottomPriority;
|
|
876
876
|
}
|
|
877
|
-
if (
|
|
877
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
878
878
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
879
879
|
delete el.dataset.pkOrigTranslate;
|
|
880
880
|
delete el.dataset.pkOrigTranslatePriority;
|
|
881
881
|
}
|
|
882
882
|
delete el.dataset.pkAffixedAdjusted;
|
|
883
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
883
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
884
884
|
if (!stillExpanded) {
|
|
885
885
|
el.classList.remove(className);
|
|
886
886
|
}
|
|
@@ -923,7 +923,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
923
923
|
viewportResized
|
|
924
924
|
};
|
|
925
925
|
};
|
|
926
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
926
|
+
var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
927
927
|
await page.evaluate((className) => {
|
|
928
928
|
const targets = new Set([
|
|
929
929
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -947,8 +947,8 @@ var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
|
947
947
|
el.classList.remove(className);
|
|
948
948
|
});
|
|
949
949
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
950
|
-
if (
|
|
951
|
-
await page.setViewportSize(
|
|
950
|
+
if (state?.originalViewport && state?.viewportResized) {
|
|
951
|
+
await page.setViewportSize(state.originalViewport);
|
|
952
952
|
}
|
|
953
953
|
};
|
|
954
954
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -1005,21 +1005,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
};
|
|
1007
1007
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
1008
|
-
const
|
|
1008
|
+
const state = await prepareExpandedFullPageScreenshot(page, options);
|
|
1009
1009
|
try {
|
|
1010
1010
|
return await capturePageScreenshot(page, {
|
|
1011
1011
|
fullPage: true,
|
|
1012
1012
|
type: options.type || "png",
|
|
1013
1013
|
quality: options.quality,
|
|
1014
1014
|
timeout: options.timeout,
|
|
1015
|
-
maxClipHeight:
|
|
1015
|
+
maxClipHeight: state.targetHeight
|
|
1016
1016
|
});
|
|
1017
1017
|
} finally {
|
|
1018
1018
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
1019
1019
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
1020
1020
|
});
|
|
1021
1021
|
if (options.restore) {
|
|
1022
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
1022
|
+
await restoreExpandedFullPageScreenshot(page, state);
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
1025
|
};
|
|
@@ -1938,8 +1938,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1938
1938
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1939
1939
|
};
|
|
1940
1940
|
};
|
|
1941
|
-
var rememberRuntimeState = (
|
|
1942
|
-
rememberedRuntimeState = deepClone(
|
|
1941
|
+
var rememberRuntimeState = (state) => {
|
|
1942
|
+
rememberedRuntimeState = deepClone(state);
|
|
1943
1943
|
return rememberedRuntimeState;
|
|
1944
1944
|
};
|
|
1945
1945
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1998,7 +1998,7 @@ var RuntimeEnv = {
|
|
|
1998
1998
|
} else {
|
|
1999
1999
|
delete normalizedRuntime.browser_profile;
|
|
2000
2000
|
}
|
|
2001
|
-
const
|
|
2001
|
+
const state = {
|
|
2002
2002
|
actor: resolvedActor,
|
|
2003
2003
|
device,
|
|
2004
2004
|
runtime: normalizedRuntime,
|
|
@@ -2012,73 +2012,73 @@ var RuntimeEnv = {
|
|
|
2012
2012
|
browserProfileCore: browserProfile.core,
|
|
2013
2013
|
browserProfileObserved: browserProfile.observed
|
|
2014
2014
|
};
|
|
2015
|
-
rememberRuntimeState(
|
|
2016
|
-
return
|
|
2015
|
+
rememberRuntimeState(state);
|
|
2016
|
+
return state;
|
|
2017
2017
|
},
|
|
2018
2018
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
2019
2019
|
buildEnvPatch(source = {}, actor = "") {
|
|
2020
|
-
const
|
|
2021
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
2020
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2021
|
+
const browserProfile = buildBrowserProfilePayload(state.browserProfileCore, state.browserProfileObserved);
|
|
2022
2022
|
const envPatch = {
|
|
2023
|
-
...Array.isArray(
|
|
2024
|
-
...Object.keys(
|
|
2025
|
-
...Object.keys(
|
|
2023
|
+
...Array.isArray(state.cookies) && state.cookies.length > 0 ? { cookies: state.cookies } : {},
|
|
2024
|
+
...Object.keys(state.localStorage || {}).length > 0 ? { local_storage: state.localStorage } : {},
|
|
2025
|
+
...Object.keys(state.sessionStorage || {}).length > 0 ? { session_storage: state.sessionStorage } : {},
|
|
2026
2026
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
2027
2027
|
};
|
|
2028
2028
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
2029
2029
|
},
|
|
2030
2030
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
2031
2031
|
hasLoginState(source = {}, actor = "") {
|
|
2032
|
-
const
|
|
2033
|
-
return isPlainObject(
|
|
2032
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2033
|
+
return isPlainObject(state.runtime) && Object.keys(state.runtime || {}).length > 0;
|
|
2034
2034
|
},
|
|
2035
2035
|
rememberState(source = {}) {
|
|
2036
|
-
const
|
|
2037
|
-
rememberRuntimeState(
|
|
2036
|
+
const state = normalizeRuntimeState(source);
|
|
2037
|
+
rememberRuntimeState(state);
|
|
2038
2038
|
return RuntimeEnv.peekRememberedState();
|
|
2039
2039
|
},
|
|
2040
2040
|
peekRememberedState() {
|
|
2041
2041
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
2042
2042
|
},
|
|
2043
2043
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
2044
|
-
const
|
|
2045
|
-
return deepClone(
|
|
2044
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2045
|
+
return deepClone(state.browserProfileCore || {});
|
|
2046
2046
|
},
|
|
2047
2047
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
2048
|
-
const
|
|
2048
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2049
2049
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
2050
2050
|
...core,
|
|
2051
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2051
|
+
device: normalizeKnownDevice(core?.device) || state.device
|
|
2052
2052
|
});
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
if (Object.keys(
|
|
2056
|
-
|
|
2053
|
+
state.browserProfileCore = normalizedCore;
|
|
2054
|
+
state.browserProfile = buildBrowserProfilePayload(normalizedCore, state.browserProfileObserved);
|
|
2055
|
+
if (Object.keys(state.browserProfile).length > 0) {
|
|
2056
|
+
state.runtime.browser_profile = state.browserProfile;
|
|
2057
2057
|
} else {
|
|
2058
|
-
delete
|
|
2058
|
+
delete state.runtime.browser_profile;
|
|
2059
2059
|
}
|
|
2060
|
-
rememberRuntimeState(
|
|
2061
|
-
return
|
|
2060
|
+
rememberRuntimeState(state);
|
|
2061
|
+
return state;
|
|
2062
2062
|
},
|
|
2063
2063
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2064
2064
|
// cookies / localStorage / sessionStorage。
|
|
2065
2065
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2066
2066
|
async applyToPage(page, source = {}, options = {}) {
|
|
2067
2067
|
if (!page) return;
|
|
2068
|
-
let
|
|
2068
|
+
let state = normalizeRuntimeState(source, options?.actor || "");
|
|
2069
2069
|
if (typeof options?.preapply === "function") {
|
|
2070
|
-
|
|
2071
|
-
rememberRuntimeState(
|
|
2070
|
+
state = await options.preapply(state) || state;
|
|
2071
|
+
rememberRuntimeState(state);
|
|
2072
2072
|
}
|
|
2073
2073
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2074
2074
|
configurable: true,
|
|
2075
2075
|
enumerable: false,
|
|
2076
2076
|
writable: true,
|
|
2077
|
-
value:
|
|
2077
|
+
value: state
|
|
2078
2078
|
});
|
|
2079
|
-
const localStorage =
|
|
2080
|
-
const sessionStorage =
|
|
2081
|
-
const cookies = (
|
|
2079
|
+
const localStorage = state.localStorage || {};
|
|
2080
|
+
const sessionStorage = state.sessionStorage || {};
|
|
2081
|
+
const cookies = (state.cookies || []).map((cookie) => {
|
|
2082
2082
|
const normalized = { ...cookie };
|
|
2083
2083
|
if (!normalized.path) {
|
|
2084
2084
|
normalized.path = "/";
|
|
@@ -2116,8 +2116,8 @@ var RuntimeEnv = {
|
|
|
2116
2116
|
},
|
|
2117
2117
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2118
2118
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2119
|
-
const
|
|
2120
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2119
|
+
const state = normalizeRuntimeState(source, options?.actor || "");
|
|
2120
|
+
const baseline = RuntimeEnv.buildEnvPatch(state) || {};
|
|
2121
2121
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2122
2122
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2123
2123
|
}
|
|
@@ -2136,7 +2136,7 @@ var RuntimeEnv = {
|
|
|
2136
2136
|
cookies
|
|
2137
2137
|
},
|
|
2138
2138
|
{
|
|
2139
|
-
browserProfileCore:
|
|
2139
|
+
browserProfileCore: state.browserProfileCore
|
|
2140
2140
|
}
|
|
2141
2141
|
);
|
|
2142
2142
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2150,11 +2150,11 @@ var RuntimeEnv = {
|
|
|
2150
2150
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2151
2151
|
var resolveRuntimeContext = (input) => {
|
|
2152
2152
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2153
|
-
const
|
|
2154
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2153
|
+
const state = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2154
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state) || null;
|
|
2155
2155
|
return {
|
|
2156
|
-
actor:
|
|
2157
|
-
runtime:
|
|
2156
|
+
actor: state.actor,
|
|
2157
|
+
runtime: state.runtime,
|
|
2158
2158
|
envPatch
|
|
2159
2159
|
};
|
|
2160
2160
|
};
|
|
@@ -2513,82 +2513,8 @@ var Utils = {
|
|
|
2513
2513
|
}
|
|
2514
2514
|
};
|
|
2515
2515
|
|
|
2516
|
-
// src/
|
|
2517
|
-
var
|
|
2518
|
-
mode: Mode.Default
|
|
2519
|
-
};
|
|
2520
|
-
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2521
|
-
var ToolkitContext = {
|
|
2522
|
-
get mode() {
|
|
2523
|
-
return state.mode;
|
|
2524
|
-
},
|
|
2525
|
-
setMode(mode = Mode.Default) {
|
|
2526
|
-
state.mode = normalizeMode(mode, Mode.Default);
|
|
2527
|
-
return state.mode;
|
|
2528
|
-
}
|
|
2529
|
-
};
|
|
2530
|
-
var getToolkitMode = () => state.mode;
|
|
2531
|
-
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2532
|
-
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2533
|
-
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2534
|
-
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2535
|
-
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2536
|
-
return {
|
|
2537
|
-
mode: normalizedMode,
|
|
2538
|
-
strategy
|
|
2539
|
-
};
|
|
2540
|
-
};
|
|
2541
|
-
|
|
2542
|
-
// src/internals/reflect.js
|
|
2543
|
-
var normalizeStrategies2 = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2544
|
-
var collectFunctionNames = (strategies = []) => {
|
|
2545
|
-
const names = /* @__PURE__ */ new Set();
|
|
2546
|
-
for (const strategy of strategies) {
|
|
2547
|
-
if (!strategy || typeof strategy !== "object") continue;
|
|
2548
|
-
for (const name of Reflect.ownKeys(strategy)) {
|
|
2549
|
-
if (typeof name === "string" && typeof strategy[name] === "function") {
|
|
2550
|
-
names.add(name);
|
|
2551
|
-
}
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
return names;
|
|
2555
|
-
};
|
|
2556
|
-
var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
2557
|
-
enumerable: true,
|
|
2558
|
-
configurable: true,
|
|
2559
|
-
writable: true,
|
|
2560
|
-
value: (...args) => {
|
|
2561
|
-
const { mode, strategy } = resolveTarget(args);
|
|
2562
|
-
const method = strategy?.[name];
|
|
2563
|
-
if (typeof method !== "function") {
|
|
2564
|
-
throw new Error(`${namespace}.${name} is not available in ${mode} mode`);
|
|
2565
|
-
}
|
|
2566
|
-
return method.apply(strategy, args);
|
|
2567
|
-
}
|
|
2568
|
-
});
|
|
2569
|
-
var withModeReflect = (namespace, strategies = {}) => {
|
|
2570
|
-
const normalizedStrategies = normalizeStrategies2(strategies);
|
|
2571
|
-
const baseStrategy = normalizedStrategies.default ?? Object.values(normalizedStrategies).find(Boolean);
|
|
2572
|
-
const names = collectFunctionNames([baseStrategy]);
|
|
2573
|
-
const descriptors = {};
|
|
2574
|
-
for (const name of names) {
|
|
2575
|
-
descriptors[name] = methodDescriptor(namespace, name, () => resolveModeStrategy(normalizedStrategies));
|
|
2576
|
-
}
|
|
2577
|
-
return Object.defineProperties({}, descriptors);
|
|
2578
|
-
};
|
|
2579
|
-
var withPageReflect = (namespace, resolveStrategy, strategies = []) => {
|
|
2580
|
-
const names = collectFunctionNames(strategies);
|
|
2581
|
-
const descriptors = {};
|
|
2582
|
-
for (const name of names) {
|
|
2583
|
-
descriptors[name] = methodDescriptor(namespace, name, ([page]) => ({
|
|
2584
|
-
mode: "page",
|
|
2585
|
-
strategy: resolveStrategy(page)
|
|
2586
|
-
}));
|
|
2587
|
-
}
|
|
2588
|
-
return Object.defineProperties({}, descriptors);
|
|
2589
|
-
};
|
|
2590
|
-
|
|
2591
|
-
// src/internals/anti-cheat/default.js
|
|
2516
|
+
// src/anti-cheat.js
|
|
2517
|
+
var logger5 = createInternalLogger("AntiCheat");
|
|
2592
2518
|
var BASE_CONFIG = Object.freeze({
|
|
2593
2519
|
locale: "zh-CN",
|
|
2594
2520
|
acceptLanguage: "zh-CN,zh;q=0.9",
|
|
@@ -2623,7 +2549,7 @@ function buildFingerprintOptions({ locale = BASE_CONFIG.locale, browserMajorVers
|
|
|
2623
2549
|
}
|
|
2624
2550
|
return options;
|
|
2625
2551
|
}
|
|
2626
|
-
var
|
|
2552
|
+
var AntiCheat = {
|
|
2627
2553
|
/**
|
|
2628
2554
|
* 获取统一的基础配置
|
|
2629
2555
|
*/
|
|
@@ -2660,47 +2586,6 @@ var DefaultAntiCheat = {
|
|
|
2660
2586
|
}
|
|
2661
2587
|
};
|
|
2662
2588
|
|
|
2663
|
-
// src/internals/anti-cheat/cloak.js
|
|
2664
|
-
var CLOAK_BASE_CONFIG = Object.freeze({
|
|
2665
|
-
locale: "",
|
|
2666
|
-
acceptLanguage: "",
|
|
2667
|
-
timezoneId: "",
|
|
2668
|
-
timezoneOffset: null,
|
|
2669
|
-
geolocation: null
|
|
2670
|
-
});
|
|
2671
|
-
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2672
|
-
var CloakAntiCheat = {
|
|
2673
|
-
/**
|
|
2674
|
-
* Cloak 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2675
|
-
*/
|
|
2676
|
-
getBaseConfig() {
|
|
2677
|
-
return { ...CLOAK_BASE_CONFIG };
|
|
2678
|
-
},
|
|
2679
|
-
getFingerprintGeneratorOptions() {
|
|
2680
|
-
return {};
|
|
2681
|
-
},
|
|
2682
|
-
getLaunchArgs() {
|
|
2683
|
-
return [];
|
|
2684
|
-
},
|
|
2685
|
-
getTlsFingerprintOptions() {
|
|
2686
|
-
return {};
|
|
2687
|
-
},
|
|
2688
|
-
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2689
|
-
const normalizedHeaders = normalizeHeaders(headers);
|
|
2690
|
-
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2691
|
-
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2692
|
-
}
|
|
2693
|
-
return normalizedHeaders;
|
|
2694
|
-
}
|
|
2695
|
-
};
|
|
2696
|
-
|
|
2697
|
-
// src/anti-cheat.js
|
|
2698
|
-
var antiCheatStrategies = {
|
|
2699
|
-
[Mode.Default]: DefaultAntiCheat,
|
|
2700
|
-
[Mode.Cloak]: CloakAntiCheat
|
|
2701
|
-
};
|
|
2702
|
-
var AntiCheat = withModeReflect("AntiCheat", antiCheatStrategies);
|
|
2703
|
-
|
|
2704
2589
|
// src/device-input.js
|
|
2705
2590
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2706
2591
|
var assertPage = (page, method) => {
|
|
@@ -3100,12 +2985,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
3100
2985
|
}
|
|
3101
2986
|
return resolved;
|
|
3102
2987
|
};
|
|
3103
|
-
var attachRuntimeState = (page,
|
|
2988
|
+
var attachRuntimeState = (page, state) => {
|
|
3104
2989
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
3105
2990
|
configurable: true,
|
|
3106
2991
|
enumerable: false,
|
|
3107
2992
|
writable: true,
|
|
3108
|
-
value:
|
|
2993
|
+
value: state
|
|
3109
2994
|
});
|
|
3110
2995
|
};
|
|
3111
2996
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -3251,13 +3136,10 @@ var DeviceView = {
|
|
|
3251
3136
|
}
|
|
3252
3137
|
};
|
|
3253
3138
|
|
|
3254
|
-
// src/internals/humanize/index.js
|
|
3255
|
-
var import_delay4 = __toESM(require("delay"), 1);
|
|
3256
|
-
|
|
3257
3139
|
// src/internals/humanize/desktop.js
|
|
3258
3140
|
var import_delay2 = __toESM(require("delay"), 1);
|
|
3259
3141
|
var import_ghost_cursor_playwright = require("ghost-cursor-playwright");
|
|
3260
|
-
var
|
|
3142
|
+
var logger6 = createInternalLogger("Humanize");
|
|
3261
3143
|
var $CursorWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3262
3144
|
function $GetCursor(page) {
|
|
3263
3145
|
const cursor = $CursorWeakMap.get(page);
|
|
@@ -3285,13 +3167,13 @@ var Humanize = {
|
|
|
3285
3167
|
*/
|
|
3286
3168
|
async initializeCursor(page) {
|
|
3287
3169
|
if ($CursorWeakMap.has(page)) {
|
|
3288
|
-
|
|
3170
|
+
logger6.debug("initializeCursor: cursor already exists, skipping");
|
|
3289
3171
|
return;
|
|
3290
3172
|
}
|
|
3291
|
-
|
|
3173
|
+
logger6.start("initializeCursor", "creating cursor");
|
|
3292
3174
|
const cursor = await (0, import_ghost_cursor_playwright.createCursor)(page);
|
|
3293
3175
|
$CursorWeakMap.set(page, cursor);
|
|
3294
|
-
|
|
3176
|
+
logger6.success("initializeCursor", "cursor initialized");
|
|
3295
3177
|
},
|
|
3296
3178
|
/**
|
|
3297
3179
|
* 人类化鼠标移动 - 使用 ghost-cursor 移动到指定位置或元素
|
|
@@ -3301,17 +3183,17 @@ var Humanize = {
|
|
|
3301
3183
|
*/
|
|
3302
3184
|
async humanMove(page, target) {
|
|
3303
3185
|
const cursor = $GetCursor(page);
|
|
3304
|
-
|
|
3186
|
+
logger6.start("humanMove", `target=${typeof target === "string" ? target : "element/coords"}`);
|
|
3305
3187
|
try {
|
|
3306
3188
|
if (typeof target === "string") {
|
|
3307
3189
|
const element = await page.$(target);
|
|
3308
3190
|
if (!element) {
|
|
3309
|
-
|
|
3191
|
+
logger6.warn(`humanMove: \u5143\u7D20\u4E0D\u5B58\u5728 ${target}`);
|
|
3310
3192
|
return false;
|
|
3311
3193
|
}
|
|
3312
3194
|
const box = await element.boundingBox();
|
|
3313
3195
|
if (!box) {
|
|
3314
|
-
|
|
3196
|
+
logger6.warn(`humanMove: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E ${target}`);
|
|
3315
3197
|
return false;
|
|
3316
3198
|
}
|
|
3317
3199
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.2;
|
|
@@ -3327,10 +3209,10 @@ var Humanize = {
|
|
|
3327
3209
|
await cursor.actions.move({ x, y });
|
|
3328
3210
|
}
|
|
3329
3211
|
}
|
|
3330
|
-
|
|
3212
|
+
logger6.success("humanMove");
|
|
3331
3213
|
return true;
|
|
3332
3214
|
} catch (error) {
|
|
3333
|
-
|
|
3215
|
+
logger6.fail("humanMove", error);
|
|
3334
3216
|
throw error;
|
|
3335
3217
|
}
|
|
3336
3218
|
},
|
|
@@ -3354,12 +3236,12 @@ var Humanize = {
|
|
|
3354
3236
|
maxDurationMs = maxSteps * 220 + 800
|
|
3355
3237
|
} = options;
|
|
3356
3238
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
3357
|
-
|
|
3239
|
+
logger6.start("humanScroll", `target=${targetDesc}`);
|
|
3358
3240
|
let element;
|
|
3359
3241
|
if (typeof target === "string") {
|
|
3360
3242
|
element = await page.$(target);
|
|
3361
3243
|
if (!element) {
|
|
3362
|
-
|
|
3244
|
+
logger6.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${target}`);
|
|
3363
3245
|
return { element: null, didScroll: false };
|
|
3364
3246
|
}
|
|
3365
3247
|
} else {
|
|
@@ -3434,26 +3316,26 @@ var Humanize = {
|
|
|
3434
3316
|
try {
|
|
3435
3317
|
for (let i = 0; i < maxSteps; i++) {
|
|
3436
3318
|
if (Date.now() - startTime > maxDurationMs) {
|
|
3437
|
-
|
|
3319
|
+
logger6.warn(`humanScroll | \u8D85\u65F6\u4FDD\u62A4\u89E6\u53D1 (${maxDurationMs}ms)`);
|
|
3438
3320
|
return { element, didScroll };
|
|
3439
3321
|
}
|
|
3440
3322
|
const status = await checkVisibility();
|
|
3441
3323
|
if (status.code === "VISIBLE") {
|
|
3442
3324
|
if (status.isFixed) {
|
|
3443
|
-
|
|
3325
|
+
logger6.info("humanScroll | fixed \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3444
3326
|
} else {
|
|
3445
|
-
|
|
3327
|
+
logger6.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
3446
3328
|
}
|
|
3447
|
-
|
|
3329
|
+
logger6.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
3448
3330
|
return { element, didScroll };
|
|
3449
3331
|
}
|
|
3450
|
-
|
|
3332
|
+
logger6.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason} ${status.direction ? `(${status.direction})` : ""}`);
|
|
3451
3333
|
if (status.code === "OBSTRUCTED" && status.obstruction) {
|
|
3452
|
-
|
|
3334
|
+
logger6.debug(`humanScroll | \u88AB\u4EE5\u4E0B\u5143\u7D20\u906E\u6321 <${status.obstruction.tag} id="${status.obstruction.id}">`);
|
|
3453
3335
|
}
|
|
3454
3336
|
const scrollRect = await getScrollableRect2();
|
|
3455
3337
|
if (!scrollRect && status.isFixed) {
|
|
3456
|
-
|
|
3338
|
+
logger6.warn("humanScroll | fixed \u5BB9\u5668\u5185\u4E14\u65E0\u53EF\u6EDA\u52A8\u7956\u5148\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3457
3339
|
return { element, didScroll };
|
|
3458
3340
|
}
|
|
3459
3341
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
@@ -3489,10 +3371,10 @@ var Humanize = {
|
|
|
3489
3371
|
didScroll = true;
|
|
3490
3372
|
await (0, import_delay2.default)(this.jitterMs(20 + Math.random() * 40, 0.2));
|
|
3491
3373
|
}
|
|
3492
|
-
|
|
3374
|
+
logger6.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
3493
3375
|
return { element, didScroll };
|
|
3494
3376
|
} catch (error) {
|
|
3495
|
-
|
|
3377
|
+
logger6.fail("humanScroll", error);
|
|
3496
3378
|
throw error;
|
|
3497
3379
|
}
|
|
3498
3380
|
},
|
|
@@ -3510,7 +3392,7 @@ var Humanize = {
|
|
|
3510
3392
|
const cursor = $GetCursor(page);
|
|
3511
3393
|
const { reactionDelay = 250, throwOnMissing = true, scrollIfNeeded = true, restore = false } = options;
|
|
3512
3394
|
const targetDesc = target == null ? "Current Position" : typeof target === "string" ? target : "ElementHandle";
|
|
3513
|
-
|
|
3395
|
+
logger6.start("humanClick", `target=${targetDesc}`);
|
|
3514
3396
|
const restoreOnce = async () => {
|
|
3515
3397
|
if (restoreOnce.restored) return;
|
|
3516
3398
|
restoreOnce.restored = true;
|
|
@@ -3519,14 +3401,14 @@ var Humanize = {
|
|
|
3519
3401
|
await (0, import_delay2.default)(this.jitterMs(1e3));
|
|
3520
3402
|
await restoreOnce.do();
|
|
3521
3403
|
} catch (restoreError) {
|
|
3522
|
-
|
|
3404
|
+
logger6.warn(`humanClick: \u6062\u590D\u6EDA\u52A8\u4F4D\u7F6E\u5931\u8D25: ${restoreError.message}`);
|
|
3523
3405
|
}
|
|
3524
3406
|
};
|
|
3525
3407
|
try {
|
|
3526
3408
|
if (target == null) {
|
|
3527
3409
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3528
3410
|
await cursor.actions.click();
|
|
3529
|
-
|
|
3411
|
+
logger6.success("humanClick", "Clicked current position");
|
|
3530
3412
|
return true;
|
|
3531
3413
|
}
|
|
3532
3414
|
let element;
|
|
@@ -3536,7 +3418,7 @@ var Humanize = {
|
|
|
3536
3418
|
if (throwOnMissing) {
|
|
3537
3419
|
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${target}`);
|
|
3538
3420
|
}
|
|
3539
|
-
|
|
3421
|
+
logger6.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${target}`);
|
|
3540
3422
|
return false;
|
|
3541
3423
|
}
|
|
3542
3424
|
} else {
|
|
@@ -3552,7 +3434,7 @@ var Humanize = {
|
|
|
3552
3434
|
if (throwOnMissing) {
|
|
3553
3435
|
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
3554
3436
|
}
|
|
3555
|
-
|
|
3437
|
+
logger6.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
3556
3438
|
return false;
|
|
3557
3439
|
}
|
|
3558
3440
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.3;
|
|
@@ -3561,11 +3443,11 @@ var Humanize = {
|
|
|
3561
3443
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3562
3444
|
await cursor.actions.click();
|
|
3563
3445
|
await restoreOnce();
|
|
3564
|
-
|
|
3446
|
+
logger6.success("humanClick");
|
|
3565
3447
|
return true;
|
|
3566
3448
|
} catch (error) {
|
|
3567
3449
|
await restoreOnce();
|
|
3568
|
-
|
|
3450
|
+
logger6.fail("humanClick", error);
|
|
3569
3451
|
throw error;
|
|
3570
3452
|
}
|
|
3571
3453
|
},
|
|
@@ -3576,9 +3458,9 @@ var Humanize = {
|
|
|
3576
3458
|
*/
|
|
3577
3459
|
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
3578
3460
|
const ms = this.jitterMs(baseMs, jitterPercent);
|
|
3579
|
-
|
|
3461
|
+
logger6.start("randomSleep", `base=${baseMs}, actual=${ms}ms`);
|
|
3580
3462
|
await (0, import_delay2.default)(ms);
|
|
3581
|
-
|
|
3463
|
+
logger6.success("randomSleep");
|
|
3582
3464
|
},
|
|
3583
3465
|
/**
|
|
3584
3466
|
* 模拟人类"注视"或"阅读"行为:鼠标在页面上随机微动
|
|
@@ -3588,7 +3470,7 @@ var Humanize = {
|
|
|
3588
3470
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
3589
3471
|
const cursor = $GetCursor(page);
|
|
3590
3472
|
const durationMs = this.jitterMs(baseDurationMs, 0.4);
|
|
3591
|
-
|
|
3473
|
+
logger6.start("simulateGaze", `duration=${durationMs}ms`);
|
|
3592
3474
|
const startTime = Date.now();
|
|
3593
3475
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3594
3476
|
while (Date.now() - startTime < durationMs) {
|
|
@@ -3597,7 +3479,7 @@ var Humanize = {
|
|
|
3597
3479
|
await cursor.actions.move({ x, y });
|
|
3598
3480
|
await (0, import_delay2.default)(this.jitterMs(600, 0.5));
|
|
3599
3481
|
}
|
|
3600
|
-
|
|
3482
|
+
logger6.success("simulateGaze");
|
|
3601
3483
|
},
|
|
3602
3484
|
/**
|
|
3603
3485
|
* 人类化输入 - 带节奏变化(快-慢-停顿-偶尔加速)
|
|
@@ -3610,7 +3492,7 @@ var Humanize = {
|
|
|
3610
3492
|
* @param {number} [options.pauseBase=800] - 停顿时长基础值 (ms),实际 ±50% 抖动
|
|
3611
3493
|
*/
|
|
3612
3494
|
async humanType(page, selector, text, options = {}) {
|
|
3613
|
-
|
|
3495
|
+
logger6.start("humanType", `selector=${selector}, textLen=${text.length}`);
|
|
3614
3496
|
const {
|
|
3615
3497
|
baseDelay = 180,
|
|
3616
3498
|
pauseProbability = 0.08,
|
|
@@ -3634,13 +3516,13 @@ var Humanize = {
|
|
|
3634
3516
|
await (0, import_delay2.default)(charDelay);
|
|
3635
3517
|
if (Math.random() < pauseProbability && i < text.length - 1) {
|
|
3636
3518
|
const pauseTime = this.jitterMs(pauseBase, 0.5);
|
|
3637
|
-
|
|
3519
|
+
logger6.debug(`\u505C\u987F ${pauseTime}ms...`);
|
|
3638
3520
|
await (0, import_delay2.default)(pauseTime);
|
|
3639
3521
|
}
|
|
3640
3522
|
}
|
|
3641
|
-
|
|
3523
|
+
logger6.success("humanType");
|
|
3642
3524
|
} catch (error) {
|
|
3643
|
-
|
|
3525
|
+
logger6.fail("humanType", error);
|
|
3644
3526
|
throw error;
|
|
3645
3527
|
}
|
|
3646
3528
|
},
|
|
@@ -3664,7 +3546,7 @@ var Humanize = {
|
|
|
3664
3546
|
keyboardOptions = {}
|
|
3665
3547
|
} = pressOptions || {};
|
|
3666
3548
|
const targetDesc = hasTarget ? typeof targetOrKey === "string" ? targetOrKey : "ElementHandle" : "current focus";
|
|
3667
|
-
|
|
3549
|
+
logger6.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
3668
3550
|
try {
|
|
3669
3551
|
if (hasTarget) {
|
|
3670
3552
|
await this.humanClick(page, targetOrKey, { reactionDelay: focusDelay, scrollIfNeeded, throwOnMissing });
|
|
@@ -3674,10 +3556,10 @@ var Humanize = {
|
|
|
3674
3556
|
...keyboardOptions,
|
|
3675
3557
|
delay: this.jitterMs(holdDelay, 0.5)
|
|
3676
3558
|
});
|
|
3677
|
-
|
|
3559
|
+
logger6.success("humanPress");
|
|
3678
3560
|
return true;
|
|
3679
3561
|
} catch (error) {
|
|
3680
|
-
|
|
3562
|
+
logger6.fail("humanPress", error);
|
|
3681
3563
|
throw error;
|
|
3682
3564
|
}
|
|
3683
3565
|
},
|
|
@@ -3687,22 +3569,22 @@ var Humanize = {
|
|
|
3687
3569
|
* @param {string} selector - 输入框选择器
|
|
3688
3570
|
*/
|
|
3689
3571
|
async humanClear(page, selector) {
|
|
3690
|
-
|
|
3572
|
+
logger6.start("humanClear", `selector=${selector}`);
|
|
3691
3573
|
try {
|
|
3692
3574
|
const locator = page.locator(selector);
|
|
3693
3575
|
await locator.click();
|
|
3694
3576
|
await (0, import_delay2.default)(this.jitterMs(200, 0.4));
|
|
3695
3577
|
const currentValue = await locator.inputValue();
|
|
3696
3578
|
if (!currentValue || currentValue.length === 0) {
|
|
3697
|
-
|
|
3579
|
+
logger6.success("humanClear", "already empty");
|
|
3698
3580
|
return;
|
|
3699
3581
|
}
|
|
3700
3582
|
await page.keyboard.press("Meta+A");
|
|
3701
3583
|
await (0, import_delay2.default)(this.jitterMs(100, 0.4));
|
|
3702
3584
|
await page.keyboard.press("Backspace");
|
|
3703
|
-
|
|
3585
|
+
logger6.success("humanClear");
|
|
3704
3586
|
} catch (error) {
|
|
3705
|
-
|
|
3587
|
+
logger6.fail("humanClear", error);
|
|
3706
3588
|
throw error;
|
|
3707
3589
|
}
|
|
3708
3590
|
},
|
|
@@ -3714,7 +3596,7 @@ var Humanize = {
|
|
|
3714
3596
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
3715
3597
|
const cursor = $GetCursor(page);
|
|
3716
3598
|
const durationMs = this.jitterMs(baseDuration, 0.4);
|
|
3717
|
-
|
|
3599
|
+
logger6.start("warmUpBrowsing", `duration=${durationMs}ms`);
|
|
3718
3600
|
const startTime = Date.now();
|
|
3719
3601
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3720
3602
|
try {
|
|
@@ -3733,9 +3615,9 @@ var Humanize = {
|
|
|
3733
3615
|
await (0, import_delay2.default)(this.jitterMs(800, 0.5));
|
|
3734
3616
|
}
|
|
3735
3617
|
}
|
|
3736
|
-
|
|
3618
|
+
logger6.success("warmUpBrowsing");
|
|
3737
3619
|
} catch (error) {
|
|
3738
|
-
|
|
3620
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3739
3621
|
throw error;
|
|
3740
3622
|
}
|
|
3741
3623
|
},
|
|
@@ -3749,7 +3631,7 @@ var Humanize = {
|
|
|
3749
3631
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3750
3632
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3751
3633
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
3752
|
-
|
|
3634
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
3753
3635
|
const sign = direction === "down" ? 1 : -1;
|
|
3754
3636
|
const stepDistance = actualDistance / steps;
|
|
3755
3637
|
try {
|
|
@@ -3761,9 +3643,9 @@ var Humanize = {
|
|
|
3761
3643
|
const baseDelay = 60 + i * 25;
|
|
3762
3644
|
await (0, import_delay2.default)(this.jitterMs(baseDelay, 0.3));
|
|
3763
3645
|
}
|
|
3764
|
-
|
|
3646
|
+
logger6.success("naturalScroll");
|
|
3765
3647
|
} catch (error) {
|
|
3766
|
-
|
|
3648
|
+
logger6.fail("naturalScroll", error);
|
|
3767
3649
|
throw error;
|
|
3768
3650
|
}
|
|
3769
3651
|
}
|
|
@@ -3792,7 +3674,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
3792
3674
|
var waitJitter = (base, jitterPercent = 0.3) => (0, import_delay3.default)(jitterMs(base, jitterPercent));
|
|
3793
3675
|
|
|
3794
3676
|
// src/internals/humanize/mobile.js
|
|
3795
|
-
var
|
|
3677
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
3796
3678
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
3797
3679
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
3798
3680
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4162,7 +4044,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4162
4044
|
return;
|
|
4163
4045
|
}
|
|
4164
4046
|
await page.evaluate(
|
|
4165
|
-
(
|
|
4047
|
+
(state) => window.scrollTo(state.x, state.y),
|
|
4166
4048
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4167
4049
|
).catch(() => {
|
|
4168
4050
|
});
|
|
@@ -4249,7 +4131,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4249
4131
|
}
|
|
4250
4132
|
return true;
|
|
4251
4133
|
} catch (error) {
|
|
4252
|
-
|
|
4134
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4253
4135
|
try {
|
|
4254
4136
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4255
4137
|
await waitJitter(120, 0.35);
|
|
@@ -4283,7 +4165,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4283
4165
|
);
|
|
4284
4166
|
return { method: "touchscreen" };
|
|
4285
4167
|
} catch (error) {
|
|
4286
|
-
|
|
4168
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4287
4169
|
if (!allowMouseFallback) throw error;
|
|
4288
4170
|
}
|
|
4289
4171
|
}
|
|
@@ -4299,10 +4181,10 @@ var MobileHumanize = {
|
|
|
4299
4181
|
async initializeCursor(page) {
|
|
4300
4182
|
if (initializedPages.has(page)) return;
|
|
4301
4183
|
initializedPages.add(page);
|
|
4302
|
-
|
|
4184
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4303
4185
|
},
|
|
4304
4186
|
async humanMove(page, target) {
|
|
4305
|
-
|
|
4187
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4306
4188
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4307
4189
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4308
4190
|
if (!element) {
|
|
@@ -4321,10 +4203,10 @@ var MobileHumanize = {
|
|
|
4321
4203
|
throwOnMissing = false
|
|
4322
4204
|
} = options;
|
|
4323
4205
|
const targetDesc = describeTarget(target);
|
|
4324
|
-
|
|
4206
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4325
4207
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4326
4208
|
if (!element) {
|
|
4327
|
-
|
|
4209
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4328
4210
|
return { element: null, didScroll: false, restore: null };
|
|
4329
4211
|
}
|
|
4330
4212
|
const startTime = Date.now();
|
|
@@ -4333,42 +4215,42 @@ var MobileHumanize = {
|
|
|
4333
4215
|
const status = await checkElementVisibility(element);
|
|
4334
4216
|
if (status.code === "VISIBLE") {
|
|
4335
4217
|
if (status.isFixed) {
|
|
4336
|
-
|
|
4218
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4337
4219
|
} else {
|
|
4338
|
-
|
|
4220
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4339
4221
|
}
|
|
4340
|
-
|
|
4222
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4341
4223
|
return { element, didScroll, restore: null };
|
|
4342
4224
|
}
|
|
4343
4225
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4344
|
-
|
|
4226
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4345
4227
|
return { element, didScroll, restore: null };
|
|
4346
4228
|
}
|
|
4347
4229
|
const scrollRect = await getScrollableRect(element);
|
|
4348
4230
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4349
|
-
|
|
4231
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u4E0D\u5728\u89C6\u53E3\u5185\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (direction=${status.direction || "unknown"})`);
|
|
4350
4232
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4351
4233
|
}
|
|
4352
4234
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4353
|
-
|
|
4235
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4354
4236
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4355
4237
|
}
|
|
4356
4238
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4357
4239
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4358
4240
|
if (moved.moved) {
|
|
4359
|
-
|
|
4241
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4360
4242
|
await waitJitter(90, 0.3);
|
|
4361
4243
|
didScroll = true;
|
|
4362
4244
|
continue;
|
|
4363
4245
|
}
|
|
4364
4246
|
}
|
|
4365
4247
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4366
|
-
|
|
4248
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4367
4249
|
return { element, didScroll, restore: null };
|
|
4368
4250
|
}
|
|
4369
4251
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4370
4252
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4371
|
-
|
|
4253
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4372
4254
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4373
4255
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4374
4256
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4408,8 +4290,8 @@ var MobileHumanize = {
|
|
|
4408
4290
|
if (scrollRect && beforeWindowState) {
|
|
4409
4291
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4410
4292
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4411
|
-
await page.evaluate((
|
|
4412
|
-
|
|
4293
|
+
await page.evaluate((state) => window.scrollTo(state.x, state.y), beforeWindowState);
|
|
4294
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4413
4295
|
}
|
|
4414
4296
|
}
|
|
4415
4297
|
let afterElementSnapshot = null;
|
|
@@ -4423,7 +4305,7 @@ var MobileHumanize = {
|
|
|
4423
4305
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4424
4306
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4425
4307
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4426
|
-
|
|
4308
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u9875\u9762\u6EDA\u52A8\u79FB\u52A8\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4427
4309
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4428
4310
|
}
|
|
4429
4311
|
}
|
|
@@ -4455,12 +4337,12 @@ var MobileHumanize = {
|
|
|
4455
4337
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4456
4338
|
if (!moved) {
|
|
4457
4339
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4458
|
-
|
|
4340
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u65E0\u6548\uFF0C\u76F4\u63A5\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4459
4341
|
} else if (beforeState.kind === afterState.kind && Math.abs(expectedDelta) > 24 && Math.sign(topDelta || expectedDelta) === Math.sign(expectedDelta) && Math.abs(topDelta) < Math.min(Math.abs(expectedDelta) * 0.45, 96)) {
|
|
4460
4342
|
const residualDelta = expectedDelta - topDelta;
|
|
4461
4343
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4462
4344
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4463
|
-
|
|
4345
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u8DDD\u79BB\u4E0D\u8DB3\uFF0C\u8865\u507F\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4464
4346
|
}
|
|
4465
4347
|
}
|
|
4466
4348
|
}
|
|
@@ -4468,7 +4350,7 @@ var MobileHumanize = {
|
|
|
4468
4350
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4469
4351
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4470
4352
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4471
|
-
|
|
4353
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u6EDA\u52A8\u5BB9\u5668\u79FB\u52A8\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4472
4354
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4473
4355
|
}
|
|
4474
4356
|
}
|
|
@@ -4479,14 +4361,14 @@ var MobileHumanize = {
|
|
|
4479
4361
|
await waitJitter(80, 0.3);
|
|
4480
4362
|
const finalStatus = await checkElementVisibility(element);
|
|
4481
4363
|
if (finalStatus.code === "VISIBLE") {
|
|
4482
|
-
|
|
4483
|
-
|
|
4364
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4365
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4484
4366
|
return { element, didScroll: true, restore: null };
|
|
4485
4367
|
}
|
|
4486
4368
|
} catch (fallbackError) {
|
|
4487
|
-
|
|
4369
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4488
4370
|
}
|
|
4489
|
-
|
|
4371
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4490
4372
|
return { element, didScroll, restore: null };
|
|
4491
4373
|
},
|
|
4492
4374
|
async humanClick(page, target, options = {}) {
|
|
@@ -4501,7 +4383,7 @@ var MobileHumanize = {
|
|
|
4501
4383
|
fallbackDomClickOnTapError = true
|
|
4502
4384
|
} = options;
|
|
4503
4385
|
const targetDesc = describeTarget(target);
|
|
4504
|
-
|
|
4386
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4505
4387
|
try {
|
|
4506
4388
|
if (target == null) {
|
|
4507
4389
|
const viewport = resolveViewport(page);
|
|
@@ -4513,12 +4395,12 @@ var MobileHumanize = {
|
|
|
4513
4395
|
timeoutMs: tapTimeoutMs,
|
|
4514
4396
|
mouseFallbackTimeoutMs
|
|
4515
4397
|
});
|
|
4516
|
-
|
|
4398
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4517
4399
|
return true;
|
|
4518
4400
|
}
|
|
4519
4401
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4520
4402
|
if (!element) {
|
|
4521
|
-
|
|
4403
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4522
4404
|
return false;
|
|
4523
4405
|
}
|
|
4524
4406
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4542,19 +4424,19 @@ var MobileHumanize = {
|
|
|
4542
4424
|
).catch(() => null);
|
|
4543
4425
|
}
|
|
4544
4426
|
if (fallback?.activated) {
|
|
4545
|
-
|
|
4427
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4546
4428
|
return true;
|
|
4547
4429
|
}
|
|
4548
4430
|
}
|
|
4549
4431
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4550
4432
|
if (throwOnMissing) throw new Error(message);
|
|
4551
|
-
|
|
4433
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4552
4434
|
return false;
|
|
4553
4435
|
}
|
|
4554
4436
|
const box = await element.boundingBox();
|
|
4555
4437
|
if (!box) {
|
|
4556
4438
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4557
|
-
|
|
4439
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4558
4440
|
return false;
|
|
4559
4441
|
}
|
|
4560
4442
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4575,13 +4457,13 @@ var MobileHumanize = {
|
|
|
4575
4457
|
"activation fallback"
|
|
4576
4458
|
).catch(() => null);
|
|
4577
4459
|
if (!fallback?.activated) throw tapError;
|
|
4578
|
-
|
|
4460
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4579
4461
|
}
|
|
4580
4462
|
await waitJitter(120, 0.35);
|
|
4581
|
-
|
|
4463
|
+
logger7.success("humanClick");
|
|
4582
4464
|
return true;
|
|
4583
4465
|
} catch (error) {
|
|
4584
|
-
|
|
4466
|
+
logger7.fail("humanClick", error);
|
|
4585
4467
|
throw error;
|
|
4586
4468
|
}
|
|
4587
4469
|
},
|
|
@@ -4634,7 +4516,7 @@ var MobileHumanize = {
|
|
|
4634
4516
|
keyboardOptions = {}
|
|
4635
4517
|
} = pressOptions || {};
|
|
4636
4518
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4637
|
-
|
|
4519
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4638
4520
|
try {
|
|
4639
4521
|
if (hasTarget) {
|
|
4640
4522
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4648,10 +4530,10 @@ var MobileHumanize = {
|
|
|
4648
4530
|
...keyboardOptions,
|
|
4649
4531
|
delay: jitterMs(holdDelay, 0.5)
|
|
4650
4532
|
});
|
|
4651
|
-
|
|
4533
|
+
logger7.success("humanPress");
|
|
4652
4534
|
return true;
|
|
4653
4535
|
} catch (error) {
|
|
4654
|
-
|
|
4536
|
+
logger7.fail("humanPress", error);
|
|
4655
4537
|
throw error;
|
|
4656
4538
|
}
|
|
4657
4539
|
},
|
|
@@ -4718,92 +4600,62 @@ var MobileHumanize = {
|
|
|
4718
4600
|
}
|
|
4719
4601
|
};
|
|
4720
4602
|
|
|
4721
|
-
// src/
|
|
4603
|
+
// src/humanize.js
|
|
4722
4604
|
var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4723
4605
|
var resolveDelegate = (page) => {
|
|
4724
4606
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
4725
4607
|
};
|
|
4726
|
-
var
|
|
4727
|
-
|
|
4728
|
-
|
|
4729
|
-
[Humanize, MobileHumanize]
|
|
4730
|
-
);
|
|
4731
|
-
|
|
4732
|
-
// src/internals/humanize/cloak.js
|
|
4733
|
-
var FORCE_CLICK = Object.freeze({
|
|
4734
|
-
forceClick: true,
|
|
4735
|
-
clickOptions: { force: true }
|
|
4736
|
-
});
|
|
4737
|
-
var pointOrNull = async (target) => {
|
|
4738
|
-
if (!target || typeof target.boundingBox !== "function") return null;
|
|
4739
|
-
const box = await target.boundingBox().catch(() => null);
|
|
4740
|
-
return box ? { x: box.x + box.width / 2, y: box.y + box.height / 2 } : null;
|
|
4608
|
+
var callDelegate = (method, page, args) => {
|
|
4609
|
+
const delegate = resolveDelegate(page);
|
|
4610
|
+
return delegate[method](page, ...args);
|
|
4741
4611
|
};
|
|
4742
|
-
var
|
|
4743
|
-
|
|
4744
|
-
return
|
|
4612
|
+
var Humanize2 = {
|
|
4613
|
+
jitterMs(base, jitterPercent = 0.3) {
|
|
4614
|
+
return Humanize.jitterMs(base, jitterPercent);
|
|
4745
4615
|
},
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
return point ? await DeviceInput.move(page, point, { forceMouse: true }) : false;
|
|
4616
|
+
initializeCursor(page) {
|
|
4617
|
+
return callDelegate("initializeCursor", page, []);
|
|
4749
4618
|
},
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4753
|
-
await element.scrollIntoViewIfNeeded?.();
|
|
4754
|
-
return { element, didScroll: true, restore: null };
|
|
4619
|
+
humanMove(page, target) {
|
|
4620
|
+
return callDelegate("humanMove", page, [target]);
|
|
4755
4621
|
},
|
|
4756
|
-
|
|
4757
|
-
return
|
|
4622
|
+
humanScroll(page, target, options = {}) {
|
|
4623
|
+
return callDelegate("humanScroll", page, [target, options]);
|
|
4758
4624
|
},
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
return await DeviceInput.keyboardType(page, text);
|
|
4625
|
+
humanClick(page, target, options = {}) {
|
|
4626
|
+
return callDelegate("humanClick", page, [target, options]);
|
|
4762
4627
|
},
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
}
|
|
4628
|
+
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4629
|
+
if (pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function") {
|
|
4630
|
+
const delegate = resolveDelegate(pageOrBaseMs);
|
|
4631
|
+
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4632
|
+
}
|
|
4633
|
+
return Humanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4768
4634
|
},
|
|
4769
|
-
|
|
4770
|
-
return
|
|
4635
|
+
simulateGaze(page, baseDurationMs = 2500) {
|
|
4636
|
+
return callDelegate("simulateGaze", page, [baseDurationMs]);
|
|
4771
4637
|
},
|
|
4772
|
-
|
|
4773
|
-
return
|
|
4638
|
+
humanType(page, selector, text, options = {}) {
|
|
4639
|
+
return callDelegate("humanType", page, [selector, text, options]);
|
|
4774
4640
|
},
|
|
4775
|
-
|
|
4776
|
-
|
|
4641
|
+
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4642
|
+
if (typeof maybeKey === "string") {
|
|
4643
|
+
return callDelegate("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4644
|
+
}
|
|
4645
|
+
return callDelegate("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4777
4646
|
},
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
// src/internals/humanize/index.js
|
|
4785
|
-
var HumanizeCommon = {
|
|
4786
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4787
|
-
return jitterMs(base, jitterPercent);
|
|
4647
|
+
humanClear(page, selector) {
|
|
4648
|
+
return callDelegate("humanClear", page, [selector]);
|
|
4649
|
+
},
|
|
4650
|
+
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4651
|
+
return callDelegate("warmUpBrowsing", page, [baseDuration]);
|
|
4788
4652
|
},
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
const baseMs = hasPage ? maybeBaseMs : pageOrBaseMs;
|
|
4792
|
-
const jitterPercent = hasPage ? maybeJitterPercent : maybeBaseMs;
|
|
4793
|
-
await (0, import_delay4.default)(jitterMs(baseMs, jitterPercent ?? 0.3));
|
|
4653
|
+
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4654
|
+
return callDelegate("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4794
4655
|
}
|
|
4795
4656
|
};
|
|
4796
|
-
var DefaultHumanize = Object.assign({}, DefaultHumanizeDevice, HumanizeCommon);
|
|
4797
|
-
var CloakHumanize = Object.assign({}, CloakHumanizeInput, HumanizeCommon);
|
|
4798
4657
|
|
|
4799
|
-
// src/
|
|
4800
|
-
var humanizeStrategies = {
|
|
4801
|
-
[Mode.Default]: DefaultHumanize,
|
|
4802
|
-
[Mode.Cloak]: CloakHumanize
|
|
4803
|
-
};
|
|
4804
|
-
var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
4805
|
-
|
|
4806
|
-
// src/internals/launch/default.js
|
|
4658
|
+
// src/launch.js
|
|
4807
4659
|
var import_node_child_process = require("node:child_process");
|
|
4808
4660
|
var import_fingerprint_generator = require("fingerprint-generator");
|
|
4809
4661
|
var import_fingerprint_injector = require("fingerprint-injector");
|
|
@@ -4888,107 +4740,9 @@ var ByPass = {
|
|
|
4888
4740
|
resolveRouteByProxy
|
|
4889
4741
|
};
|
|
4890
4742
|
|
|
4891
|
-
// src/
|
|
4892
|
-
var logger7 = createInternalLogger("Launch");
|
|
4893
|
-
var normalizeObject = (value) => {
|
|
4894
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4895
|
-
return {};
|
|
4896
|
-
}
|
|
4897
|
-
return value;
|
|
4898
|
-
};
|
|
4899
|
-
var parseProxyConfiguration = (proxyConfiguration = {}) => {
|
|
4900
|
-
const config = normalizeObject(proxyConfiguration);
|
|
4901
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4902
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4903
|
-
const byPassDomains = enableProxy && proxyUrl ? ByPass.normalizeByPassDomains(config.by_pass_domains) : [];
|
|
4904
|
-
return {
|
|
4905
|
-
byPassDomains,
|
|
4906
|
-
enableProxy,
|
|
4907
|
-
proxyUrl
|
|
4908
|
-
};
|
|
4909
|
-
};
|
|
4910
|
-
var resolveLaunchTraffic = ({
|
|
4911
|
-
proxyConfiguration = {},
|
|
4912
|
-
debugMode = false,
|
|
4913
|
-
useMeter = true
|
|
4914
|
-
} = {}) => {
|
|
4915
|
-
const { byPassDomains, enableProxy, proxyUrl } = parseProxyConfiguration(proxyConfiguration);
|
|
4916
|
-
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4917
|
-
const proxyMeter = useMeter && enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4918
|
-
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4919
|
-
if (launchProxy && byPassDomains.length > 0) {
|
|
4920
|
-
launchProxy.bypass = byPassDomains.join(",");
|
|
4921
|
-
}
|
|
4922
|
-
return {
|
|
4923
|
-
byPassDomains,
|
|
4924
|
-
byPassRules,
|
|
4925
|
-
enableProxy,
|
|
4926
|
-
proxyUrl,
|
|
4927
|
-
launchProxy
|
|
4928
|
-
};
|
|
4929
|
-
};
|
|
4930
|
-
var logLaunchTraffic = ({
|
|
4931
|
-
byPassDomains = [],
|
|
4932
|
-
debugMode = false,
|
|
4933
|
-
enabled = false,
|
|
4934
|
-
enableProxy = false,
|
|
4935
|
-
explicitProxy = false,
|
|
4936
|
-
launchProxy = null,
|
|
4937
|
-
proxyUrl = ""
|
|
4938
|
-
} = {}) => {
|
|
4939
|
-
if (!enabled) return;
|
|
4940
|
-
if (explicitProxy) {
|
|
4941
|
-
logger7.info("[\u4EE3\u7406\u5DF2\u542F\u7528] \u4F7F\u7528\u663E\u5F0F proxy \u914D\u7F6E\uFF0C\u8DF3\u8FC7 toolkit \u672C\u5730\u6D41\u91CF\u89C2\u6D4B");
|
|
4942
|
-
return;
|
|
4943
|
-
}
|
|
4944
|
-
if (launchProxy) {
|
|
4945
|
-
let upstreamLabel = "";
|
|
4946
|
-
try {
|
|
4947
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
4948
|
-
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
4949
|
-
} catch {
|
|
4950
|
-
}
|
|
4951
|
-
logger7.info(
|
|
4952
|
-
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
4953
|
-
);
|
|
4954
|
-
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`);
|
|
4955
|
-
return;
|
|
4956
|
-
}
|
|
4957
|
-
if (enableProxy) {
|
|
4958
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4959
|
-
} else if (proxyUrl) {
|
|
4960
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4961
|
-
}
|
|
4962
|
-
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`);
|
|
4963
|
-
};
|
|
4964
|
-
var createLaunchTrafficHook = ({
|
|
4965
|
-
byPassDomains = [],
|
|
4966
|
-
byPassRules = [],
|
|
4967
|
-
enabled = false,
|
|
4968
|
-
launchProxy = null
|
|
4969
|
-
} = {}) => {
|
|
4970
|
-
const patchedPages = /* @__PURE__ */ new WeakSet();
|
|
4971
|
-
return (page) => {
|
|
4972
|
-
if (!page || typeof page.on !== "function" || patchedPages.has(page)) {
|
|
4973
|
-
return;
|
|
4974
|
-
}
|
|
4975
|
-
patchedPages.add(page);
|
|
4976
|
-
page.on("request", (req) => {
|
|
4977
|
-
const requestUrl = req.url();
|
|
4978
|
-
const resourceType = req.resourceType();
|
|
4979
|
-
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
4980
|
-
if (launchProxy) {
|
|
4981
|
-
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
4982
|
-
}
|
|
4983
|
-
if (!enabled || byPassDomains.length === 0) return;
|
|
4984
|
-
if (!matched || !matched.rule) return;
|
|
4985
|
-
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}`);
|
|
4986
|
-
});
|
|
4987
|
-
};
|
|
4988
|
-
};
|
|
4989
|
-
|
|
4990
|
-
// src/internals/launch/default.js
|
|
4743
|
+
// src/launch.js
|
|
4991
4744
|
var logger8 = createInternalLogger("Launch");
|
|
4745
|
+
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
4992
4746
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4993
4747
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
4994
4748
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -5000,6 +4754,16 @@ var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
|
5000
4754
|
navigationTimeoutSecs: 120
|
|
5001
4755
|
});
|
|
5002
4756
|
var fingerprintInjector = new import_fingerprint_injector.FingerprintInjector();
|
|
4757
|
+
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
4758
|
+
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
4759
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4760
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4761
|
+
if (!enableProxy || !proxyUrl) {
|
|
4762
|
+
return { byPassDomains: [], enableProxy, proxyUrl };
|
|
4763
|
+
}
|
|
4764
|
+
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
4765
|
+
return { byPassDomains, enableProxy, proxyUrl };
|
|
4766
|
+
};
|
|
5003
4767
|
var parseChromeMajorVersion = (rawValue = "") => {
|
|
5004
4768
|
const match = String(rawValue || "").match(/(?:Chrome|Chromium)(?:\/|\s+(?:for Testing\s+)?)(\d+)/i);
|
|
5005
4769
|
return match ? Number(match[1] || 0) : 0;
|
|
@@ -5043,7 +4807,7 @@ var resolveCoreDevice = (core = {}) => {
|
|
|
5043
4807
|
};
|
|
5044
4808
|
var buildFingerprintGenerator = ({ locale, browserMajorVersion, device }) => {
|
|
5045
4809
|
return new import_fingerprint_generator.FingerprintGenerator(
|
|
5046
|
-
|
|
4810
|
+
AntiCheat.getFingerprintGeneratorOptions({
|
|
5047
4811
|
locale,
|
|
5048
4812
|
browserMajorVersion,
|
|
5049
4813
|
device
|
|
@@ -5087,7 +4851,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5087
4851
|
}
|
|
5088
4852
|
let nextState = RuntimeEnv.rememberState(runtimeState);
|
|
5089
4853
|
let browserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
|
|
5090
|
-
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() ||
|
|
4854
|
+
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() || AntiCheat.getBaseConfig().timezoneId;
|
|
5091
4855
|
const locale = DEFAULT_LOCALE;
|
|
5092
4856
|
const currentBrowserMajorVersion = detectBrowserMajorVersion(launcher);
|
|
5093
4857
|
const storedBrowserMajorVersion = Number(browserProfileCore?.browser_major_version || 0);
|
|
@@ -5166,7 +4930,7 @@ var applyFingerprintPageOptions = (pageOptions = {}, { fingerprintWithHeaders =
|
|
|
5166
4930
|
pageOptions.timezoneId = timezoneId;
|
|
5167
4931
|
}
|
|
5168
4932
|
};
|
|
5169
|
-
var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
4933
|
+
var buildReplayBrowserPoolOptions = (browserProfileCore, modifyPageOptions = null) => {
|
|
5170
4934
|
const fingerprintWithHeaders = browserProfileCore?.fingerprint;
|
|
5171
4935
|
const fingerprint = fingerprintWithHeaders?.fingerprint;
|
|
5172
4936
|
if (!fingerprintWithHeaders || !fingerprint) {
|
|
@@ -5175,13 +4939,16 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5175
4939
|
return {
|
|
5176
4940
|
useFingerprints: false,
|
|
5177
4941
|
prePageCreateHooks: [
|
|
5178
|
-
(
|
|
4942
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5179
4943
|
if (!pageOptions || typeof pageOptions !== "object") return;
|
|
5180
4944
|
applyFingerprintPageOptions(pageOptions, {
|
|
5181
4945
|
fingerprintWithHeaders,
|
|
5182
4946
|
locale: browserProfileCore.locale,
|
|
5183
4947
|
timezoneId: browserProfileCore.timezone_id
|
|
5184
4948
|
});
|
|
4949
|
+
if (modifyPageOptions) {
|
|
4950
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
4951
|
+
}
|
|
5185
4952
|
}
|
|
5186
4953
|
],
|
|
5187
4954
|
postPageCreateHooks: [
|
|
@@ -5196,7 +4963,7 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5196
4963
|
]
|
|
5197
4964
|
};
|
|
5198
4965
|
};
|
|
5199
|
-
var
|
|
4966
|
+
var Launch = {
|
|
5200
4967
|
getPlaywrightCrawlerOptions(options = {}) {
|
|
5201
4968
|
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
5202
4969
|
const {
|
|
@@ -5207,35 +4974,54 @@ var DefaultLaunch = {
|
|
|
5207
4974
|
debugMode = false,
|
|
5208
4975
|
isRunningOnApify = false,
|
|
5209
4976
|
launcher = null,
|
|
4977
|
+
hooks = {},
|
|
5210
4978
|
preNavigationHooks = [],
|
|
5211
4979
|
postNavigationHooks = [],
|
|
5212
4980
|
runtimeState = null
|
|
5213
4981
|
} = normalizedOptions;
|
|
5214
4982
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5215
|
-
const
|
|
5216
|
-
const
|
|
5217
|
-
const
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
4983
|
+
const modifyPageOptions = typeof hooks?.modifyPageOptions === "function" ? hooks.modifyPageOptions : null;
|
|
4984
|
+
const { byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
4985
|
+
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4986
|
+
const proxyMeter = enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4987
|
+
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4988
|
+
if (launchProxy && byPassDomains.length > 0) {
|
|
4989
|
+
launchProxy.bypass = byPassDomains.join(",");
|
|
4990
|
+
}
|
|
5221
4991
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5222
|
-
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
4992
|
+
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore, modifyPageOptions);
|
|
5223
4993
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5224
4994
|
const launchOptions = {
|
|
5225
4995
|
args: [
|
|
5226
|
-
...
|
|
4996
|
+
...AntiCheat.getLaunchArgs({ locale: launchLocale }),
|
|
5227
4997
|
...customArgs
|
|
5228
4998
|
],
|
|
5229
4999
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
5230
5000
|
};
|
|
5231
|
-
if (
|
|
5232
|
-
launchOptions.proxy =
|
|
5001
|
+
if (launchProxy) {
|
|
5002
|
+
launchOptions.proxy = launchProxy;
|
|
5003
|
+
}
|
|
5004
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5005
|
+
if (enableByPassLogger && launchProxy) {
|
|
5006
|
+
let upstreamLabel = "";
|
|
5007
|
+
try {
|
|
5008
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5009
|
+
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5010
|
+
} catch {
|
|
5011
|
+
}
|
|
5012
|
+
logger8.info(
|
|
5013
|
+
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5014
|
+
);
|
|
5015
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5016
|
+
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5017
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5018
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5019
|
+
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5020
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5021
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5022
|
+
} else if (enableByPassLogger) {
|
|
5023
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5233
5024
|
}
|
|
5234
|
-
logLaunchTraffic({
|
|
5235
|
-
...traffic,
|
|
5236
|
-
debugMode,
|
|
5237
|
-
enabled: enableByPassLogger
|
|
5238
|
-
});
|
|
5239
5025
|
const onPageCreated = (page) => {
|
|
5240
5026
|
const recommendedGotoOptions = {
|
|
5241
5027
|
waitUntil: "commit"
|
|
@@ -5243,7 +5029,22 @@ var DefaultLaunch = {
|
|
|
5243
5029
|
if (!page || typeof page.on !== "function") {
|
|
5244
5030
|
return recommendedGotoOptions;
|
|
5245
5031
|
}
|
|
5246
|
-
|
|
5032
|
+
if (page[REQUEST_HOOK_FLAG]) {
|
|
5033
|
+
return recommendedGotoOptions;
|
|
5034
|
+
}
|
|
5035
|
+
page[REQUEST_HOOK_FLAG] = true;
|
|
5036
|
+
const requestHandler = (req) => {
|
|
5037
|
+
const requestUrl = req.url();
|
|
5038
|
+
const resourceType = req.resourceType();
|
|
5039
|
+
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
5040
|
+
if (launchProxy) {
|
|
5041
|
+
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
5042
|
+
}
|
|
5043
|
+
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5044
|
+
if (!matched || !matched.rule) return;
|
|
5045
|
+
logger8.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
5046
|
+
};
|
|
5047
|
+
page.on("request", requestHandler);
|
|
5247
5048
|
return recommendedGotoOptions;
|
|
5248
5049
|
};
|
|
5249
5050
|
const launchContext = {
|
|
@@ -5260,20 +5061,23 @@ var DefaultLaunch = {
|
|
|
5260
5061
|
browserPoolOptions: replayBrowserPoolOptions || {
|
|
5261
5062
|
useFingerprints: true,
|
|
5262
5063
|
fingerprintOptions: {
|
|
5263
|
-
fingerprintGeneratorOptions:
|
|
5064
|
+
fingerprintGeneratorOptions: AntiCheat.getFingerprintGeneratorOptions({
|
|
5264
5065
|
locale: launchLocale,
|
|
5265
5066
|
device
|
|
5266
5067
|
})
|
|
5267
5068
|
},
|
|
5268
5069
|
prePageCreateHooks: [
|
|
5269
|
-
(
|
|
5070
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5270
5071
|
const fingerprintWithHeaders = browserController?.launchContext?.fingerprint;
|
|
5271
|
-
const timezoneId =
|
|
5072
|
+
const timezoneId = AntiCheat.getBaseConfig().timezoneId;
|
|
5272
5073
|
applyFingerprintPageOptions(pageOptions, {
|
|
5273
5074
|
fingerprintWithHeaders,
|
|
5274
5075
|
locale: launchLocale,
|
|
5275
5076
|
timezoneId
|
|
5276
5077
|
});
|
|
5078
|
+
if (modifyPageOptions) {
|
|
5079
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
5080
|
+
}
|
|
5277
5081
|
}
|
|
5278
5082
|
]
|
|
5279
5083
|
},
|
|
@@ -5295,287 +5099,10 @@ var DefaultLaunch = {
|
|
|
5295
5099
|
}
|
|
5296
5100
|
};
|
|
5297
5101
|
|
|
5298
|
-
// src/internals/launch/cloak.js
|
|
5299
|
-
var import_node_child_process2 = require("node:child_process");
|
|
5300
|
-
var import_node_util = require("node:util");
|
|
5301
|
-
var logger9 = createInternalLogger("Launch");
|
|
5302
|
-
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5303
|
-
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5304
|
-
maxConcurrency: 1,
|
|
5305
|
-
maxRequestRetries: 0,
|
|
5306
|
-
requestHandlerTimeoutSecs: 240,
|
|
5307
|
-
navigationTimeoutSecs: 120
|
|
5308
|
-
});
|
|
5309
|
-
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5310
|
-
humanize: true
|
|
5311
|
-
});
|
|
5312
|
-
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5313
|
-
waitUntil: "commit"
|
|
5314
|
-
});
|
|
5315
|
-
var cachedCloakModulePromise = null;
|
|
5316
|
-
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5317
|
-
var loadCloakModule = async () => {
|
|
5318
|
-
if (!cachedCloakModulePromise) {
|
|
5319
|
-
cachedCloakModulePromise = import("cloakbrowser").catch((error) => {
|
|
5320
|
-
cachedCloakModulePromise = null;
|
|
5321
|
-
throw new Error("Cloak \u6A21\u5757\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5 cloakbrowser\u3002", {
|
|
5322
|
-
cause: error
|
|
5323
|
-
});
|
|
5324
|
-
});
|
|
5325
|
-
}
|
|
5326
|
-
return cachedCloakModulePromise;
|
|
5327
|
-
};
|
|
5328
|
-
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5329
|
-
const { buildLaunchOptions } = await loadCloakModule();
|
|
5330
|
-
return await buildLaunchOptions(normalizeObject2(options));
|
|
5331
|
-
};
|
|
5332
|
-
var normalizeObject2 = (value) => {
|
|
5333
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5334
|
-
return {};
|
|
5335
|
-
}
|
|
5336
|
-
return value;
|
|
5337
|
-
};
|
|
5338
|
-
var normalizeStringArray = (value) => {
|
|
5339
|
-
if (!Array.isArray(value)) {
|
|
5340
|
-
return [];
|
|
5341
|
-
}
|
|
5342
|
-
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5343
|
-
};
|
|
5344
|
-
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5345
|
-
const config = normalizeObject2(proxyConfiguration);
|
|
5346
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5347
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5348
|
-
if (!enableProxy || !proxyUrl) {
|
|
5349
|
-
return null;
|
|
5350
|
-
}
|
|
5351
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5352
|
-
if (byPassDomains.length === 0) {
|
|
5353
|
-
return proxyUrl;
|
|
5354
|
-
}
|
|
5355
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5356
|
-
return {
|
|
5357
|
-
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5358
|
-
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5359
|
-
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5360
|
-
bypass: byPassDomains.join(",")
|
|
5361
|
-
};
|
|
5362
|
-
};
|
|
5363
|
-
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5364
|
-
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5365
|
-
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5366
|
-
};
|
|
5367
|
-
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5368
|
-
const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
|
|
5369
|
-
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5370
|
-
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5371
|
-
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5372
|
-
if (gotoOptions[key] == null) {
|
|
5373
|
-
gotoOptions[key] = value;
|
|
5374
|
-
}
|
|
5375
|
-
}
|
|
5376
|
-
};
|
|
5377
|
-
};
|
|
5378
|
-
var attachCloakHumanizeHook = ({
|
|
5379
|
-
browserPoolOptions = {},
|
|
5380
|
-
activeBrowsers,
|
|
5381
|
-
patchedBrowsers,
|
|
5382
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5383
|
-
} = {}) => {
|
|
5384
|
-
const normalizedBrowserPoolOptions = normalizeObject2(browserPoolOptions);
|
|
5385
|
-
const shouldHumanize = humanizeOptions !== false;
|
|
5386
|
-
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5387
|
-
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5388
|
-
...normalizeObject2(humanizeOptions)
|
|
5389
|
-
} : null;
|
|
5390
|
-
return {
|
|
5391
|
-
...normalizedBrowserPoolOptions,
|
|
5392
|
-
useFingerprints: false,
|
|
5393
|
-
postLaunchHooks: [
|
|
5394
|
-
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5395
|
-
async (_pageId, browserController) => {
|
|
5396
|
-
const browser = browserController?.browser;
|
|
5397
|
-
if (!browser || typeof browser.contexts !== "function") {
|
|
5398
|
-
return;
|
|
5399
|
-
}
|
|
5400
|
-
activeBrowsers.add(browser);
|
|
5401
|
-
if (typeof browser.once === "function") {
|
|
5402
|
-
browser.once("disconnected", () => {
|
|
5403
|
-
activeBrowsers.delete(browser);
|
|
5404
|
-
});
|
|
5405
|
-
}
|
|
5406
|
-
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5407
|
-
return;
|
|
5408
|
-
}
|
|
5409
|
-
const { humanizeBrowser } = await loadCloakModule();
|
|
5410
|
-
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5411
|
-
patchedBrowsers.add(browser);
|
|
5412
|
-
}
|
|
5413
|
-
]
|
|
5414
|
-
};
|
|
5415
|
-
};
|
|
5416
|
-
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5417
|
-
const browsers = Array.from(activeBrowsers || []);
|
|
5418
|
-
activeBrowsers?.clear?.();
|
|
5419
|
-
await Promise.allSettled(
|
|
5420
|
-
browsers.map(async (browser) => {
|
|
5421
|
-
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5422
|
-
return;
|
|
5423
|
-
}
|
|
5424
|
-
await browser.close().catch(() => {
|
|
5425
|
-
});
|
|
5426
|
-
})
|
|
5427
|
-
);
|
|
5428
|
-
};
|
|
5429
|
-
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5430
|
-
if (!fingerprintArg) {
|
|
5431
|
-
return;
|
|
5432
|
-
}
|
|
5433
|
-
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5434
|
-
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5435
|
-
return;
|
|
5436
|
-
}
|
|
5437
|
-
logger9.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5438
|
-
});
|
|
5439
|
-
};
|
|
5440
|
-
var CloakLaunch = {
|
|
5441
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5442
|
-
return resolveCloakProxy(proxyConfiguration);
|
|
5443
|
-
},
|
|
5444
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5445
|
-
return extractFingerprintArg(launchOptions);
|
|
5446
|
-
},
|
|
5447
|
-
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5448
|
-
return createStableGotoHook(recommendedGotoOptions);
|
|
5449
|
-
},
|
|
5450
|
-
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5451
|
-
const runtime2 = await CloakLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5452
|
-
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5453
|
-
cleanup: {
|
|
5454
|
-
enumerable: false,
|
|
5455
|
-
value: runtime2.cleanup
|
|
5456
|
-
},
|
|
5457
|
-
closeActiveBrowsers: {
|
|
5458
|
-
enumerable: false,
|
|
5459
|
-
value: runtime2.closeActiveBrowsers
|
|
5460
|
-
},
|
|
5461
|
-
forceTerminateActiveProcesses: {
|
|
5462
|
-
enumerable: false,
|
|
5463
|
-
value: runtime2.forceTerminateActiveProcesses
|
|
5464
|
-
}
|
|
5465
|
-
});
|
|
5466
|
-
},
|
|
5467
|
-
async buildLaunchOptions(options = {}) {
|
|
5468
|
-
return await buildCloakLaunchOptions(options);
|
|
5469
|
-
},
|
|
5470
|
-
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5471
|
-
const normalizedOptions = normalizeObject2(options);
|
|
5472
|
-
const {
|
|
5473
|
-
proxyConfiguration = {},
|
|
5474
|
-
log: logOptions = null,
|
|
5475
|
-
debugMode = false,
|
|
5476
|
-
runInHeadfulMode = false,
|
|
5477
|
-
isRunningOnApify = false,
|
|
5478
|
-
launcher = null,
|
|
5479
|
-
cloakOptions = {},
|
|
5480
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5481
|
-
crawlerBaseOptions = {},
|
|
5482
|
-
browserPoolOptions = {},
|
|
5483
|
-
launchContext = {},
|
|
5484
|
-
preNavigationHooks = [],
|
|
5485
|
-
postNavigationHooks = [],
|
|
5486
|
-
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5487
|
-
} = normalizedOptions;
|
|
5488
|
-
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5489
|
-
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5490
|
-
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5491
|
-
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5492
|
-
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5493
|
-
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5494
|
-
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5495
|
-
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
5496
|
-
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5497
|
-
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5498
|
-
const mergedCloakOptions = {
|
|
5499
|
-
...normalizedCloakOptions,
|
|
5500
|
-
headless,
|
|
5501
|
-
proxy,
|
|
5502
|
-
args: [...defaultArgs, ...extraArgs]
|
|
5503
|
-
};
|
|
5504
|
-
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5505
|
-
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5506
|
-
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5507
|
-
const trafficHook = createLaunchTrafficHook({
|
|
5508
|
-
byPassDomains: proxyLaunchState.byPassDomains,
|
|
5509
|
-
byPassRules: proxyLaunchState.byPassRules,
|
|
5510
|
-
enabled: enableByPassLogger,
|
|
5511
|
-
launchProxy: proxyLaunchState.launchProxy
|
|
5512
|
-
});
|
|
5513
|
-
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5514
|
-
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5515
|
-
logLaunchTraffic({
|
|
5516
|
-
...proxyLaunchState,
|
|
5517
|
-
debugMode,
|
|
5518
|
-
enabled: enableByPassLogger,
|
|
5519
|
-
explicitProxy: hasExplicitProxy
|
|
5520
|
-
});
|
|
5521
|
-
const crawlerOptions = {
|
|
5522
|
-
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5523
|
-
...normalizeObject2(crawlerBaseOptions),
|
|
5524
|
-
headless,
|
|
5525
|
-
launchContext: {
|
|
5526
|
-
useIncognitoPages: true,
|
|
5527
|
-
...normalizeObject2(launchContext),
|
|
5528
|
-
...launcher ? { launcher } : {},
|
|
5529
|
-
launchOptions
|
|
5530
|
-
},
|
|
5531
|
-
browserPoolOptions: attachCloakHumanizeHook({
|
|
5532
|
-
browserPoolOptions,
|
|
5533
|
-
activeBrowsers,
|
|
5534
|
-
patchedBrowsers,
|
|
5535
|
-
humanizeOptions
|
|
5536
|
-
}),
|
|
5537
|
-
preNavigationHooks: [
|
|
5538
|
-
async (crawlingContext, gotoOptions = {}) => {
|
|
5539
|
-
trafficHook(crawlingContext?.page);
|
|
5540
|
-
await internalPreNavigationHook(crawlingContext, gotoOptions);
|
|
5541
|
-
},
|
|
5542
|
-
...normalizedPreNavigationHooks
|
|
5543
|
-
],
|
|
5544
|
-
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5545
|
-
};
|
|
5546
|
-
const closeActiveBrowsers = async () => {
|
|
5547
|
-
await closeTrackedBrowsers(activeBrowsers);
|
|
5548
|
-
};
|
|
5549
|
-
const forceTerminateActiveProcesses = async () => {
|
|
5550
|
-
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5551
|
-
};
|
|
5552
|
-
const cleanup = async () => {
|
|
5553
|
-
await closeActiveBrowsers();
|
|
5554
|
-
await forceTerminateActiveProcesses();
|
|
5555
|
-
};
|
|
5556
|
-
return {
|
|
5557
|
-
headless,
|
|
5558
|
-
launchOptions,
|
|
5559
|
-
fingerprintArg,
|
|
5560
|
-
crawlerOptions,
|
|
5561
|
-
closeActiveBrowsers,
|
|
5562
|
-
forceTerminateActiveProcesses,
|
|
5563
|
-
cleanup
|
|
5564
|
-
};
|
|
5565
|
-
}
|
|
5566
|
-
};
|
|
5567
|
-
|
|
5568
|
-
// src/launch.js
|
|
5569
|
-
var launchStrategies = {
|
|
5570
|
-
[Mode.Default]: DefaultLaunch,
|
|
5571
|
-
[Mode.Cloak]: CloakLaunch
|
|
5572
|
-
};
|
|
5573
|
-
var Launch = withModeReflect("Launch", launchStrategies);
|
|
5574
|
-
|
|
5575
5102
|
// src/live-view.js
|
|
5576
5103
|
var import_express = __toESM(require("express"), 1);
|
|
5577
5104
|
var import_apify = require("apify");
|
|
5578
|
-
var
|
|
5105
|
+
var logger9 = createInternalLogger("LiveView");
|
|
5579
5106
|
async function startLiveViewServer(liveViewKey) {
|
|
5580
5107
|
const app = (0, import_express.default)();
|
|
5581
5108
|
app.get("/", async (req, res) => {
|
|
@@ -5600,13 +5127,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5600
5127
|
</html>
|
|
5601
5128
|
`);
|
|
5602
5129
|
} catch (error) {
|
|
5603
|
-
|
|
5130
|
+
logger9.fail("Live View Server", error);
|
|
5604
5131
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5605
5132
|
}
|
|
5606
5133
|
});
|
|
5607
5134
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5608
5135
|
app.listen(port, () => {
|
|
5609
|
-
|
|
5136
|
+
logger9.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5610
5137
|
});
|
|
5611
5138
|
}
|
|
5612
5139
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5614,10 +5141,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5614
5141
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5615
5142
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5616
5143
|
if (logMessage) {
|
|
5617
|
-
|
|
5144
|
+
logger9.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5618
5145
|
}
|
|
5619
5146
|
} catch (e) {
|
|
5620
|
-
|
|
5147
|
+
logger9.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5621
5148
|
}
|
|
5622
5149
|
}
|
|
5623
5150
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5634,6 +5161,9 @@ var LiveView = {
|
|
|
5634
5161
|
useLiveView
|
|
5635
5162
|
};
|
|
5636
5163
|
|
|
5164
|
+
// src/chaptcha.js
|
|
5165
|
+
var import_uuid = require("uuid");
|
|
5166
|
+
|
|
5637
5167
|
// src/internals/captcha/bytedance.js
|
|
5638
5168
|
var import_promises = require("fs/promises");
|
|
5639
5169
|
var import_path2 = __toESM(require("path"), 1);
|
|
@@ -5723,7 +5253,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5723
5253
|
};
|
|
5724
5254
|
|
|
5725
5255
|
// src/internals/captcha/bytedance.js
|
|
5726
|
-
var
|
|
5256
|
+
var logger10 = createInternalLogger("Captcha");
|
|
5727
5257
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5728
5258
|
apiType: "31234",
|
|
5729
5259
|
maxRetries: 3,
|
|
@@ -5855,7 +5385,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5855
5385
|
}
|
|
5856
5386
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5857
5387
|
}
|
|
5858
|
-
|
|
5388
|
+
logger10.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5859
5389
|
};
|
|
5860
5390
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5861
5391
|
if (!options.debugArtifacts) {
|
|
@@ -5892,14 +5422,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5892
5422
|
if (!isContainerVisible) {
|
|
5893
5423
|
return null;
|
|
5894
5424
|
}
|
|
5895
|
-
|
|
5425
|
+
logger10.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5896
5426
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5897
5427
|
let isIframeVisible = await waitForVisible(
|
|
5898
5428
|
iframeLocator,
|
|
5899
5429
|
options.iframeVisibleTimeoutMs
|
|
5900
5430
|
);
|
|
5901
5431
|
if (!isIframeVisible) {
|
|
5902
|
-
|
|
5432
|
+
logger10.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5903
5433
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5904
5434
|
isIframeVisible = await waitForVisible(
|
|
5905
5435
|
iframeLocator,
|
|
@@ -5909,7 +5439,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5909
5439
|
if (!isIframeVisible) {
|
|
5910
5440
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5911
5441
|
}
|
|
5912
|
-
|
|
5442
|
+
logger10.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5913
5443
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5914
5444
|
if (!frame) {
|
|
5915
5445
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -6025,11 +5555,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
6025
5555
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
6026
5556
|
...options,
|
|
6027
5557
|
page,
|
|
6028
|
-
logger:
|
|
5558
|
+
logger: logger10,
|
|
6029
5559
|
forceMouse: true
|
|
6030
5560
|
}).catch(() => false);
|
|
6031
5561
|
if (!clicked) {
|
|
6032
|
-
|
|
5562
|
+
logger10.warn("Refresh button not found.");
|
|
6033
5563
|
return false;
|
|
6034
5564
|
}
|
|
6035
5565
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6060,24 +5590,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6060
5590
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6061
5591
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6062
5592
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6063
|
-
|
|
5593
|
+
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");
|
|
6064
5594
|
hasLoggedGuideMask = true;
|
|
6065
5595
|
}
|
|
6066
5596
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6067
|
-
|
|
5597
|
+
logger10.info(
|
|
6068
5598
|
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"
|
|
6069
5599
|
);
|
|
6070
5600
|
return;
|
|
6071
5601
|
}
|
|
6072
5602
|
if (hasErrorTextVisible) {
|
|
6073
|
-
|
|
5603
|
+
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");
|
|
6074
5604
|
await refreshCaptcha(page, frame, options);
|
|
6075
5605
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6076
5606
|
hasSeenLoading = false;
|
|
6077
5607
|
continue;
|
|
6078
5608
|
}
|
|
6079
5609
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6080
|
-
|
|
5610
|
+
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`);
|
|
6081
5611
|
await refreshCaptcha(page, frame, options);
|
|
6082
5612
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6083
5613
|
hasSeenLoading = false;
|
|
@@ -6125,7 +5655,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6125
5655
|
accepted
|
|
6126
5656
|
};
|
|
6127
5657
|
dragAttempts.push(attemptInfo);
|
|
6128
|
-
|
|
5658
|
+
logger10.info(
|
|
6129
5659
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6130
5660
|
);
|
|
6131
5661
|
if (accepted) {
|
|
@@ -6143,7 +5673,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6143
5673
|
dragAttempts,
|
|
6144
5674
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6145
5675
|
}).catch((error) => {
|
|
6146
|
-
|
|
5676
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6147
5677
|
});
|
|
6148
5678
|
return {
|
|
6149
5679
|
accepted: false,
|
|
@@ -6160,16 +5690,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6160
5690
|
...options
|
|
6161
5691
|
};
|
|
6162
5692
|
if (!config.token) {
|
|
6163
|
-
|
|
5693
|
+
logger10.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6164
5694
|
return false;
|
|
6165
5695
|
}
|
|
6166
|
-
|
|
5696
|
+
logger10.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6167
5697
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6168
|
-
|
|
5698
|
+
logger10.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6169
5699
|
try {
|
|
6170
5700
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6171
5701
|
if (!captchaContext) {
|
|
6172
|
-
|
|
5702
|
+
logger10.info("Captcha container is not visible anymore.");
|
|
6173
5703
|
return true;
|
|
6174
5704
|
}
|
|
6175
5705
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6182,7 +5712,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6182
5712
|
"ready",
|
|
6183
5713
|
config
|
|
6184
5714
|
).catch((error) => {
|
|
6185
|
-
|
|
5715
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6186
5716
|
});
|
|
6187
5717
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6188
5718
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6194,16 +5724,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6194
5724
|
});
|
|
6195
5725
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6196
5726
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6197
|
-
|
|
5727
|
+
logger10.warn(
|
|
6198
5728
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6199
5729
|
);
|
|
6200
5730
|
await refreshCaptcha(page, frame, config);
|
|
6201
5731
|
continue;
|
|
6202
5732
|
}
|
|
6203
|
-
|
|
5733
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6204
5734
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6205
5735
|
if (!dropTarget) {
|
|
6206
|
-
|
|
5736
|
+
logger10.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6207
5737
|
await refreshCaptcha(page, frame, config);
|
|
6208
5738
|
continue;
|
|
6209
5739
|
}
|
|
@@ -6214,7 +5744,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6214
5744
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6215
5745
|
);
|
|
6216
5746
|
}
|
|
6217
|
-
|
|
5747
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6218
5748
|
for (const imageIndex of normalizedIndexes) {
|
|
6219
5749
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6220
5750
|
throw new Error(
|
|
@@ -6246,55 +5776,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6246
5776
|
}
|
|
6247
5777
|
}
|
|
6248
5778
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6249
|
-
|
|
5779
|
+
logger10.info(
|
|
6250
5780
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6251
5781
|
);
|
|
6252
5782
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6253
5783
|
...config,
|
|
6254
5784
|
page,
|
|
6255
|
-
logger:
|
|
5785
|
+
logger: logger10,
|
|
6256
5786
|
forceMouse: true,
|
|
6257
5787
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6258
5788
|
}).catch(() => false);
|
|
6259
5789
|
if (!submitted) {
|
|
6260
|
-
|
|
5790
|
+
logger10.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6261
5791
|
}
|
|
6262
5792
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6263
5793
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6264
|
-
|
|
5794
|
+
logger10.info(
|
|
6265
5795
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6266
5796
|
);
|
|
6267
5797
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6268
5798
|
if (!stillVisible) {
|
|
6269
|
-
|
|
5799
|
+
logger10.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6270
5800
|
return true;
|
|
6271
5801
|
}
|
|
6272
5802
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6273
5803
|
beforeSubmitState,
|
|
6274
5804
|
afterSubmitState
|
|
6275
5805
|
}).catch((error) => {
|
|
6276
|
-
|
|
5806
|
+
logger10.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6277
5807
|
});
|
|
6278
|
-
|
|
5808
|
+
logger10.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6279
5809
|
await page.waitForTimeout(2e3);
|
|
6280
5810
|
await refreshCaptcha(page, frame, config);
|
|
6281
5811
|
} catch (error) {
|
|
6282
|
-
|
|
5812
|
+
logger10.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6283
5813
|
}
|
|
6284
5814
|
if (attempt < config.maxRetries) {
|
|
6285
5815
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6286
5816
|
}
|
|
6287
5817
|
}
|
|
6288
|
-
|
|
5818
|
+
logger10.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6289
5819
|
return false;
|
|
6290
5820
|
}
|
|
6291
5821
|
var sloveCaptcha = solveCaptcha;
|
|
6292
5822
|
|
|
6293
5823
|
// src/chaptcha.js
|
|
6294
|
-
var
|
|
6295
|
-
var DOM_MONITOR_WAIT_TIMEOUT_MS = 1e3;
|
|
6296
|
-
var DOM_MONITOR_POST_DETECT_HIDDEN_WAIT_MS = 300;
|
|
6297
|
-
var DOM_MONITOR_RECOVERY_WAIT_MS = 100;
|
|
5824
|
+
var logger11 = createInternalLogger("Captcha");
|
|
6298
5825
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6299
5826
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6300
5827
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6315,15 +5842,6 @@ var mergeDefinedOptions = (...sources) => {
|
|
|
6315
5842
|
}
|
|
6316
5843
|
return merged;
|
|
6317
5844
|
};
|
|
6318
|
-
var sleep = (ms) => new Promise((resolve) => {
|
|
6319
|
-
setTimeout(resolve, ms);
|
|
6320
|
-
});
|
|
6321
|
-
var getErrorMessage = (error) => String(error?.message || error || "");
|
|
6322
|
-
var isTimeoutError = (error) => error?.name === "TimeoutError" || getErrorMessage(error).includes("Timeout");
|
|
6323
|
-
var isPageLifecycleError = (error) => {
|
|
6324
|
-
const message = getErrorMessage(error);
|
|
6325
|
-
return message.includes("Execution context was destroyed") || message.includes("Frame was detached") || message.includes("Target page, context or browser has been closed") || message.includes("Target closed") || message.includes("Most likely the page has been closed");
|
|
6326
|
-
};
|
|
6327
5845
|
function useCaptchaMonitor(page, options) {
|
|
6328
5846
|
const { domSelector, urlPattern, onDetected } = options;
|
|
6329
5847
|
if (!domSelector && !urlPattern) {
|
|
@@ -6335,13 +5853,10 @@ function useCaptchaMonitor(page, options) {
|
|
|
6335
5853
|
let isStopped = false;
|
|
6336
5854
|
let isHandling = false;
|
|
6337
5855
|
let frameHandler = null;
|
|
6338
|
-
let
|
|
6339
|
-
let lastTriggeredAt = 0;
|
|
5856
|
+
let exposedFunctionName = null;
|
|
6340
5857
|
const triggerDetected = async () => {
|
|
6341
|
-
|
|
6342
|
-
if (isStopped || isHandling || now - lastTriggeredAt < 250) return;
|
|
5858
|
+
if (isStopped || isHandling) return;
|
|
6343
5859
|
isHandling = true;
|
|
6344
|
-
lastTriggeredAt = now;
|
|
6345
5860
|
try {
|
|
6346
5861
|
await onDetected();
|
|
6347
5862
|
} finally {
|
|
@@ -6350,38 +5865,60 @@ function useCaptchaMonitor(page, options) {
|
|
|
6350
5865
|
};
|
|
6351
5866
|
const cleanupFns = [];
|
|
6352
5867
|
if (domSelector) {
|
|
6353
|
-
|
|
6354
|
-
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
}).catch(() => {
|
|
6365
|
-
});
|
|
6366
|
-
} catch (error) {
|
|
6367
|
-
if (isStopped) break;
|
|
6368
|
-
if (page?.isClosed?.() && isPageLifecycleError(error)) break;
|
|
6369
|
-
if (isTimeoutError(error) || isPageLifecycleError(error)) {
|
|
6370
|
-
await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
|
|
6371
|
-
continue;
|
|
5868
|
+
exposedFunctionName = `__c_d_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
5869
|
+
const cleanerName = `__c_cleaner_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
5870
|
+
page.exposeFunction(exposedFunctionName, triggerDetected).catch(() => {
|
|
5871
|
+
});
|
|
5872
|
+
page.addInitScript(({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
5873
|
+
(() => {
|
|
5874
|
+
let observer = null;
|
|
5875
|
+
const checkAndReport = () => {
|
|
5876
|
+
const element = document.querySelector(selector);
|
|
5877
|
+
if (!element) {
|
|
5878
|
+
return false;
|
|
6372
5879
|
}
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
5880
|
+
if (window[callbackName]) {
|
|
5881
|
+
window[callbackName]();
|
|
5882
|
+
}
|
|
5883
|
+
return true;
|
|
5884
|
+
};
|
|
5885
|
+
checkAndReport();
|
|
5886
|
+
observer = new MutationObserver((mutations) => {
|
|
5887
|
+
const shouldCheck = mutations.some((mutation) => mutation.addedNodes.length > 0);
|
|
5888
|
+
if (shouldCheck && observer) {
|
|
5889
|
+
checkAndReport();
|
|
5890
|
+
}
|
|
5891
|
+
});
|
|
5892
|
+
const mountObserver = () => {
|
|
5893
|
+
const target = document.documentElement;
|
|
5894
|
+
if (target && observer) {
|
|
5895
|
+
observer.observe(target, { childList: true, subtree: true });
|
|
5896
|
+
}
|
|
5897
|
+
};
|
|
5898
|
+
if (document.readyState === "loading") {
|
|
5899
|
+
window.addEventListener("DOMContentLoaded", mountObserver);
|
|
5900
|
+
} else {
|
|
5901
|
+
mountObserver();
|
|
6378
5902
|
}
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
5903
|
+
window[cleanupName] = () => {
|
|
5904
|
+
if (observer) {
|
|
5905
|
+
observer.disconnect();
|
|
5906
|
+
observer = null;
|
|
5907
|
+
}
|
|
5908
|
+
};
|
|
5909
|
+
})();
|
|
5910
|
+
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
5911
|
+
logger11.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6382
5912
|
cleanupFns.push(async () => {
|
|
6383
|
-
|
|
6384
|
-
|
|
5913
|
+
try {
|
|
5914
|
+
await page.evaluate((name) => {
|
|
5915
|
+
if (window[name]) {
|
|
5916
|
+
window[name]();
|
|
5917
|
+
delete window[name];
|
|
5918
|
+
}
|
|
5919
|
+
}, cleanerName);
|
|
5920
|
+
} catch {
|
|
5921
|
+
}
|
|
6385
5922
|
});
|
|
6386
5923
|
}
|
|
6387
5924
|
if (urlPattern) {
|
|
@@ -6395,24 +5932,18 @@ function useCaptchaMonitor(page, options) {
|
|
|
6395
5932
|
}
|
|
6396
5933
|
};
|
|
6397
5934
|
page.on("framenavigated", frameHandler);
|
|
6398
|
-
|
|
6399
|
-
Promise.resolve().then(async () => {
|
|
6400
|
-
if (!isStopped && page.url().includes(urlPattern)) {
|
|
6401
|
-
await triggerDetected();
|
|
6402
|
-
}
|
|
6403
|
-
}).catch(() => {
|
|
6404
|
-
});
|
|
5935
|
+
logger11.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6405
5936
|
cleanupFns.push(async () => {
|
|
6406
5937
|
page.off("framenavigated", frameHandler);
|
|
6407
5938
|
});
|
|
6408
5939
|
}
|
|
6409
5940
|
return {
|
|
6410
5941
|
stop: async () => {
|
|
6411
|
-
|
|
6412
|
-
isStopped = true;
|
|
5942
|
+
logger11.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6413
5943
|
for (const fn of cleanupFns) {
|
|
6414
5944
|
await fn();
|
|
6415
5945
|
}
|
|
5946
|
+
isStopped = true;
|
|
6416
5947
|
}
|
|
6417
5948
|
};
|
|
6418
5949
|
}
|
|
@@ -6447,7 +5978,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6447
5978
|
);
|
|
6448
5979
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6449
5980
|
callCaptchaRecognitionApi,
|
|
6450
|
-
logger:
|
|
5981
|
+
logger: logger11
|
|
6451
5982
|
});
|
|
6452
5983
|
}
|
|
6453
5984
|
var Captcha = {
|
|
@@ -6457,15 +5988,15 @@ var Captcha = {
|
|
|
6457
5988
|
|
|
6458
5989
|
// src/mutation.js
|
|
6459
5990
|
var import_node_crypto = require("node:crypto");
|
|
6460
|
-
var
|
|
6461
|
-
var
|
|
5991
|
+
var import_uuid2 = require("uuid");
|
|
5992
|
+
var logger12 = createInternalLogger("Mutation");
|
|
6462
5993
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6463
5994
|
Added: "added",
|
|
6464
5995
|
Changed: "changed",
|
|
6465
5996
|
All: "all"
|
|
6466
5997
|
});
|
|
6467
5998
|
function generateKey(prefix) {
|
|
6468
|
-
return `__${prefix}_${(0,
|
|
5999
|
+
return `__${prefix}_${(0, import_uuid2.v4)().replace(/-/g, "_")}`;
|
|
6469
6000
|
}
|
|
6470
6001
|
var Mutation = {
|
|
6471
6002
|
Mode: MUTATION_MONITOR_MODE,
|
|
@@ -6491,14 +6022,14 @@ var Mutation = {
|
|
|
6491
6022
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6492
6023
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6493
6024
|
const onMutation = options.onMutation;
|
|
6494
|
-
|
|
6025
|
+
logger12.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6495
6026
|
if (initialTimeout > 0) {
|
|
6496
6027
|
const selectorQuery = selectorList.join(",");
|
|
6497
6028
|
try {
|
|
6498
6029
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6499
|
-
|
|
6030
|
+
logger12.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6500
6031
|
} catch (e) {
|
|
6501
|
-
|
|
6032
|
+
logger12.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6502
6033
|
throw e;
|
|
6503
6034
|
}
|
|
6504
6035
|
}
|
|
@@ -6514,7 +6045,7 @@ var Mutation = {
|
|
|
6514
6045
|
return "__CONTINUE__";
|
|
6515
6046
|
}
|
|
6516
6047
|
});
|
|
6517
|
-
|
|
6048
|
+
logger12.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6518
6049
|
} catch (e) {
|
|
6519
6050
|
}
|
|
6520
6051
|
}
|
|
@@ -6629,9 +6160,9 @@ var Mutation = {
|
|
|
6629
6160
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6630
6161
|
);
|
|
6631
6162
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6632
|
-
|
|
6163
|
+
logger12.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6633
6164
|
}
|
|
6634
|
-
|
|
6165
|
+
logger12.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6635
6166
|
return result;
|
|
6636
6167
|
},
|
|
6637
6168
|
/**
|
|
@@ -6655,7 +6186,7 @@ var Mutation = {
|
|
|
6655
6186
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6656
6187
|
const onMutation = options.onMutation;
|
|
6657
6188
|
const pollInterval = 500;
|
|
6658
|
-
const
|
|
6189
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6659
6190
|
setTimeout(resolve, ms);
|
|
6660
6191
|
});
|
|
6661
6192
|
const truncate = (value, max = 800) => {
|
|
@@ -6803,29 +6334,29 @@ var Mutation = {
|
|
|
6803
6334
|
return "__CONTINUE__";
|
|
6804
6335
|
}
|
|
6805
6336
|
};
|
|
6806
|
-
|
|
6337
|
+
logger12.start(
|
|
6807
6338
|
"waitForStableAcrossRoots",
|
|
6808
6339
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6809
6340
|
);
|
|
6810
6341
|
if (initialTimeout > 0) {
|
|
6811
6342
|
try {
|
|
6812
6343
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6813
|
-
|
|
6344
|
+
logger12.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6814
6345
|
} catch (e) {
|
|
6815
|
-
|
|
6346
|
+
logger12.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6816
6347
|
throw e;
|
|
6817
6348
|
}
|
|
6818
6349
|
}
|
|
6819
|
-
let
|
|
6820
|
-
if (!
|
|
6821
|
-
|
|
6350
|
+
let state = await buildState();
|
|
6351
|
+
if (!state?.hasMatched) {
|
|
6352
|
+
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6822
6353
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6823
6354
|
}
|
|
6824
6355
|
let mutationCount = 0;
|
|
6825
6356
|
let stableSince = 0;
|
|
6826
6357
|
let isPaused = false;
|
|
6827
6358
|
let wasPaused = false;
|
|
6828
|
-
let lastSnapshotKey =
|
|
6359
|
+
let lastSnapshotKey = state.snapshotKey;
|
|
6829
6360
|
const applyPauseSignal = (signal) => {
|
|
6830
6361
|
const nextPaused = signal === "__PAUSE__";
|
|
6831
6362
|
if (nextPaused) {
|
|
@@ -6839,15 +6370,15 @@ var Mutation = {
|
|
|
6839
6370
|
};
|
|
6840
6371
|
const initialSignal = await invokeMutationCallback({
|
|
6841
6372
|
mutationCount: 0,
|
|
6842
|
-
html:
|
|
6843
|
-
text:
|
|
6844
|
-
mutationNodes:
|
|
6373
|
+
html: state.html || "",
|
|
6374
|
+
text: state.text || "",
|
|
6375
|
+
mutationNodes: state.mutationNodes || []
|
|
6845
6376
|
});
|
|
6846
6377
|
applyPauseSignal(initialSignal);
|
|
6847
6378
|
const deadline = Date.now() + overallTimeout;
|
|
6848
|
-
let lastState =
|
|
6379
|
+
let lastState = state;
|
|
6849
6380
|
while (Date.now() < deadline) {
|
|
6850
|
-
await
|
|
6381
|
+
await sleep(pollInterval);
|
|
6851
6382
|
lastState = await buildState();
|
|
6852
6383
|
if (!lastState?.hasMatched) {
|
|
6853
6384
|
continue;
|
|
@@ -6855,7 +6386,7 @@ var Mutation = {
|
|
|
6855
6386
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6856
6387
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6857
6388
|
mutationCount += 1;
|
|
6858
|
-
|
|
6389
|
+
logger12.info(
|
|
6859
6390
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6860
6391
|
);
|
|
6861
6392
|
const signal = await invokeMutationCallback({
|
|
@@ -6868,7 +6399,7 @@ var Mutation = {
|
|
|
6868
6399
|
continue;
|
|
6869
6400
|
}
|
|
6870
6401
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6871
|
-
|
|
6402
|
+
logger12.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6872
6403
|
return {
|
|
6873
6404
|
mutationCount,
|
|
6874
6405
|
stableTime: waitForStableTime,
|
|
@@ -6895,7 +6426,7 @@ var Mutation = {
|
|
|
6895
6426
|
const onMutation = options.onMutation;
|
|
6896
6427
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6897
6428
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6898
|
-
|
|
6429
|
+
logger12.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6899
6430
|
const monitorKey = generateKey("pk_mon");
|
|
6900
6431
|
const callbackName = generateKey("pk_mon_cb");
|
|
6901
6432
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7038,7 +6569,7 @@ var Mutation = {
|
|
|
7038
6569
|
return total;
|
|
7039
6570
|
};
|
|
7040
6571
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7041
|
-
|
|
6572
|
+
logger12.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7042
6573
|
return {
|
|
7043
6574
|
stop: async () => {
|
|
7044
6575
|
let totalMutations = 0;
|
|
@@ -7051,7 +6582,7 @@ var Mutation = {
|
|
|
7051
6582
|
}, cleanerName);
|
|
7052
6583
|
} catch (e) {
|
|
7053
6584
|
}
|
|
7054
|
-
|
|
6585
|
+
logger12.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7055
6586
|
return { totalMutations };
|
|
7056
6587
|
}
|
|
7057
6588
|
};
|
|
@@ -7920,7 +7451,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7920
7451
|
};
|
|
7921
7452
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7922
7453
|
var Logger = {
|
|
7923
|
-
setLogger: (
|
|
7454
|
+
setLogger: (logger16) => setDefaultLogger(logger16),
|
|
7924
7455
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7925
7456
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7926
7457
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7928,14 +7459,14 @@ var Logger = {
|
|
|
7928
7459
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7929
7460
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7930
7461
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7931
|
-
useTemplate: (
|
|
7932
|
-
if (
|
|
7462
|
+
useTemplate: (logger16) => {
|
|
7463
|
+
if (logger16) return createTemplateLogger(createBaseLogger("", logger16));
|
|
7933
7464
|
return createTemplateLogger();
|
|
7934
7465
|
}
|
|
7935
7466
|
};
|
|
7936
7467
|
|
|
7937
7468
|
// src/share.js
|
|
7938
|
-
var
|
|
7469
|
+
var import_delay4 = __toESM(require("delay"), 1);
|
|
7939
7470
|
|
|
7940
7471
|
// src/internals/watermarkify.js
|
|
7941
7472
|
var DEFAULT_TIMEZONE_OFFSET = 8;
|
|
@@ -8003,7 +7534,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
8003
7534
|
];
|
|
8004
7535
|
var cachedStripLogoSrcPromise = null;
|
|
8005
7536
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
8006
|
-
var
|
|
7537
|
+
var logger13 = createInternalLogger("Watermarkify");
|
|
8007
7538
|
var normalizeText = (value) => String(value || "").trim();
|
|
8008
7539
|
var toInline = (value, maxLen = 200) => {
|
|
8009
7540
|
const text = normalizeText(value);
|
|
@@ -8245,9 +7776,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8245
7776
|
location: toInline(resolved.location, 80)
|
|
8246
7777
|
};
|
|
8247
7778
|
if (enrichment.ip || enrichment.location) {
|
|
8248
|
-
|
|
7779
|
+
logger13.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8249
7780
|
} else {
|
|
8250
|
-
|
|
7781
|
+
logger13.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8251
7782
|
}
|
|
8252
7783
|
return enrichment;
|
|
8253
7784
|
} finally {
|
|
@@ -8431,17 +7962,14 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8431
7962
|
</html>
|
|
8432
7963
|
`;
|
|
8433
7964
|
};
|
|
8434
|
-
var
|
|
8435
|
-
return String(value || "default").trim().toLowerCase() === "cloak" ? "cloak" : "default";
|
|
8436
|
-
};
|
|
8437
|
-
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
7965
|
+
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
8438
7966
|
if (!page || typeof page.context !== "function") {
|
|
8439
|
-
|
|
7967
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8440
7968
|
return buffer;
|
|
8441
7969
|
}
|
|
8442
7970
|
const renderScope = await openProbePage(page);
|
|
8443
7971
|
if (!renderScope?.page) {
|
|
8444
|
-
|
|
7972
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8445
7973
|
return buffer;
|
|
8446
7974
|
}
|
|
8447
7975
|
try {
|
|
@@ -8458,35 +7986,15 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8458
7986
|
height: viewportHeight
|
|
8459
7987
|
}).catch(() => {
|
|
8460
7988
|
});
|
|
8461
|
-
|
|
8462
|
-
|
|
8463
|
-
|
|
8464
|
-
|
|
8465
|
-
|
|
8466
|
-
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8470
|
-
await renderPage.goto("about:blank", {
|
|
8471
|
-
waitUntil: "commit"
|
|
8472
|
-
}).catch(() => {
|
|
8473
|
-
});
|
|
8474
|
-
await renderPage.evaluate((html) => {
|
|
8475
|
-
document.open();
|
|
8476
|
-
document.write(html);
|
|
8477
|
-
document.close();
|
|
8478
|
-
}, renderHtml);
|
|
8479
|
-
} else {
|
|
8480
|
-
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
8481
|
-
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8482
|
-
overlaySvg,
|
|
8483
|
-
width: safeWidth,
|
|
8484
|
-
height: safeHeight,
|
|
8485
|
-
imageHeight: safeImageHeight
|
|
8486
|
-
}), {
|
|
8487
|
-
waitUntil: "load"
|
|
8488
|
-
});
|
|
8489
|
-
}
|
|
7989
|
+
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
7990
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
7991
|
+
overlaySvg,
|
|
7992
|
+
width: safeWidth,
|
|
7993
|
+
height: safeHeight,
|
|
7994
|
+
imageHeight: safeImageHeight
|
|
7995
|
+
}), {
|
|
7996
|
+
waitUntil: "load"
|
|
7997
|
+
});
|
|
8490
7998
|
await renderPage.waitForFunction(() => {
|
|
8491
7999
|
const image = document.getElementById("pk-base-image");
|
|
8492
8000
|
return image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0 && image.naturalHeight > 0;
|
|
@@ -8506,13 +8014,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8506
8014
|
fullPage: true,
|
|
8507
8015
|
animations: "disabled"
|
|
8508
8016
|
}).catch((error) => {
|
|
8509
|
-
|
|
8017
|
+
logger13.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8510
8018
|
return null;
|
|
8511
8019
|
});
|
|
8512
8020
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8513
8021
|
return composed;
|
|
8514
8022
|
}
|
|
8515
|
-
|
|
8023
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8516
8024
|
return buffer;
|
|
8517
8025
|
} finally {
|
|
8518
8026
|
await renderScope.close().catch(() => {
|
|
@@ -8525,7 +8033,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8525
8033
|
}
|
|
8526
8034
|
const probeScope = await openProbePage(page);
|
|
8527
8035
|
if (!probeScope?.page) {
|
|
8528
|
-
|
|
8036
|
+
logger13.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8529
8037
|
return null;
|
|
8530
8038
|
}
|
|
8531
8039
|
const timeoutMs = Math.max(
|
|
@@ -8534,12 +8042,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8534
8042
|
);
|
|
8535
8043
|
try {
|
|
8536
8044
|
const probePage = probeScope.page;
|
|
8537
|
-
|
|
8045
|
+
logger13.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8538
8046
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8539
8047
|
waitUntil: "commit",
|
|
8540
8048
|
timeout: timeoutMs
|
|
8541
8049
|
}).catch((error) => {
|
|
8542
|
-
|
|
8050
|
+
logger13.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8543
8051
|
return null;
|
|
8544
8052
|
});
|
|
8545
8053
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8561,13 +8069,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8561
8069
|
}
|
|
8562
8070
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8563
8071
|
if (parsed?.ip || parsed?.location) {
|
|
8564
|
-
|
|
8072
|
+
logger13.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8565
8073
|
return parsed;
|
|
8566
8074
|
}
|
|
8567
|
-
|
|
8075
|
+
logger13.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8568
8076
|
return null;
|
|
8569
8077
|
} catch (error) {
|
|
8570
|
-
|
|
8078
|
+
logger13.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8571
8079
|
return null;
|
|
8572
8080
|
} finally {
|
|
8573
8081
|
await probeScope.close().catch(() => {
|
|
@@ -8581,10 +8089,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8581
8089
|
ip: toInline(options.ip, 80),
|
|
8582
8090
|
location: toInline(options.location, 80)
|
|
8583
8091
|
};
|
|
8584
|
-
|
|
8092
|
+
logger13.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8585
8093
|
if (!merged.ip || !merged.location) {
|
|
8586
8094
|
if (cached?.ip || cached?.location) {
|
|
8587
|
-
|
|
8095
|
+
logger13.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8588
8096
|
}
|
|
8589
8097
|
fillEnrichment(merged, cached);
|
|
8590
8098
|
}
|
|
@@ -8608,15 +8116,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8608
8116
|
"x-geo-country"
|
|
8609
8117
|
]), 80);
|
|
8610
8118
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8611
|
-
|
|
8119
|
+
logger13.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8612
8120
|
merged.location = headerLocation || merged.location;
|
|
8613
8121
|
}
|
|
8614
8122
|
}
|
|
8615
8123
|
writeCachedEnrichment(page, merged);
|
|
8616
8124
|
if (merged.ip || merged.location) {
|
|
8617
|
-
|
|
8125
|
+
logger13.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8618
8126
|
} else {
|
|
8619
|
-
|
|
8127
|
+
logger13.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8620
8128
|
}
|
|
8621
8129
|
return merged;
|
|
8622
8130
|
};
|
|
@@ -9421,7 +8929,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
9421
8929
|
</svg>
|
|
9422
8930
|
`;
|
|
9423
8931
|
};
|
|
9424
|
-
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null
|
|
8932
|
+
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
9425
8933
|
const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
|
|
9426
8934
|
const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
|
|
9427
8935
|
if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
|
|
@@ -9429,7 +8937,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9429
8937
|
}
|
|
9430
8938
|
const imageInfo = readImageInfo(buffer);
|
|
9431
8939
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9432
|
-
|
|
8940
|
+
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9433
8941
|
return buffer;
|
|
9434
8942
|
}
|
|
9435
8943
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9442,12 +8950,12 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9442
8950
|
if (!overlaySvg) {
|
|
9443
8951
|
return buffer;
|
|
9444
8952
|
}
|
|
9445
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo
|
|
8953
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
9446
8954
|
};
|
|
9447
8955
|
|
|
9448
8956
|
// src/internals/compression.js
|
|
9449
8957
|
var import_jimp = require("jimp");
|
|
9450
|
-
var
|
|
8958
|
+
var logger14 = createInternalLogger("Compression");
|
|
9451
8959
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9452
8960
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9453
8961
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9566,18 +9074,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9566
9074
|
return buffer.toString("base64");
|
|
9567
9075
|
}
|
|
9568
9076
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9569
|
-
|
|
9077
|
+
logger14.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9570
9078
|
return null;
|
|
9571
9079
|
});
|
|
9572
9080
|
if (!result?.buffer) {
|
|
9573
9081
|
return buffer.toString("base64");
|
|
9574
9082
|
}
|
|
9575
9083
|
if (result.withinLimit) {
|
|
9576
|
-
|
|
9084
|
+
logger14.info(
|
|
9577
9085
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9578
9086
|
);
|
|
9579
9087
|
} else {
|
|
9580
|
-
|
|
9088
|
+
logger14.warning(
|
|
9581
9089
|
`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}`
|
|
9582
9090
|
);
|
|
9583
9091
|
}
|
|
@@ -9585,7 +9093,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9585
9093
|
};
|
|
9586
9094
|
|
|
9587
9095
|
// src/share.js
|
|
9588
|
-
var
|
|
9096
|
+
var logger15 = createInternalLogger("Share");
|
|
9589
9097
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9590
9098
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9591
9099
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9722,7 +9230,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9722
9230
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9723
9231
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9724
9232
|
let matched = false;
|
|
9725
|
-
|
|
9233
|
+
logger15.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9726
9234
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9727
9235
|
mode,
|
|
9728
9236
|
onMutation: (context = {}) => {
|
|
@@ -9740,12 +9248,12 @@ ${text}`;
|
|
|
9740
9248
|
});
|
|
9741
9249
|
}
|
|
9742
9250
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9743
|
-
|
|
9251
|
+
logger15.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9744
9252
|
}
|
|
9745
9253
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9746
9254
|
if (!candidate) return;
|
|
9747
9255
|
matched = true;
|
|
9748
|
-
|
|
9256
|
+
logger15.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9749
9257
|
if (onMatch) {
|
|
9750
9258
|
onMatch({
|
|
9751
9259
|
link: candidate,
|
|
@@ -9761,7 +9269,7 @@ ${text}`;
|
|
|
9761
9269
|
return {
|
|
9762
9270
|
stop: async () => {
|
|
9763
9271
|
const result = await monitor.stop();
|
|
9764
|
-
|
|
9272
|
+
logger15.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9765
9273
|
return result;
|
|
9766
9274
|
}
|
|
9767
9275
|
};
|
|
@@ -9810,8 +9318,8 @@ var Share = {
|
|
|
9810
9318
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9811
9319
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9812
9320
|
}
|
|
9813
|
-
|
|
9814
|
-
|
|
9321
|
+
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9322
|
+
logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9815
9323
|
const stats = {
|
|
9816
9324
|
actionTimedOut: false,
|
|
9817
9325
|
domMutationCount: 0,
|
|
@@ -9823,7 +9331,7 @@ var Share = {
|
|
|
9823
9331
|
responseSampleUrls: []
|
|
9824
9332
|
};
|
|
9825
9333
|
if (isAborted()) {
|
|
9826
|
-
|
|
9334
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9827
9335
|
return {
|
|
9828
9336
|
link: null,
|
|
9829
9337
|
payloadText: "",
|
|
@@ -9846,7 +9354,7 @@ var Share = {
|
|
|
9846
9354
|
link: validated,
|
|
9847
9355
|
payloadText: String(payloadText || "")
|
|
9848
9356
|
};
|
|
9849
|
-
|
|
9357
|
+
logger15.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9850
9358
|
return true;
|
|
9851
9359
|
};
|
|
9852
9360
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9881,7 +9389,7 @@ var Share = {
|
|
|
9881
9389
|
try {
|
|
9882
9390
|
await monitor.stop();
|
|
9883
9391
|
} catch (error) {
|
|
9884
|
-
|
|
9392
|
+
logger15.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9885
9393
|
}
|
|
9886
9394
|
};
|
|
9887
9395
|
const onResponse = async (response) => {
|
|
@@ -9895,29 +9403,29 @@ var Share = {
|
|
|
9895
9403
|
stats.responseSampleUrls.push(url);
|
|
9896
9404
|
}
|
|
9897
9405
|
if (stats.responseObserved <= 5) {
|
|
9898
|
-
|
|
9406
|
+
logger15.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9899
9407
|
}
|
|
9900
9408
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9901
9409
|
stats.responseMatched += 1;
|
|
9902
9410
|
stats.lastMatchedUrl = url;
|
|
9903
|
-
|
|
9411
|
+
logger15.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9904
9412
|
const text = await response.text();
|
|
9905
9413
|
const hit = resolveResponseCandidate(text);
|
|
9906
9414
|
if (!hit?.link) {
|
|
9907
9415
|
if (stats.responseMatched <= 3) {
|
|
9908
|
-
|
|
9416
|
+
logger15.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9909
9417
|
}
|
|
9910
9418
|
return;
|
|
9911
9419
|
}
|
|
9912
9420
|
stats.responseResolved += 1;
|
|
9913
|
-
|
|
9421
|
+
logger15.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9914
9422
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9915
9423
|
} catch (error) {
|
|
9916
|
-
|
|
9424
|
+
logger15.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9917
9425
|
}
|
|
9918
9426
|
};
|
|
9919
9427
|
if (share.mode === "dom") {
|
|
9920
|
-
|
|
9428
|
+
logger15.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9921
9429
|
domMonitor = await createDomShareMonitor(page, {
|
|
9922
9430
|
prefix: share.prefix,
|
|
9923
9431
|
selectors: domSelectors,
|
|
@@ -9932,17 +9440,17 @@ var Share = {
|
|
|
9932
9440
|
});
|
|
9933
9441
|
}
|
|
9934
9442
|
if (share.mode === "response") {
|
|
9935
|
-
|
|
9443
|
+
logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9936
9444
|
page.on("response", onResponse);
|
|
9937
9445
|
}
|
|
9938
9446
|
if (share.mode === "custom") {
|
|
9939
|
-
|
|
9447
|
+
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9940
9448
|
}
|
|
9941
9449
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9942
9450
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9943
9451
|
try {
|
|
9944
9452
|
const actionTimeout = getRemainingMs();
|
|
9945
|
-
|
|
9453
|
+
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9946
9454
|
let actionValue;
|
|
9947
9455
|
if (!isAborted() && actionTimeout > 0) {
|
|
9948
9456
|
let timer = null;
|
|
@@ -9955,30 +9463,30 @@ var Share = {
|
|
|
9955
9463
|
]);
|
|
9956
9464
|
if (timer) clearTimeout(timer);
|
|
9957
9465
|
if (actionResult.type === "error") {
|
|
9958
|
-
|
|
9466
|
+
logger15.fail("captureLink.performActions", actionResult.error);
|
|
9959
9467
|
throw actionResult.error;
|
|
9960
9468
|
}
|
|
9961
9469
|
if (actionResult.type === "timeout") {
|
|
9962
9470
|
stats.actionTimedOut = true;
|
|
9963
|
-
|
|
9471
|
+
logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9964
9472
|
} else {
|
|
9965
9473
|
actionValue = actionResult.result;
|
|
9966
|
-
|
|
9474
|
+
logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9967
9475
|
}
|
|
9968
9476
|
}
|
|
9969
9477
|
if (share.mode === "custom") {
|
|
9970
9478
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9971
9479
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9972
9480
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9973
|
-
|
|
9481
|
+
logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9974
9482
|
} else {
|
|
9975
|
-
|
|
9483
|
+
logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9976
9484
|
}
|
|
9977
9485
|
}
|
|
9978
9486
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9979
9487
|
while (true) {
|
|
9980
9488
|
if (isAborted()) {
|
|
9981
|
-
|
|
9489
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9982
9490
|
return {
|
|
9983
9491
|
link: null,
|
|
9984
9492
|
payloadText: "",
|
|
@@ -9988,7 +9496,7 @@ var Share = {
|
|
|
9988
9496
|
}
|
|
9989
9497
|
const selected = candidates[share.mode];
|
|
9990
9498
|
if (selected?.link) {
|
|
9991
|
-
|
|
9499
|
+
logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9992
9500
|
return {
|
|
9993
9501
|
link: selected.link,
|
|
9994
9502
|
payloadText: selected.payloadText,
|
|
@@ -10001,19 +9509,19 @@ var Share = {
|
|
|
10001
9509
|
if (remaining <= 0) break;
|
|
10002
9510
|
const now = Date.now();
|
|
10003
9511
|
if (now >= nextProgressLogTs) {
|
|
10004
|
-
|
|
9512
|
+
logger15.info(
|
|
10005
9513
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
10006
9514
|
);
|
|
10007
9515
|
nextProgressLogTs = now + 5e3;
|
|
10008
9516
|
}
|
|
10009
|
-
await (0,
|
|
9517
|
+
await (0, import_delay4.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10010
9518
|
}
|
|
10011
9519
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10012
|
-
|
|
9520
|
+
logger15.warning(
|
|
10013
9521
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
10014
9522
|
);
|
|
10015
9523
|
}
|
|
10016
|
-
|
|
9524
|
+
logger15.warning(
|
|
10017
9525
|
`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"}`
|
|
10018
9526
|
);
|
|
10019
9527
|
return {
|
|
@@ -10025,7 +9533,7 @@ var Share = {
|
|
|
10025
9533
|
} finally {
|
|
10026
9534
|
if (share.mode === "response") {
|
|
10027
9535
|
page.off("response", onResponse);
|
|
10028
|
-
|
|
9536
|
+
logger15.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10029
9537
|
}
|
|
10030
9538
|
await stopDomMonitor();
|
|
10031
9539
|
}
|
|
@@ -10040,7 +9548,6 @@ var Share = {
|
|
|
10040
9548
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10041
9549
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10042
9550
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10043
|
-
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认 default
|
|
10044
9551
|
* @returns {Promise<string>} base64 image
|
|
10045
9552
|
*/
|
|
10046
9553
|
async captureScreen(page, options = {}) {
|
|
@@ -10061,9 +9568,7 @@ var Share = {
|
|
|
10061
9568
|
...screenshotWatermarkify,
|
|
10062
9569
|
capturedAt
|
|
10063
9570
|
});
|
|
10064
|
-
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page
|
|
10065
|
-
mode: options.mode
|
|
10066
|
-
});
|
|
9571
|
+
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page);
|
|
10067
9572
|
}
|
|
10068
9573
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
10069
9574
|
}
|
|
@@ -10071,9 +9576,8 @@ var Share = {
|
|
|
10071
9576
|
|
|
10072
9577
|
// entrys/node.js
|
|
10073
9578
|
Logger.setLogger(import_crawlee.log);
|
|
10074
|
-
var usePlaywrightToolKit = (
|
|
10075
|
-
|
|
10076
|
-
const toolkit = {
|
|
9579
|
+
var usePlaywrightToolKit = () => {
|
|
9580
|
+
return {
|
|
10077
9581
|
ApifyKit,
|
|
10078
9582
|
AntiCheat,
|
|
10079
9583
|
DeviceInput,
|
|
@@ -10093,7 +9597,6 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10093
9597
|
ByPass,
|
|
10094
9598
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
10095
9599
|
};
|
|
10096
|
-
return toolkit;
|
|
10097
9600
|
};
|
|
10098
9601
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10099
9602
|
0 && (module.exports = {
|