@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.js
CHANGED
|
@@ -13,11 +13,9 @@ __export(constants_exports, {
|
|
|
13
13
|
ActorInfo: () => ActorInfo,
|
|
14
14
|
Code: () => Code,
|
|
15
15
|
Device: () => Device,
|
|
16
|
-
Mode: () => Mode,
|
|
17
16
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
18
17
|
Status: () => Status,
|
|
19
|
-
normalizeDevice: () => normalizeDevice
|
|
20
|
-
normalizeMode: () => normalizeMode
|
|
18
|
+
normalizeDevice: () => normalizeDevice
|
|
21
19
|
});
|
|
22
20
|
var Code = {
|
|
23
21
|
Success: 0,
|
|
@@ -37,10 +35,6 @@ var Device = Object.freeze({
|
|
|
37
35
|
Desktop: "desktop",
|
|
38
36
|
Mobile: "mobile"
|
|
39
37
|
});
|
|
40
|
-
var Mode = Object.freeze({
|
|
41
|
-
Default: "default",
|
|
42
|
-
Cloak: "cloak"
|
|
43
|
-
});
|
|
44
38
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
45
39
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
46
40
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -48,13 +42,6 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
48
42
|
if (raw === Device.Desktop) return Device.Desktop;
|
|
49
43
|
return normalizedFallback;
|
|
50
44
|
};
|
|
51
|
-
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
52
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
53
|
-
const raw = String(value || "").trim().toLowerCase();
|
|
54
|
-
if (raw === Mode.Cloak) return Mode.Cloak;
|
|
55
|
-
if (raw === Mode.Default) return Mode.Default;
|
|
56
|
-
return normalizedFallback;
|
|
57
|
-
};
|
|
58
45
|
var createActorInfo = (info) => {
|
|
59
46
|
const normalizeDomain = (value) => {
|
|
60
47
|
if (!value) return "";
|
|
@@ -122,6 +109,7 @@ var createActorInfo = (info) => {
|
|
|
122
109
|
const buildLandingUrl = ({ protocol: protocol2, domain: domain2, path: path4 }) => {
|
|
123
110
|
const safeProtocol = String(protocol2).trim();
|
|
124
111
|
const safeDomain = normalizeDomain(domain2);
|
|
112
|
+
if (!safeDomain) return "";
|
|
125
113
|
const safePath = normalizePath(path4);
|
|
126
114
|
return `${safeProtocol}://${safeDomain}${safePath}`;
|
|
127
115
|
};
|
|
@@ -329,6 +317,18 @@ var ActorInfo = {
|
|
|
329
317
|
prefix: "",
|
|
330
318
|
xurl: []
|
|
331
319
|
}
|
|
320
|
+
}),
|
|
321
|
+
// 通用网页抓取 Actor:入口 URL 来自 query,因此这里只声明统一的 Actor 元信息。
|
|
322
|
+
webpage: createActorInfo({
|
|
323
|
+
key: "webpage",
|
|
324
|
+
name: "\u901A\u7528\u7F51\u9875",
|
|
325
|
+
domain: "",
|
|
326
|
+
path: "/",
|
|
327
|
+
share: {
|
|
328
|
+
mode: "dom",
|
|
329
|
+
prefix: "",
|
|
330
|
+
xurl: []
|
|
331
|
+
}
|
|
332
332
|
})
|
|
333
333
|
};
|
|
334
334
|
|
|
@@ -360,18 +360,18 @@ var fallbackLog = {
|
|
|
360
360
|
error: (...args) => console.error(...args),
|
|
361
361
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
362
362
|
};
|
|
363
|
-
var resolveLogMethod = (
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
363
|
+
var resolveLogMethod = (logger16, name) => {
|
|
364
|
+
if (logger16 && typeof logger16[name] === "function") {
|
|
365
|
+
return logger16[name].bind(logger16);
|
|
366
366
|
}
|
|
367
|
-
if (name === "warning" &&
|
|
368
|
-
return
|
|
367
|
+
if (name === "warning" && logger16 && typeof logger16.warn === "function") {
|
|
368
|
+
return logger16.warn.bind(logger16);
|
|
369
369
|
}
|
|
370
370
|
return fallbackLog[name];
|
|
371
371
|
};
|
|
372
372
|
var defaultLogger = null;
|
|
373
|
-
var setDefaultLogger = (
|
|
374
|
-
defaultLogger =
|
|
373
|
+
var setDefaultLogger = (logger16) => {
|
|
374
|
+
defaultLogger = logger16;
|
|
375
375
|
};
|
|
376
376
|
var resolveLogger = (explicitLogger) => {
|
|
377
377
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -398,8 +398,8 @@ var colorize = (text, color) => {
|
|
|
398
398
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
399
399
|
const name = prefix ? String(prefix) : "";
|
|
400
400
|
const dispatch = (methodName, icon, message, color) => {
|
|
401
|
-
const
|
|
402
|
-
const logFn = resolveLogMethod(
|
|
401
|
+
const logger16 = resolveLogger(explicitLogger);
|
|
402
|
+
const logFn = resolveLogMethod(logger16, methodName);
|
|
403
403
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
404
404
|
const line = formatLine(name, icon, message);
|
|
405
405
|
const coloredLine = colorize(line, color);
|
|
@@ -753,7 +753,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
753
753
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
754
754
|
return 0;
|
|
755
755
|
}
|
|
756
|
-
const
|
|
756
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
757
757
|
const isVisible = (el, style, rect) => {
|
|
758
758
|
if (!el || !style || !rect) return false;
|
|
759
759
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -793,7 +793,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
793
793
|
return true;
|
|
794
794
|
});
|
|
795
795
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
796
|
-
if (!
|
|
796
|
+
if (!hasOwn(el.dataset, "pkAffixedAdjusted")) {
|
|
797
797
|
el.dataset.pkAffixedAdjusted = "1";
|
|
798
798
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
799
799
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -824,7 +824,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
824
824
|
};
|
|
825
825
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
826
826
|
await page.evaluate((className) => {
|
|
827
|
-
const
|
|
827
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
828
828
|
const expansionKeys = [
|
|
829
829
|
"pkOrigOverflow",
|
|
830
830
|
"pkOrigHeight",
|
|
@@ -832,28 +832,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
832
832
|
"pkOrigMaxHeight"
|
|
833
833
|
];
|
|
834
834
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
835
|
-
if (
|
|
835
|
+
if (hasOwn(el.dataset, "pkOrigPosition")) {
|
|
836
836
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
837
837
|
delete el.dataset.pkOrigPosition;
|
|
838
838
|
delete el.dataset.pkOrigPositionPriority;
|
|
839
839
|
}
|
|
840
|
-
if (
|
|
840
|
+
if (hasOwn(el.dataset, "pkOrigTop")) {
|
|
841
841
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
842
842
|
delete el.dataset.pkOrigTop;
|
|
843
843
|
delete el.dataset.pkOrigTopPriority;
|
|
844
844
|
}
|
|
845
|
-
if (
|
|
845
|
+
if (hasOwn(el.dataset, "pkOrigBottom")) {
|
|
846
846
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
847
847
|
delete el.dataset.pkOrigBottom;
|
|
848
848
|
delete el.dataset.pkOrigBottomPriority;
|
|
849
849
|
}
|
|
850
|
-
if (
|
|
850
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
851
851
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
852
852
|
delete el.dataset.pkOrigTranslate;
|
|
853
853
|
delete el.dataset.pkOrigTranslatePriority;
|
|
854
854
|
}
|
|
855
855
|
delete el.dataset.pkAffixedAdjusted;
|
|
856
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
856
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
857
857
|
if (!stillExpanded) {
|
|
858
858
|
el.classList.remove(className);
|
|
859
859
|
}
|
|
@@ -896,7 +896,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
896
896
|
viewportResized
|
|
897
897
|
};
|
|
898
898
|
};
|
|
899
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
899
|
+
var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
900
900
|
await page.evaluate((className) => {
|
|
901
901
|
const targets = new Set([
|
|
902
902
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -920,8 +920,8 @@ var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
|
920
920
|
el.classList.remove(className);
|
|
921
921
|
});
|
|
922
922
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
923
|
-
if (
|
|
924
|
-
await page.setViewportSize(
|
|
923
|
+
if (state?.originalViewport && state?.viewportResized) {
|
|
924
|
+
await page.setViewportSize(state.originalViewport);
|
|
925
925
|
}
|
|
926
926
|
};
|
|
927
927
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -978,21 +978,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
978
978
|
}
|
|
979
979
|
};
|
|
980
980
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
981
|
-
const
|
|
981
|
+
const state = await prepareExpandedFullPageScreenshot(page, options);
|
|
982
982
|
try {
|
|
983
983
|
return await capturePageScreenshot(page, {
|
|
984
984
|
fullPage: true,
|
|
985
985
|
type: options.type || "png",
|
|
986
986
|
quality: options.quality,
|
|
987
987
|
timeout: options.timeout,
|
|
988
|
-
maxClipHeight:
|
|
988
|
+
maxClipHeight: state.targetHeight
|
|
989
989
|
});
|
|
990
990
|
} finally {
|
|
991
991
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
992
992
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
993
993
|
});
|
|
994
994
|
if (options.restore) {
|
|
995
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
995
|
+
await restoreExpandedFullPageScreenshot(page, state);
|
|
996
996
|
}
|
|
997
997
|
}
|
|
998
998
|
};
|
|
@@ -1910,8 +1910,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1910
1910
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1911
1911
|
};
|
|
1912
1912
|
};
|
|
1913
|
-
var rememberRuntimeState = (
|
|
1914
|
-
rememberedRuntimeState = deepClone(
|
|
1913
|
+
var rememberRuntimeState = (state) => {
|
|
1914
|
+
rememberedRuntimeState = deepClone(state);
|
|
1915
1915
|
return rememberedRuntimeState;
|
|
1916
1916
|
};
|
|
1917
1917
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1970,7 +1970,7 @@ var RuntimeEnv = {
|
|
|
1970
1970
|
} else {
|
|
1971
1971
|
delete normalizedRuntime.browser_profile;
|
|
1972
1972
|
}
|
|
1973
|
-
const
|
|
1973
|
+
const state = {
|
|
1974
1974
|
actor: resolvedActor,
|
|
1975
1975
|
device,
|
|
1976
1976
|
runtime: normalizedRuntime,
|
|
@@ -1984,73 +1984,73 @@ var RuntimeEnv = {
|
|
|
1984
1984
|
browserProfileCore: browserProfile.core,
|
|
1985
1985
|
browserProfileObserved: browserProfile.observed
|
|
1986
1986
|
};
|
|
1987
|
-
rememberRuntimeState(
|
|
1988
|
-
return
|
|
1987
|
+
rememberRuntimeState(state);
|
|
1988
|
+
return state;
|
|
1989
1989
|
},
|
|
1990
1990
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
1991
1991
|
buildEnvPatch(source = {}, actor = "") {
|
|
1992
|
-
const
|
|
1993
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
1992
|
+
const state = normalizeRuntimeState(source, actor);
|
|
1993
|
+
const browserProfile = buildBrowserProfilePayload(state.browserProfileCore, state.browserProfileObserved);
|
|
1994
1994
|
const envPatch = {
|
|
1995
|
-
...Array.isArray(
|
|
1996
|
-
...Object.keys(
|
|
1997
|
-
...Object.keys(
|
|
1995
|
+
...Array.isArray(state.cookies) && state.cookies.length > 0 ? { cookies: state.cookies } : {},
|
|
1996
|
+
...Object.keys(state.localStorage || {}).length > 0 ? { local_storage: state.localStorage } : {},
|
|
1997
|
+
...Object.keys(state.sessionStorage || {}).length > 0 ? { session_storage: state.sessionStorage } : {},
|
|
1998
1998
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
1999
1999
|
};
|
|
2000
2000
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
2001
2001
|
},
|
|
2002
2002
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
2003
2003
|
hasLoginState(source = {}, actor = "") {
|
|
2004
|
-
const
|
|
2005
|
-
return isPlainObject(
|
|
2004
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2005
|
+
return isPlainObject(state.runtime) && Object.keys(state.runtime || {}).length > 0;
|
|
2006
2006
|
},
|
|
2007
2007
|
rememberState(source = {}) {
|
|
2008
|
-
const
|
|
2009
|
-
rememberRuntimeState(
|
|
2008
|
+
const state = normalizeRuntimeState(source);
|
|
2009
|
+
rememberRuntimeState(state);
|
|
2010
2010
|
return RuntimeEnv.peekRememberedState();
|
|
2011
2011
|
},
|
|
2012
2012
|
peekRememberedState() {
|
|
2013
2013
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
2014
2014
|
},
|
|
2015
2015
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
2016
|
-
const
|
|
2017
|
-
return deepClone(
|
|
2016
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2017
|
+
return deepClone(state.browserProfileCore || {});
|
|
2018
2018
|
},
|
|
2019
2019
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
2020
|
-
const
|
|
2020
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2021
2021
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
2022
2022
|
...core,
|
|
2023
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2023
|
+
device: normalizeKnownDevice(core?.device) || state.device
|
|
2024
2024
|
});
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
if (Object.keys(
|
|
2028
|
-
|
|
2025
|
+
state.browserProfileCore = normalizedCore;
|
|
2026
|
+
state.browserProfile = buildBrowserProfilePayload(normalizedCore, state.browserProfileObserved);
|
|
2027
|
+
if (Object.keys(state.browserProfile).length > 0) {
|
|
2028
|
+
state.runtime.browser_profile = state.browserProfile;
|
|
2029
2029
|
} else {
|
|
2030
|
-
delete
|
|
2030
|
+
delete state.runtime.browser_profile;
|
|
2031
2031
|
}
|
|
2032
|
-
rememberRuntimeState(
|
|
2033
|
-
return
|
|
2032
|
+
rememberRuntimeState(state);
|
|
2033
|
+
return state;
|
|
2034
2034
|
},
|
|
2035
2035
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2036
2036
|
// cookies / localStorage / sessionStorage。
|
|
2037
2037
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2038
2038
|
async applyToPage(page, source = {}, options = {}) {
|
|
2039
2039
|
if (!page) return;
|
|
2040
|
-
let
|
|
2040
|
+
let state = normalizeRuntimeState(source, options?.actor || "");
|
|
2041
2041
|
if (typeof options?.preapply === "function") {
|
|
2042
|
-
|
|
2043
|
-
rememberRuntimeState(
|
|
2042
|
+
state = await options.preapply(state) || state;
|
|
2043
|
+
rememberRuntimeState(state);
|
|
2044
2044
|
}
|
|
2045
2045
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2046
2046
|
configurable: true,
|
|
2047
2047
|
enumerable: false,
|
|
2048
2048
|
writable: true,
|
|
2049
|
-
value:
|
|
2049
|
+
value: state
|
|
2050
2050
|
});
|
|
2051
|
-
const localStorage =
|
|
2052
|
-
const sessionStorage =
|
|
2053
|
-
const cookies = (
|
|
2051
|
+
const localStorage = state.localStorage || {};
|
|
2052
|
+
const sessionStorage = state.sessionStorage || {};
|
|
2053
|
+
const cookies = (state.cookies || []).map((cookie) => {
|
|
2054
2054
|
const normalized = { ...cookie };
|
|
2055
2055
|
if (!normalized.path) {
|
|
2056
2056
|
normalized.path = "/";
|
|
@@ -2088,8 +2088,8 @@ var RuntimeEnv = {
|
|
|
2088
2088
|
},
|
|
2089
2089
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2090
2090
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2091
|
-
const
|
|
2092
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2091
|
+
const state = normalizeRuntimeState(source, options?.actor || "");
|
|
2092
|
+
const baseline = RuntimeEnv.buildEnvPatch(state) || {};
|
|
2093
2093
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2094
2094
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2095
2095
|
}
|
|
@@ -2108,7 +2108,7 @@ var RuntimeEnv = {
|
|
|
2108
2108
|
cookies
|
|
2109
2109
|
},
|
|
2110
2110
|
{
|
|
2111
|
-
browserProfileCore:
|
|
2111
|
+
browserProfileCore: state.browserProfileCore
|
|
2112
2112
|
}
|
|
2113
2113
|
);
|
|
2114
2114
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2122,11 +2122,11 @@ var RuntimeEnv = {
|
|
|
2122
2122
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2123
2123
|
var resolveRuntimeContext = (input) => {
|
|
2124
2124
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2125
|
-
const
|
|
2126
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2125
|
+
const state = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2126
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state) || null;
|
|
2127
2127
|
return {
|
|
2128
|
-
actor:
|
|
2129
|
-
runtime:
|
|
2128
|
+
actor: state.actor,
|
|
2129
|
+
runtime: state.runtime,
|
|
2130
2130
|
envPatch
|
|
2131
2131
|
};
|
|
2132
2132
|
};
|
|
@@ -2485,82 +2485,8 @@ var Utils = {
|
|
|
2485
2485
|
}
|
|
2486
2486
|
};
|
|
2487
2487
|
|
|
2488
|
-
// src/
|
|
2489
|
-
var
|
|
2490
|
-
mode: Mode.Default
|
|
2491
|
-
};
|
|
2492
|
-
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2493
|
-
var ToolkitContext = {
|
|
2494
|
-
get mode() {
|
|
2495
|
-
return state.mode;
|
|
2496
|
-
},
|
|
2497
|
-
setMode(mode = Mode.Default) {
|
|
2498
|
-
state.mode = normalizeMode(mode, Mode.Default);
|
|
2499
|
-
return state.mode;
|
|
2500
|
-
}
|
|
2501
|
-
};
|
|
2502
|
-
var getToolkitMode = () => state.mode;
|
|
2503
|
-
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2504
|
-
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2505
|
-
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2506
|
-
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2507
|
-
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2508
|
-
return {
|
|
2509
|
-
mode: normalizedMode,
|
|
2510
|
-
strategy
|
|
2511
|
-
};
|
|
2512
|
-
};
|
|
2513
|
-
|
|
2514
|
-
// src/internals/reflect.js
|
|
2515
|
-
var normalizeStrategies2 = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2516
|
-
var collectFunctionNames = (strategies = []) => {
|
|
2517
|
-
const names = /* @__PURE__ */ new Set();
|
|
2518
|
-
for (const strategy of strategies) {
|
|
2519
|
-
if (!strategy || typeof strategy !== "object") continue;
|
|
2520
|
-
for (const name of Reflect.ownKeys(strategy)) {
|
|
2521
|
-
if (typeof name === "string" && typeof strategy[name] === "function") {
|
|
2522
|
-
names.add(name);
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
}
|
|
2526
|
-
return names;
|
|
2527
|
-
};
|
|
2528
|
-
var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
2529
|
-
enumerable: true,
|
|
2530
|
-
configurable: true,
|
|
2531
|
-
writable: true,
|
|
2532
|
-
value: (...args) => {
|
|
2533
|
-
const { mode, strategy } = resolveTarget(args);
|
|
2534
|
-
const method = strategy?.[name];
|
|
2535
|
-
if (typeof method !== "function") {
|
|
2536
|
-
throw new Error(`${namespace}.${name} is not available in ${mode} mode`);
|
|
2537
|
-
}
|
|
2538
|
-
return method.apply(strategy, args);
|
|
2539
|
-
}
|
|
2540
|
-
});
|
|
2541
|
-
var withModeReflect = (namespace, strategies = {}) => {
|
|
2542
|
-
const normalizedStrategies = normalizeStrategies2(strategies);
|
|
2543
|
-
const baseStrategy = normalizedStrategies.default ?? Object.values(normalizedStrategies).find(Boolean);
|
|
2544
|
-
const names = collectFunctionNames([baseStrategy]);
|
|
2545
|
-
const descriptors = {};
|
|
2546
|
-
for (const name of names) {
|
|
2547
|
-
descriptors[name] = methodDescriptor(namespace, name, () => resolveModeStrategy(normalizedStrategies));
|
|
2548
|
-
}
|
|
2549
|
-
return Object.defineProperties({}, descriptors);
|
|
2550
|
-
};
|
|
2551
|
-
var withPageReflect = (namespace, resolveStrategy, strategies = []) => {
|
|
2552
|
-
const names = collectFunctionNames(strategies);
|
|
2553
|
-
const descriptors = {};
|
|
2554
|
-
for (const name of names) {
|
|
2555
|
-
descriptors[name] = methodDescriptor(namespace, name, ([page]) => ({
|
|
2556
|
-
mode: "page",
|
|
2557
|
-
strategy: resolveStrategy(page)
|
|
2558
|
-
}));
|
|
2559
|
-
}
|
|
2560
|
-
return Object.defineProperties({}, descriptors);
|
|
2561
|
-
};
|
|
2562
|
-
|
|
2563
|
-
// src/internals/anti-cheat/default.js
|
|
2488
|
+
// src/anti-cheat.js
|
|
2489
|
+
var logger5 = createInternalLogger("AntiCheat");
|
|
2564
2490
|
var BASE_CONFIG = Object.freeze({
|
|
2565
2491
|
locale: "zh-CN",
|
|
2566
2492
|
acceptLanguage: "zh-CN,zh;q=0.9",
|
|
@@ -2595,7 +2521,7 @@ function buildFingerprintOptions({ locale = BASE_CONFIG.locale, browserMajorVers
|
|
|
2595
2521
|
}
|
|
2596
2522
|
return options;
|
|
2597
2523
|
}
|
|
2598
|
-
var
|
|
2524
|
+
var AntiCheat = {
|
|
2599
2525
|
/**
|
|
2600
2526
|
* 获取统一的基础配置
|
|
2601
2527
|
*/
|
|
@@ -2632,47 +2558,6 @@ var DefaultAntiCheat = {
|
|
|
2632
2558
|
}
|
|
2633
2559
|
};
|
|
2634
2560
|
|
|
2635
|
-
// src/internals/anti-cheat/cloak.js
|
|
2636
|
-
var CLOAK_BASE_CONFIG = Object.freeze({
|
|
2637
|
-
locale: "",
|
|
2638
|
-
acceptLanguage: "",
|
|
2639
|
-
timezoneId: "",
|
|
2640
|
-
timezoneOffset: null,
|
|
2641
|
-
geolocation: null
|
|
2642
|
-
});
|
|
2643
|
-
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2644
|
-
var CloakAntiCheat = {
|
|
2645
|
-
/**
|
|
2646
|
-
* Cloak 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2647
|
-
*/
|
|
2648
|
-
getBaseConfig() {
|
|
2649
|
-
return { ...CLOAK_BASE_CONFIG };
|
|
2650
|
-
},
|
|
2651
|
-
getFingerprintGeneratorOptions() {
|
|
2652
|
-
return {};
|
|
2653
|
-
},
|
|
2654
|
-
getLaunchArgs() {
|
|
2655
|
-
return [];
|
|
2656
|
-
},
|
|
2657
|
-
getTlsFingerprintOptions() {
|
|
2658
|
-
return {};
|
|
2659
|
-
},
|
|
2660
|
-
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2661
|
-
const normalizedHeaders = normalizeHeaders(headers);
|
|
2662
|
-
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2663
|
-
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2664
|
-
}
|
|
2665
|
-
return normalizedHeaders;
|
|
2666
|
-
}
|
|
2667
|
-
};
|
|
2668
|
-
|
|
2669
|
-
// src/anti-cheat.js
|
|
2670
|
-
var antiCheatStrategies = {
|
|
2671
|
-
[Mode.Default]: DefaultAntiCheat,
|
|
2672
|
-
[Mode.Cloak]: CloakAntiCheat
|
|
2673
|
-
};
|
|
2674
|
-
var AntiCheat = withModeReflect("AntiCheat", antiCheatStrategies);
|
|
2675
|
-
|
|
2676
2561
|
// src/device-input.js
|
|
2677
2562
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2678
2563
|
var assertPage = (page, method) => {
|
|
@@ -3072,12 +2957,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
3072
2957
|
}
|
|
3073
2958
|
return resolved;
|
|
3074
2959
|
};
|
|
3075
|
-
var attachRuntimeState = (page,
|
|
2960
|
+
var attachRuntimeState = (page, state) => {
|
|
3076
2961
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
3077
2962
|
configurable: true,
|
|
3078
2963
|
enumerable: false,
|
|
3079
2964
|
writable: true,
|
|
3080
|
-
value:
|
|
2965
|
+
value: state
|
|
3081
2966
|
});
|
|
3082
2967
|
};
|
|
3083
2968
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -3223,13 +3108,10 @@ var DeviceView = {
|
|
|
3223
3108
|
}
|
|
3224
3109
|
};
|
|
3225
3110
|
|
|
3226
|
-
// src/internals/humanize/index.js
|
|
3227
|
-
import delay4 from "delay";
|
|
3228
|
-
|
|
3229
3111
|
// src/internals/humanize/desktop.js
|
|
3230
3112
|
import delay2 from "delay";
|
|
3231
3113
|
import { createCursor } from "ghost-cursor-playwright";
|
|
3232
|
-
var
|
|
3114
|
+
var logger6 = createInternalLogger("Humanize");
|
|
3233
3115
|
var $CursorWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3234
3116
|
function $GetCursor(page) {
|
|
3235
3117
|
const cursor = $CursorWeakMap.get(page);
|
|
@@ -3257,13 +3139,13 @@ var Humanize = {
|
|
|
3257
3139
|
*/
|
|
3258
3140
|
async initializeCursor(page) {
|
|
3259
3141
|
if ($CursorWeakMap.has(page)) {
|
|
3260
|
-
|
|
3142
|
+
logger6.debug("initializeCursor: cursor already exists, skipping");
|
|
3261
3143
|
return;
|
|
3262
3144
|
}
|
|
3263
|
-
|
|
3145
|
+
logger6.start("initializeCursor", "creating cursor");
|
|
3264
3146
|
const cursor = await createCursor(page);
|
|
3265
3147
|
$CursorWeakMap.set(page, cursor);
|
|
3266
|
-
|
|
3148
|
+
logger6.success("initializeCursor", "cursor initialized");
|
|
3267
3149
|
},
|
|
3268
3150
|
/**
|
|
3269
3151
|
* 人类化鼠标移动 - 使用 ghost-cursor 移动到指定位置或元素
|
|
@@ -3273,17 +3155,17 @@ var Humanize = {
|
|
|
3273
3155
|
*/
|
|
3274
3156
|
async humanMove(page, target) {
|
|
3275
3157
|
const cursor = $GetCursor(page);
|
|
3276
|
-
|
|
3158
|
+
logger6.start("humanMove", `target=${typeof target === "string" ? target : "element/coords"}`);
|
|
3277
3159
|
try {
|
|
3278
3160
|
if (typeof target === "string") {
|
|
3279
3161
|
const element = await page.$(target);
|
|
3280
3162
|
if (!element) {
|
|
3281
|
-
|
|
3163
|
+
logger6.warn(`humanMove: \u5143\u7D20\u4E0D\u5B58\u5728 ${target}`);
|
|
3282
3164
|
return false;
|
|
3283
3165
|
}
|
|
3284
3166
|
const box = await element.boundingBox();
|
|
3285
3167
|
if (!box) {
|
|
3286
|
-
|
|
3168
|
+
logger6.warn(`humanMove: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E ${target}`);
|
|
3287
3169
|
return false;
|
|
3288
3170
|
}
|
|
3289
3171
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.2;
|
|
@@ -3299,10 +3181,10 @@ var Humanize = {
|
|
|
3299
3181
|
await cursor.actions.move({ x, y });
|
|
3300
3182
|
}
|
|
3301
3183
|
}
|
|
3302
|
-
|
|
3184
|
+
logger6.success("humanMove");
|
|
3303
3185
|
return true;
|
|
3304
3186
|
} catch (error) {
|
|
3305
|
-
|
|
3187
|
+
logger6.fail("humanMove", error);
|
|
3306
3188
|
throw error;
|
|
3307
3189
|
}
|
|
3308
3190
|
},
|
|
@@ -3326,12 +3208,12 @@ var Humanize = {
|
|
|
3326
3208
|
maxDurationMs = maxSteps * 220 + 800
|
|
3327
3209
|
} = options;
|
|
3328
3210
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
3329
|
-
|
|
3211
|
+
logger6.start("humanScroll", `target=${targetDesc}`);
|
|
3330
3212
|
let element;
|
|
3331
3213
|
if (typeof target === "string") {
|
|
3332
3214
|
element = await page.$(target);
|
|
3333
3215
|
if (!element) {
|
|
3334
|
-
|
|
3216
|
+
logger6.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${target}`);
|
|
3335
3217
|
return { element: null, didScroll: false };
|
|
3336
3218
|
}
|
|
3337
3219
|
} else {
|
|
@@ -3406,26 +3288,26 @@ var Humanize = {
|
|
|
3406
3288
|
try {
|
|
3407
3289
|
for (let i = 0; i < maxSteps; i++) {
|
|
3408
3290
|
if (Date.now() - startTime > maxDurationMs) {
|
|
3409
|
-
|
|
3291
|
+
logger6.warn(`humanScroll | \u8D85\u65F6\u4FDD\u62A4\u89E6\u53D1 (${maxDurationMs}ms)`);
|
|
3410
3292
|
return { element, didScroll };
|
|
3411
3293
|
}
|
|
3412
3294
|
const status = await checkVisibility();
|
|
3413
3295
|
if (status.code === "VISIBLE") {
|
|
3414
3296
|
if (status.isFixed) {
|
|
3415
|
-
|
|
3297
|
+
logger6.info("humanScroll | fixed \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3416
3298
|
} else {
|
|
3417
|
-
|
|
3299
|
+
logger6.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
3418
3300
|
}
|
|
3419
|
-
|
|
3301
|
+
logger6.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
3420
3302
|
return { element, didScroll };
|
|
3421
3303
|
}
|
|
3422
|
-
|
|
3304
|
+
logger6.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason} ${status.direction ? `(${status.direction})` : ""}`);
|
|
3423
3305
|
if (status.code === "OBSTRUCTED" && status.obstruction) {
|
|
3424
|
-
|
|
3306
|
+
logger6.debug(`humanScroll | \u88AB\u4EE5\u4E0B\u5143\u7D20\u906E\u6321 <${status.obstruction.tag} id="${status.obstruction.id}">`);
|
|
3425
3307
|
}
|
|
3426
3308
|
const scrollRect = await getScrollableRect2();
|
|
3427
3309
|
if (!scrollRect && status.isFixed) {
|
|
3428
|
-
|
|
3310
|
+
logger6.warn("humanScroll | fixed \u5BB9\u5668\u5185\u4E14\u65E0\u53EF\u6EDA\u52A8\u7956\u5148\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3429
3311
|
return { element, didScroll };
|
|
3430
3312
|
}
|
|
3431
3313
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
@@ -3461,10 +3343,10 @@ var Humanize = {
|
|
|
3461
3343
|
didScroll = true;
|
|
3462
3344
|
await delay2(this.jitterMs(20 + Math.random() * 40, 0.2));
|
|
3463
3345
|
}
|
|
3464
|
-
|
|
3346
|
+
logger6.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
3465
3347
|
return { element, didScroll };
|
|
3466
3348
|
} catch (error) {
|
|
3467
|
-
|
|
3349
|
+
logger6.fail("humanScroll", error);
|
|
3468
3350
|
throw error;
|
|
3469
3351
|
}
|
|
3470
3352
|
},
|
|
@@ -3482,7 +3364,7 @@ var Humanize = {
|
|
|
3482
3364
|
const cursor = $GetCursor(page);
|
|
3483
3365
|
const { reactionDelay = 250, throwOnMissing = true, scrollIfNeeded = true, restore = false } = options;
|
|
3484
3366
|
const targetDesc = target == null ? "Current Position" : typeof target === "string" ? target : "ElementHandle";
|
|
3485
|
-
|
|
3367
|
+
logger6.start("humanClick", `target=${targetDesc}`);
|
|
3486
3368
|
const restoreOnce = async () => {
|
|
3487
3369
|
if (restoreOnce.restored) return;
|
|
3488
3370
|
restoreOnce.restored = true;
|
|
@@ -3491,14 +3373,14 @@ var Humanize = {
|
|
|
3491
3373
|
await delay2(this.jitterMs(1e3));
|
|
3492
3374
|
await restoreOnce.do();
|
|
3493
3375
|
} catch (restoreError) {
|
|
3494
|
-
|
|
3376
|
+
logger6.warn(`humanClick: \u6062\u590D\u6EDA\u52A8\u4F4D\u7F6E\u5931\u8D25: ${restoreError.message}`);
|
|
3495
3377
|
}
|
|
3496
3378
|
};
|
|
3497
3379
|
try {
|
|
3498
3380
|
if (target == null) {
|
|
3499
3381
|
await delay2(this.jitterMs(reactionDelay, 0.4));
|
|
3500
3382
|
await cursor.actions.click();
|
|
3501
|
-
|
|
3383
|
+
logger6.success("humanClick", "Clicked current position");
|
|
3502
3384
|
return true;
|
|
3503
3385
|
}
|
|
3504
3386
|
let element;
|
|
@@ -3508,7 +3390,7 @@ var Humanize = {
|
|
|
3508
3390
|
if (throwOnMissing) {
|
|
3509
3391
|
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${target}`);
|
|
3510
3392
|
}
|
|
3511
|
-
|
|
3393
|
+
logger6.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${target}`);
|
|
3512
3394
|
return false;
|
|
3513
3395
|
}
|
|
3514
3396
|
} else {
|
|
@@ -3524,7 +3406,7 @@ var Humanize = {
|
|
|
3524
3406
|
if (throwOnMissing) {
|
|
3525
3407
|
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
3526
3408
|
}
|
|
3527
|
-
|
|
3409
|
+
logger6.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
3528
3410
|
return false;
|
|
3529
3411
|
}
|
|
3530
3412
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.3;
|
|
@@ -3533,11 +3415,11 @@ var Humanize = {
|
|
|
3533
3415
|
await delay2(this.jitterMs(reactionDelay, 0.4));
|
|
3534
3416
|
await cursor.actions.click();
|
|
3535
3417
|
await restoreOnce();
|
|
3536
|
-
|
|
3418
|
+
logger6.success("humanClick");
|
|
3537
3419
|
return true;
|
|
3538
3420
|
} catch (error) {
|
|
3539
3421
|
await restoreOnce();
|
|
3540
|
-
|
|
3422
|
+
logger6.fail("humanClick", error);
|
|
3541
3423
|
throw error;
|
|
3542
3424
|
}
|
|
3543
3425
|
},
|
|
@@ -3548,9 +3430,9 @@ var Humanize = {
|
|
|
3548
3430
|
*/
|
|
3549
3431
|
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
3550
3432
|
const ms = this.jitterMs(baseMs, jitterPercent);
|
|
3551
|
-
|
|
3433
|
+
logger6.start("randomSleep", `base=${baseMs}, actual=${ms}ms`);
|
|
3552
3434
|
await delay2(ms);
|
|
3553
|
-
|
|
3435
|
+
logger6.success("randomSleep");
|
|
3554
3436
|
},
|
|
3555
3437
|
/**
|
|
3556
3438
|
* 模拟人类"注视"或"阅读"行为:鼠标在页面上随机微动
|
|
@@ -3560,7 +3442,7 @@ var Humanize = {
|
|
|
3560
3442
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
3561
3443
|
const cursor = $GetCursor(page);
|
|
3562
3444
|
const durationMs = this.jitterMs(baseDurationMs, 0.4);
|
|
3563
|
-
|
|
3445
|
+
logger6.start("simulateGaze", `duration=${durationMs}ms`);
|
|
3564
3446
|
const startTime = Date.now();
|
|
3565
3447
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3566
3448
|
while (Date.now() - startTime < durationMs) {
|
|
@@ -3569,7 +3451,7 @@ var Humanize = {
|
|
|
3569
3451
|
await cursor.actions.move({ x, y });
|
|
3570
3452
|
await delay2(this.jitterMs(600, 0.5));
|
|
3571
3453
|
}
|
|
3572
|
-
|
|
3454
|
+
logger6.success("simulateGaze");
|
|
3573
3455
|
},
|
|
3574
3456
|
/**
|
|
3575
3457
|
* 人类化输入 - 带节奏变化(快-慢-停顿-偶尔加速)
|
|
@@ -3582,7 +3464,7 @@ var Humanize = {
|
|
|
3582
3464
|
* @param {number} [options.pauseBase=800] - 停顿时长基础值 (ms),实际 ±50% 抖动
|
|
3583
3465
|
*/
|
|
3584
3466
|
async humanType(page, selector, text, options = {}) {
|
|
3585
|
-
|
|
3467
|
+
logger6.start("humanType", `selector=${selector}, textLen=${text.length}`);
|
|
3586
3468
|
const {
|
|
3587
3469
|
baseDelay = 180,
|
|
3588
3470
|
pauseProbability = 0.08,
|
|
@@ -3606,13 +3488,13 @@ var Humanize = {
|
|
|
3606
3488
|
await delay2(charDelay);
|
|
3607
3489
|
if (Math.random() < pauseProbability && i < text.length - 1) {
|
|
3608
3490
|
const pauseTime = this.jitterMs(pauseBase, 0.5);
|
|
3609
|
-
|
|
3491
|
+
logger6.debug(`\u505C\u987F ${pauseTime}ms...`);
|
|
3610
3492
|
await delay2(pauseTime);
|
|
3611
3493
|
}
|
|
3612
3494
|
}
|
|
3613
|
-
|
|
3495
|
+
logger6.success("humanType");
|
|
3614
3496
|
} catch (error) {
|
|
3615
|
-
|
|
3497
|
+
logger6.fail("humanType", error);
|
|
3616
3498
|
throw error;
|
|
3617
3499
|
}
|
|
3618
3500
|
},
|
|
@@ -3636,7 +3518,7 @@ var Humanize = {
|
|
|
3636
3518
|
keyboardOptions = {}
|
|
3637
3519
|
} = pressOptions || {};
|
|
3638
3520
|
const targetDesc = hasTarget ? typeof targetOrKey === "string" ? targetOrKey : "ElementHandle" : "current focus";
|
|
3639
|
-
|
|
3521
|
+
logger6.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
3640
3522
|
try {
|
|
3641
3523
|
if (hasTarget) {
|
|
3642
3524
|
await this.humanClick(page, targetOrKey, { reactionDelay: focusDelay, scrollIfNeeded, throwOnMissing });
|
|
@@ -3646,10 +3528,10 @@ var Humanize = {
|
|
|
3646
3528
|
...keyboardOptions,
|
|
3647
3529
|
delay: this.jitterMs(holdDelay, 0.5)
|
|
3648
3530
|
});
|
|
3649
|
-
|
|
3531
|
+
logger6.success("humanPress");
|
|
3650
3532
|
return true;
|
|
3651
3533
|
} catch (error) {
|
|
3652
|
-
|
|
3534
|
+
logger6.fail("humanPress", error);
|
|
3653
3535
|
throw error;
|
|
3654
3536
|
}
|
|
3655
3537
|
},
|
|
@@ -3659,22 +3541,22 @@ var Humanize = {
|
|
|
3659
3541
|
* @param {string} selector - 输入框选择器
|
|
3660
3542
|
*/
|
|
3661
3543
|
async humanClear(page, selector) {
|
|
3662
|
-
|
|
3544
|
+
logger6.start("humanClear", `selector=${selector}`);
|
|
3663
3545
|
try {
|
|
3664
3546
|
const locator = page.locator(selector);
|
|
3665
3547
|
await locator.click();
|
|
3666
3548
|
await delay2(this.jitterMs(200, 0.4));
|
|
3667
3549
|
const currentValue = await locator.inputValue();
|
|
3668
3550
|
if (!currentValue || currentValue.length === 0) {
|
|
3669
|
-
|
|
3551
|
+
logger6.success("humanClear", "already empty");
|
|
3670
3552
|
return;
|
|
3671
3553
|
}
|
|
3672
3554
|
await page.keyboard.press("Meta+A");
|
|
3673
3555
|
await delay2(this.jitterMs(100, 0.4));
|
|
3674
3556
|
await page.keyboard.press("Backspace");
|
|
3675
|
-
|
|
3557
|
+
logger6.success("humanClear");
|
|
3676
3558
|
} catch (error) {
|
|
3677
|
-
|
|
3559
|
+
logger6.fail("humanClear", error);
|
|
3678
3560
|
throw error;
|
|
3679
3561
|
}
|
|
3680
3562
|
},
|
|
@@ -3686,7 +3568,7 @@ var Humanize = {
|
|
|
3686
3568
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
3687
3569
|
const cursor = $GetCursor(page);
|
|
3688
3570
|
const durationMs = this.jitterMs(baseDuration, 0.4);
|
|
3689
|
-
|
|
3571
|
+
logger6.start("warmUpBrowsing", `duration=${durationMs}ms`);
|
|
3690
3572
|
const startTime = Date.now();
|
|
3691
3573
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3692
3574
|
try {
|
|
@@ -3705,9 +3587,9 @@ var Humanize = {
|
|
|
3705
3587
|
await delay2(this.jitterMs(800, 0.5));
|
|
3706
3588
|
}
|
|
3707
3589
|
}
|
|
3708
|
-
|
|
3590
|
+
logger6.success("warmUpBrowsing");
|
|
3709
3591
|
} catch (error) {
|
|
3710
|
-
|
|
3592
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3711
3593
|
throw error;
|
|
3712
3594
|
}
|
|
3713
3595
|
},
|
|
@@ -3721,7 +3603,7 @@ var Humanize = {
|
|
|
3721
3603
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3722
3604
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3723
3605
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
3724
|
-
|
|
3606
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
3725
3607
|
const sign = direction === "down" ? 1 : -1;
|
|
3726
3608
|
const stepDistance = actualDistance / steps;
|
|
3727
3609
|
try {
|
|
@@ -3733,9 +3615,9 @@ var Humanize = {
|
|
|
3733
3615
|
const baseDelay = 60 + i * 25;
|
|
3734
3616
|
await delay2(this.jitterMs(baseDelay, 0.3));
|
|
3735
3617
|
}
|
|
3736
|
-
|
|
3618
|
+
logger6.success("naturalScroll");
|
|
3737
3619
|
} catch (error) {
|
|
3738
|
-
|
|
3620
|
+
logger6.fail("naturalScroll", error);
|
|
3739
3621
|
throw error;
|
|
3740
3622
|
}
|
|
3741
3623
|
}
|
|
@@ -3764,7 +3646,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
3764
3646
|
var waitJitter = (base, jitterPercent = 0.3) => delay3(jitterMs(base, jitterPercent));
|
|
3765
3647
|
|
|
3766
3648
|
// src/internals/humanize/mobile.js
|
|
3767
|
-
var
|
|
3649
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
3768
3650
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
3769
3651
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
3770
3652
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4134,7 +4016,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4134
4016
|
return;
|
|
4135
4017
|
}
|
|
4136
4018
|
await page.evaluate(
|
|
4137
|
-
(
|
|
4019
|
+
(state) => window.scrollTo(state.x, state.y),
|
|
4138
4020
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4139
4021
|
).catch(() => {
|
|
4140
4022
|
});
|
|
@@ -4221,7 +4103,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4221
4103
|
}
|
|
4222
4104
|
return true;
|
|
4223
4105
|
} catch (error) {
|
|
4224
|
-
|
|
4106
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4225
4107
|
try {
|
|
4226
4108
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4227
4109
|
await waitJitter(120, 0.35);
|
|
@@ -4255,7 +4137,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4255
4137
|
);
|
|
4256
4138
|
return { method: "touchscreen" };
|
|
4257
4139
|
} catch (error) {
|
|
4258
|
-
|
|
4140
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4259
4141
|
if (!allowMouseFallback) throw error;
|
|
4260
4142
|
}
|
|
4261
4143
|
}
|
|
@@ -4271,10 +4153,10 @@ var MobileHumanize = {
|
|
|
4271
4153
|
async initializeCursor(page) {
|
|
4272
4154
|
if (initializedPages.has(page)) return;
|
|
4273
4155
|
initializedPages.add(page);
|
|
4274
|
-
|
|
4156
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4275
4157
|
},
|
|
4276
4158
|
async humanMove(page, target) {
|
|
4277
|
-
|
|
4159
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4278
4160
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4279
4161
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4280
4162
|
if (!element) {
|
|
@@ -4293,10 +4175,10 @@ var MobileHumanize = {
|
|
|
4293
4175
|
throwOnMissing = false
|
|
4294
4176
|
} = options;
|
|
4295
4177
|
const targetDesc = describeTarget(target);
|
|
4296
|
-
|
|
4178
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4297
4179
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4298
4180
|
if (!element) {
|
|
4299
|
-
|
|
4181
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4300
4182
|
return { element: null, didScroll: false, restore: null };
|
|
4301
4183
|
}
|
|
4302
4184
|
const startTime = Date.now();
|
|
@@ -4305,42 +4187,42 @@ var MobileHumanize = {
|
|
|
4305
4187
|
const status = await checkElementVisibility(element);
|
|
4306
4188
|
if (status.code === "VISIBLE") {
|
|
4307
4189
|
if (status.isFixed) {
|
|
4308
|
-
|
|
4190
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4309
4191
|
} else {
|
|
4310
|
-
|
|
4192
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4311
4193
|
}
|
|
4312
|
-
|
|
4194
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4313
4195
|
return { element, didScroll, restore: null };
|
|
4314
4196
|
}
|
|
4315
4197
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4316
|
-
|
|
4198
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4317
4199
|
return { element, didScroll, restore: null };
|
|
4318
4200
|
}
|
|
4319
4201
|
const scrollRect = await getScrollableRect(element);
|
|
4320
4202
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4321
|
-
|
|
4203
|
+
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"})`);
|
|
4322
4204
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4323
4205
|
}
|
|
4324
4206
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4325
|
-
|
|
4207
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4326
4208
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4327
4209
|
}
|
|
4328
4210
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4329
4211
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4330
4212
|
if (moved.moved) {
|
|
4331
|
-
|
|
4213
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4332
4214
|
await waitJitter(90, 0.3);
|
|
4333
4215
|
didScroll = true;
|
|
4334
4216
|
continue;
|
|
4335
4217
|
}
|
|
4336
4218
|
}
|
|
4337
4219
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4338
|
-
|
|
4220
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4339
4221
|
return { element, didScroll, restore: null };
|
|
4340
4222
|
}
|
|
4341
4223
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4342
4224
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4343
|
-
|
|
4225
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4344
4226
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4345
4227
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4346
4228
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4380,8 +4262,8 @@ var MobileHumanize = {
|
|
|
4380
4262
|
if (scrollRect && beforeWindowState) {
|
|
4381
4263
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4382
4264
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4383
|
-
await page.evaluate((
|
|
4384
|
-
|
|
4265
|
+
await page.evaluate((state) => window.scrollTo(state.x, state.y), beforeWindowState);
|
|
4266
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4385
4267
|
}
|
|
4386
4268
|
}
|
|
4387
4269
|
let afterElementSnapshot = null;
|
|
@@ -4395,7 +4277,7 @@ var MobileHumanize = {
|
|
|
4395
4277
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4396
4278
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4397
4279
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4398
|
-
|
|
4280
|
+
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"})`);
|
|
4399
4281
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4400
4282
|
}
|
|
4401
4283
|
}
|
|
@@ -4427,12 +4309,12 @@ var MobileHumanize = {
|
|
|
4427
4309
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4428
4310
|
if (!moved) {
|
|
4429
4311
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4430
|
-
|
|
4312
|
+
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)}`);
|
|
4431
4313
|
} 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)) {
|
|
4432
4314
|
const residualDelta = expectedDelta - topDelta;
|
|
4433
4315
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4434
4316
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4435
|
-
|
|
4317
|
+
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)}`);
|
|
4436
4318
|
}
|
|
4437
4319
|
}
|
|
4438
4320
|
}
|
|
@@ -4440,7 +4322,7 @@ var MobileHumanize = {
|
|
|
4440
4322
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4441
4323
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4442
4324
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4443
|
-
|
|
4325
|
+
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"})`);
|
|
4444
4326
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4445
4327
|
}
|
|
4446
4328
|
}
|
|
@@ -4451,14 +4333,14 @@ var MobileHumanize = {
|
|
|
4451
4333
|
await waitJitter(80, 0.3);
|
|
4452
4334
|
const finalStatus = await checkElementVisibility(element);
|
|
4453
4335
|
if (finalStatus.code === "VISIBLE") {
|
|
4454
|
-
|
|
4455
|
-
|
|
4336
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4337
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4456
4338
|
return { element, didScroll: true, restore: null };
|
|
4457
4339
|
}
|
|
4458
4340
|
} catch (fallbackError) {
|
|
4459
|
-
|
|
4341
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4460
4342
|
}
|
|
4461
|
-
|
|
4343
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4462
4344
|
return { element, didScroll, restore: null };
|
|
4463
4345
|
},
|
|
4464
4346
|
async humanClick(page, target, options = {}) {
|
|
@@ -4473,7 +4355,7 @@ var MobileHumanize = {
|
|
|
4473
4355
|
fallbackDomClickOnTapError = true
|
|
4474
4356
|
} = options;
|
|
4475
4357
|
const targetDesc = describeTarget(target);
|
|
4476
|
-
|
|
4358
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4477
4359
|
try {
|
|
4478
4360
|
if (target == null) {
|
|
4479
4361
|
const viewport = resolveViewport(page);
|
|
@@ -4485,12 +4367,12 @@ var MobileHumanize = {
|
|
|
4485
4367
|
timeoutMs: tapTimeoutMs,
|
|
4486
4368
|
mouseFallbackTimeoutMs
|
|
4487
4369
|
});
|
|
4488
|
-
|
|
4370
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4489
4371
|
return true;
|
|
4490
4372
|
}
|
|
4491
4373
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4492
4374
|
if (!element) {
|
|
4493
|
-
|
|
4375
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4494
4376
|
return false;
|
|
4495
4377
|
}
|
|
4496
4378
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4514,19 +4396,19 @@ var MobileHumanize = {
|
|
|
4514
4396
|
).catch(() => null);
|
|
4515
4397
|
}
|
|
4516
4398
|
if (fallback?.activated) {
|
|
4517
|
-
|
|
4399
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4518
4400
|
return true;
|
|
4519
4401
|
}
|
|
4520
4402
|
}
|
|
4521
4403
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4522
4404
|
if (throwOnMissing) throw new Error(message);
|
|
4523
|
-
|
|
4405
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4524
4406
|
return false;
|
|
4525
4407
|
}
|
|
4526
4408
|
const box = await element.boundingBox();
|
|
4527
4409
|
if (!box) {
|
|
4528
4410
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4529
|
-
|
|
4411
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4530
4412
|
return false;
|
|
4531
4413
|
}
|
|
4532
4414
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4547,13 +4429,13 @@ var MobileHumanize = {
|
|
|
4547
4429
|
"activation fallback"
|
|
4548
4430
|
).catch(() => null);
|
|
4549
4431
|
if (!fallback?.activated) throw tapError;
|
|
4550
|
-
|
|
4432
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4551
4433
|
}
|
|
4552
4434
|
await waitJitter(120, 0.35);
|
|
4553
|
-
|
|
4435
|
+
logger7.success("humanClick");
|
|
4554
4436
|
return true;
|
|
4555
4437
|
} catch (error) {
|
|
4556
|
-
|
|
4438
|
+
logger7.fail("humanClick", error);
|
|
4557
4439
|
throw error;
|
|
4558
4440
|
}
|
|
4559
4441
|
},
|
|
@@ -4606,7 +4488,7 @@ var MobileHumanize = {
|
|
|
4606
4488
|
keyboardOptions = {}
|
|
4607
4489
|
} = pressOptions || {};
|
|
4608
4490
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4609
|
-
|
|
4491
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4610
4492
|
try {
|
|
4611
4493
|
if (hasTarget) {
|
|
4612
4494
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4620,10 +4502,10 @@ var MobileHumanize = {
|
|
|
4620
4502
|
...keyboardOptions,
|
|
4621
4503
|
delay: jitterMs(holdDelay, 0.5)
|
|
4622
4504
|
});
|
|
4623
|
-
|
|
4505
|
+
logger7.success("humanPress");
|
|
4624
4506
|
return true;
|
|
4625
4507
|
} catch (error) {
|
|
4626
|
-
|
|
4508
|
+
logger7.fail("humanPress", error);
|
|
4627
4509
|
throw error;
|
|
4628
4510
|
}
|
|
4629
4511
|
},
|
|
@@ -4690,92 +4572,62 @@ var MobileHumanize = {
|
|
|
4690
4572
|
}
|
|
4691
4573
|
};
|
|
4692
4574
|
|
|
4693
|
-
// src/
|
|
4575
|
+
// src/humanize.js
|
|
4694
4576
|
var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4695
4577
|
var resolveDelegate = (page) => {
|
|
4696
4578
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
4697
4579
|
};
|
|
4698
|
-
var
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
[Humanize, MobileHumanize]
|
|
4702
|
-
);
|
|
4703
|
-
|
|
4704
|
-
// src/internals/humanize/cloak.js
|
|
4705
|
-
var FORCE_CLICK = Object.freeze({
|
|
4706
|
-
forceClick: true,
|
|
4707
|
-
clickOptions: { force: true }
|
|
4708
|
-
});
|
|
4709
|
-
var pointOrNull = async (target) => {
|
|
4710
|
-
if (!target || typeof target.boundingBox !== "function") return null;
|
|
4711
|
-
const box = await target.boundingBox().catch(() => null);
|
|
4712
|
-
return box ? { x: box.x + box.width / 2, y: box.y + box.height / 2 } : null;
|
|
4580
|
+
var callDelegate = (method, page, args) => {
|
|
4581
|
+
const delegate = resolveDelegate(page);
|
|
4582
|
+
return delegate[method](page, ...args);
|
|
4713
4583
|
};
|
|
4714
|
-
var
|
|
4715
|
-
|
|
4716
|
-
return
|
|
4584
|
+
var Humanize2 = {
|
|
4585
|
+
jitterMs(base, jitterPercent = 0.3) {
|
|
4586
|
+
return Humanize.jitterMs(base, jitterPercent);
|
|
4717
4587
|
},
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
return point ? await DeviceInput.move(page, point, { forceMouse: true }) : false;
|
|
4588
|
+
initializeCursor(page) {
|
|
4589
|
+
return callDelegate("initializeCursor", page, []);
|
|
4721
4590
|
},
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4725
|
-
await element.scrollIntoViewIfNeeded?.();
|
|
4726
|
-
return { element, didScroll: true, restore: null };
|
|
4591
|
+
humanMove(page, target) {
|
|
4592
|
+
return callDelegate("humanMove", page, [target]);
|
|
4727
4593
|
},
|
|
4728
|
-
|
|
4729
|
-
return
|
|
4594
|
+
humanScroll(page, target, options = {}) {
|
|
4595
|
+
return callDelegate("humanScroll", page, [target, options]);
|
|
4730
4596
|
},
|
|
4731
|
-
|
|
4732
|
-
|
|
4733
|
-
return await DeviceInput.keyboardType(page, text);
|
|
4597
|
+
humanClick(page, target, options = {}) {
|
|
4598
|
+
return callDelegate("humanClick", page, [target, options]);
|
|
4734
4599
|
},
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
4739
|
-
}
|
|
4600
|
+
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4601
|
+
if (pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function") {
|
|
4602
|
+
const delegate = resolveDelegate(pageOrBaseMs);
|
|
4603
|
+
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4604
|
+
}
|
|
4605
|
+
return Humanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4740
4606
|
},
|
|
4741
|
-
|
|
4742
|
-
return
|
|
4607
|
+
simulateGaze(page, baseDurationMs = 2500) {
|
|
4608
|
+
return callDelegate("simulateGaze", page, [baseDurationMs]);
|
|
4743
4609
|
},
|
|
4744
|
-
|
|
4745
|
-
return
|
|
4610
|
+
humanType(page, selector, text, options = {}) {
|
|
4611
|
+
return callDelegate("humanType", page, [selector, text, options]);
|
|
4746
4612
|
},
|
|
4747
|
-
|
|
4748
|
-
|
|
4613
|
+
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4614
|
+
if (typeof maybeKey === "string") {
|
|
4615
|
+
return callDelegate("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4616
|
+
}
|
|
4617
|
+
return callDelegate("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4749
4618
|
},
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
// src/internals/humanize/index.js
|
|
4757
|
-
var HumanizeCommon = {
|
|
4758
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4759
|
-
return jitterMs(base, jitterPercent);
|
|
4619
|
+
humanClear(page, selector) {
|
|
4620
|
+
return callDelegate("humanClear", page, [selector]);
|
|
4621
|
+
},
|
|
4622
|
+
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4623
|
+
return callDelegate("warmUpBrowsing", page, [baseDuration]);
|
|
4760
4624
|
},
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
const baseMs = hasPage ? maybeBaseMs : pageOrBaseMs;
|
|
4764
|
-
const jitterPercent = hasPage ? maybeJitterPercent : maybeBaseMs;
|
|
4765
|
-
await delay4(jitterMs(baseMs, jitterPercent ?? 0.3));
|
|
4625
|
+
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4626
|
+
return callDelegate("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4766
4627
|
}
|
|
4767
4628
|
};
|
|
4768
|
-
var DefaultHumanize = Object.assign({}, DefaultHumanizeDevice, HumanizeCommon);
|
|
4769
|
-
var CloakHumanize = Object.assign({}, CloakHumanizeInput, HumanizeCommon);
|
|
4770
4629
|
|
|
4771
|
-
// src/
|
|
4772
|
-
var humanizeStrategies = {
|
|
4773
|
-
[Mode.Default]: DefaultHumanize,
|
|
4774
|
-
[Mode.Cloak]: CloakHumanize
|
|
4775
|
-
};
|
|
4776
|
-
var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
4777
|
-
|
|
4778
|
-
// src/internals/launch/default.js
|
|
4630
|
+
// src/launch.js
|
|
4779
4631
|
import { execFileSync } from "node:child_process";
|
|
4780
4632
|
import { FingerprintGenerator } from "fingerprint-generator";
|
|
4781
4633
|
import { FingerprintInjector } from "fingerprint-injector";
|
|
@@ -4860,107 +4712,9 @@ var ByPass = {
|
|
|
4860
4712
|
resolveRouteByProxy
|
|
4861
4713
|
};
|
|
4862
4714
|
|
|
4863
|
-
// src/
|
|
4864
|
-
var logger7 = createInternalLogger("Launch");
|
|
4865
|
-
var normalizeObject = (value) => {
|
|
4866
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4867
|
-
return {};
|
|
4868
|
-
}
|
|
4869
|
-
return value;
|
|
4870
|
-
};
|
|
4871
|
-
var parseProxyConfiguration = (proxyConfiguration = {}) => {
|
|
4872
|
-
const config = normalizeObject(proxyConfiguration);
|
|
4873
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4874
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4875
|
-
const byPassDomains = enableProxy && proxyUrl ? ByPass.normalizeByPassDomains(config.by_pass_domains) : [];
|
|
4876
|
-
return {
|
|
4877
|
-
byPassDomains,
|
|
4878
|
-
enableProxy,
|
|
4879
|
-
proxyUrl
|
|
4880
|
-
};
|
|
4881
|
-
};
|
|
4882
|
-
var resolveLaunchTraffic = ({
|
|
4883
|
-
proxyConfiguration = {},
|
|
4884
|
-
debugMode = false,
|
|
4885
|
-
useMeter = true
|
|
4886
|
-
} = {}) => {
|
|
4887
|
-
const { byPassDomains, enableProxy, proxyUrl } = parseProxyConfiguration(proxyConfiguration);
|
|
4888
|
-
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4889
|
-
const proxyMeter = useMeter && enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4890
|
-
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4891
|
-
if (launchProxy && byPassDomains.length > 0) {
|
|
4892
|
-
launchProxy.bypass = byPassDomains.join(",");
|
|
4893
|
-
}
|
|
4894
|
-
return {
|
|
4895
|
-
byPassDomains,
|
|
4896
|
-
byPassRules,
|
|
4897
|
-
enableProxy,
|
|
4898
|
-
proxyUrl,
|
|
4899
|
-
launchProxy
|
|
4900
|
-
};
|
|
4901
|
-
};
|
|
4902
|
-
var logLaunchTraffic = ({
|
|
4903
|
-
byPassDomains = [],
|
|
4904
|
-
debugMode = false,
|
|
4905
|
-
enabled = false,
|
|
4906
|
-
enableProxy = false,
|
|
4907
|
-
explicitProxy = false,
|
|
4908
|
-
launchProxy = null,
|
|
4909
|
-
proxyUrl = ""
|
|
4910
|
-
} = {}) => {
|
|
4911
|
-
if (!enabled) return;
|
|
4912
|
-
if (explicitProxy) {
|
|
4913
|
-
logger7.info("[\u4EE3\u7406\u5DF2\u542F\u7528] \u4F7F\u7528\u663E\u5F0F proxy \u914D\u7F6E\uFF0C\u8DF3\u8FC7 toolkit \u672C\u5730\u6D41\u91CF\u89C2\u6D4B");
|
|
4914
|
-
return;
|
|
4915
|
-
}
|
|
4916
|
-
if (launchProxy) {
|
|
4917
|
-
let upstreamLabel = "";
|
|
4918
|
-
try {
|
|
4919
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
4920
|
-
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
4921
|
-
} catch {
|
|
4922
|
-
}
|
|
4923
|
-
logger7.info(
|
|
4924
|
-
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
4925
|
-
);
|
|
4926
|
-
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`);
|
|
4927
|
-
return;
|
|
4928
|
-
}
|
|
4929
|
-
if (enableProxy) {
|
|
4930
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4931
|
-
} else if (proxyUrl) {
|
|
4932
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4933
|
-
}
|
|
4934
|
-
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`);
|
|
4935
|
-
};
|
|
4936
|
-
var createLaunchTrafficHook = ({
|
|
4937
|
-
byPassDomains = [],
|
|
4938
|
-
byPassRules = [],
|
|
4939
|
-
enabled = false,
|
|
4940
|
-
launchProxy = null
|
|
4941
|
-
} = {}) => {
|
|
4942
|
-
const patchedPages = /* @__PURE__ */ new WeakSet();
|
|
4943
|
-
return (page) => {
|
|
4944
|
-
if (!page || typeof page.on !== "function" || patchedPages.has(page)) {
|
|
4945
|
-
return;
|
|
4946
|
-
}
|
|
4947
|
-
patchedPages.add(page);
|
|
4948
|
-
page.on("request", (req) => {
|
|
4949
|
-
const requestUrl = req.url();
|
|
4950
|
-
const resourceType = req.resourceType();
|
|
4951
|
-
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
4952
|
-
if (launchProxy) {
|
|
4953
|
-
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
4954
|
-
}
|
|
4955
|
-
if (!enabled || byPassDomains.length === 0) return;
|
|
4956
|
-
if (!matched || !matched.rule) return;
|
|
4957
|
-
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}`);
|
|
4958
|
-
});
|
|
4959
|
-
};
|
|
4960
|
-
};
|
|
4961
|
-
|
|
4962
|
-
// src/internals/launch/default.js
|
|
4715
|
+
// src/launch.js
|
|
4963
4716
|
var logger8 = createInternalLogger("Launch");
|
|
4717
|
+
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
4964
4718
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4965
4719
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
4966
4720
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -4972,6 +4726,16 @@ var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
|
4972
4726
|
navigationTimeoutSecs: 120
|
|
4973
4727
|
});
|
|
4974
4728
|
var fingerprintInjector = new FingerprintInjector();
|
|
4729
|
+
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
4730
|
+
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
4731
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4732
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4733
|
+
if (!enableProxy || !proxyUrl) {
|
|
4734
|
+
return { byPassDomains: [], enableProxy, proxyUrl };
|
|
4735
|
+
}
|
|
4736
|
+
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
4737
|
+
return { byPassDomains, enableProxy, proxyUrl };
|
|
4738
|
+
};
|
|
4975
4739
|
var parseChromeMajorVersion = (rawValue = "") => {
|
|
4976
4740
|
const match = String(rawValue || "").match(/(?:Chrome|Chromium)(?:\/|\s+(?:for Testing\s+)?)(\d+)/i);
|
|
4977
4741
|
return match ? Number(match[1] || 0) : 0;
|
|
@@ -5015,7 +4779,7 @@ var resolveCoreDevice = (core = {}) => {
|
|
|
5015
4779
|
};
|
|
5016
4780
|
var buildFingerprintGenerator = ({ locale, browserMajorVersion, device }) => {
|
|
5017
4781
|
return new FingerprintGenerator(
|
|
5018
|
-
|
|
4782
|
+
AntiCheat.getFingerprintGeneratorOptions({
|
|
5019
4783
|
locale,
|
|
5020
4784
|
browserMajorVersion,
|
|
5021
4785
|
device
|
|
@@ -5059,7 +4823,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5059
4823
|
}
|
|
5060
4824
|
let nextState = RuntimeEnv.rememberState(runtimeState);
|
|
5061
4825
|
let browserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
|
|
5062
|
-
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() ||
|
|
4826
|
+
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() || AntiCheat.getBaseConfig().timezoneId;
|
|
5063
4827
|
const locale = DEFAULT_LOCALE;
|
|
5064
4828
|
const currentBrowserMajorVersion = detectBrowserMajorVersion(launcher);
|
|
5065
4829
|
const storedBrowserMajorVersion = Number(browserProfileCore?.browser_major_version || 0);
|
|
@@ -5138,7 +4902,7 @@ var applyFingerprintPageOptions = (pageOptions = {}, { fingerprintWithHeaders =
|
|
|
5138
4902
|
pageOptions.timezoneId = timezoneId;
|
|
5139
4903
|
}
|
|
5140
4904
|
};
|
|
5141
|
-
var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
4905
|
+
var buildReplayBrowserPoolOptions = (browserProfileCore, modifyPageOptions = null) => {
|
|
5142
4906
|
const fingerprintWithHeaders = browserProfileCore?.fingerprint;
|
|
5143
4907
|
const fingerprint = fingerprintWithHeaders?.fingerprint;
|
|
5144
4908
|
if (!fingerprintWithHeaders || !fingerprint) {
|
|
@@ -5147,13 +4911,16 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5147
4911
|
return {
|
|
5148
4912
|
useFingerprints: false,
|
|
5149
4913
|
prePageCreateHooks: [
|
|
5150
|
-
(
|
|
4914
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5151
4915
|
if (!pageOptions || typeof pageOptions !== "object") return;
|
|
5152
4916
|
applyFingerprintPageOptions(pageOptions, {
|
|
5153
4917
|
fingerprintWithHeaders,
|
|
5154
4918
|
locale: browserProfileCore.locale,
|
|
5155
4919
|
timezoneId: browserProfileCore.timezone_id
|
|
5156
4920
|
});
|
|
4921
|
+
if (modifyPageOptions) {
|
|
4922
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
4923
|
+
}
|
|
5157
4924
|
}
|
|
5158
4925
|
],
|
|
5159
4926
|
postPageCreateHooks: [
|
|
@@ -5168,7 +4935,7 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5168
4935
|
]
|
|
5169
4936
|
};
|
|
5170
4937
|
};
|
|
5171
|
-
var
|
|
4938
|
+
var Launch = {
|
|
5172
4939
|
getPlaywrightCrawlerOptions(options = {}) {
|
|
5173
4940
|
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
5174
4941
|
const {
|
|
@@ -5179,35 +4946,54 @@ var DefaultLaunch = {
|
|
|
5179
4946
|
debugMode = false,
|
|
5180
4947
|
isRunningOnApify = false,
|
|
5181
4948
|
launcher = null,
|
|
4949
|
+
hooks = {},
|
|
5182
4950
|
preNavigationHooks = [],
|
|
5183
4951
|
postNavigationHooks = [],
|
|
5184
4952
|
runtimeState = null
|
|
5185
4953
|
} = normalizedOptions;
|
|
5186
4954
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5187
|
-
const
|
|
5188
|
-
const
|
|
5189
|
-
const
|
|
5190
|
-
|
|
5191
|
-
|
|
5192
|
-
|
|
4955
|
+
const modifyPageOptions = typeof hooks?.modifyPageOptions === "function" ? hooks.modifyPageOptions : null;
|
|
4956
|
+
const { byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
4957
|
+
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4958
|
+
const proxyMeter = enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4959
|
+
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4960
|
+
if (launchProxy && byPassDomains.length > 0) {
|
|
4961
|
+
launchProxy.bypass = byPassDomains.join(",");
|
|
4962
|
+
}
|
|
5193
4963
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5194
|
-
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
4964
|
+
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore, modifyPageOptions);
|
|
5195
4965
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5196
4966
|
const launchOptions = {
|
|
5197
4967
|
args: [
|
|
5198
|
-
...
|
|
4968
|
+
...AntiCheat.getLaunchArgs({ locale: launchLocale }),
|
|
5199
4969
|
...customArgs
|
|
5200
4970
|
],
|
|
5201
4971
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
5202
4972
|
};
|
|
5203
|
-
if (
|
|
5204
|
-
launchOptions.proxy =
|
|
4973
|
+
if (launchProxy) {
|
|
4974
|
+
launchOptions.proxy = launchProxy;
|
|
4975
|
+
}
|
|
4976
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
4977
|
+
if (enableByPassLogger && launchProxy) {
|
|
4978
|
+
let upstreamLabel = "";
|
|
4979
|
+
try {
|
|
4980
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
4981
|
+
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
4982
|
+
} catch {
|
|
4983
|
+
}
|
|
4984
|
+
logger8.info(
|
|
4985
|
+
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
4986
|
+
);
|
|
4987
|
+
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`);
|
|
4988
|
+
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
4989
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4990
|
+
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`);
|
|
4991
|
+
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
4992
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4993
|
+
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`);
|
|
4994
|
+
} else if (enableByPassLogger) {
|
|
4995
|
+
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`);
|
|
5205
4996
|
}
|
|
5206
|
-
logLaunchTraffic({
|
|
5207
|
-
...traffic,
|
|
5208
|
-
debugMode,
|
|
5209
|
-
enabled: enableByPassLogger
|
|
5210
|
-
});
|
|
5211
4997
|
const onPageCreated = (page) => {
|
|
5212
4998
|
const recommendedGotoOptions = {
|
|
5213
4999
|
waitUntil: "commit"
|
|
@@ -5215,7 +5001,22 @@ var DefaultLaunch = {
|
|
|
5215
5001
|
if (!page || typeof page.on !== "function") {
|
|
5216
5002
|
return recommendedGotoOptions;
|
|
5217
5003
|
}
|
|
5218
|
-
|
|
5004
|
+
if (page[REQUEST_HOOK_FLAG]) {
|
|
5005
|
+
return recommendedGotoOptions;
|
|
5006
|
+
}
|
|
5007
|
+
page[REQUEST_HOOK_FLAG] = true;
|
|
5008
|
+
const requestHandler = (req) => {
|
|
5009
|
+
const requestUrl = req.url();
|
|
5010
|
+
const resourceType = req.resourceType();
|
|
5011
|
+
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
5012
|
+
if (launchProxy) {
|
|
5013
|
+
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
5014
|
+
}
|
|
5015
|
+
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5016
|
+
if (!matched || !matched.rule) return;
|
|
5017
|
+
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}`);
|
|
5018
|
+
};
|
|
5019
|
+
page.on("request", requestHandler);
|
|
5219
5020
|
return recommendedGotoOptions;
|
|
5220
5021
|
};
|
|
5221
5022
|
const launchContext = {
|
|
@@ -5232,20 +5033,23 @@ var DefaultLaunch = {
|
|
|
5232
5033
|
browserPoolOptions: replayBrowserPoolOptions || {
|
|
5233
5034
|
useFingerprints: true,
|
|
5234
5035
|
fingerprintOptions: {
|
|
5235
|
-
fingerprintGeneratorOptions:
|
|
5036
|
+
fingerprintGeneratorOptions: AntiCheat.getFingerprintGeneratorOptions({
|
|
5236
5037
|
locale: launchLocale,
|
|
5237
5038
|
device
|
|
5238
5039
|
})
|
|
5239
5040
|
},
|
|
5240
5041
|
prePageCreateHooks: [
|
|
5241
|
-
(
|
|
5042
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5242
5043
|
const fingerprintWithHeaders = browserController?.launchContext?.fingerprint;
|
|
5243
|
-
const timezoneId =
|
|
5044
|
+
const timezoneId = AntiCheat.getBaseConfig().timezoneId;
|
|
5244
5045
|
applyFingerprintPageOptions(pageOptions, {
|
|
5245
5046
|
fingerprintWithHeaders,
|
|
5246
5047
|
locale: launchLocale,
|
|
5247
5048
|
timezoneId
|
|
5248
5049
|
});
|
|
5050
|
+
if (modifyPageOptions) {
|
|
5051
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
5052
|
+
}
|
|
5249
5053
|
}
|
|
5250
5054
|
]
|
|
5251
5055
|
},
|
|
@@ -5267,287 +5071,10 @@ var DefaultLaunch = {
|
|
|
5267
5071
|
}
|
|
5268
5072
|
};
|
|
5269
5073
|
|
|
5270
|
-
// src/internals/launch/cloak.js
|
|
5271
|
-
import { execFile } from "node:child_process";
|
|
5272
|
-
import { promisify } from "node:util";
|
|
5273
|
-
var logger9 = createInternalLogger("Launch");
|
|
5274
|
-
var execFileAsync = promisify(execFile);
|
|
5275
|
-
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5276
|
-
maxConcurrency: 1,
|
|
5277
|
-
maxRequestRetries: 0,
|
|
5278
|
-
requestHandlerTimeoutSecs: 240,
|
|
5279
|
-
navigationTimeoutSecs: 120
|
|
5280
|
-
});
|
|
5281
|
-
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5282
|
-
humanize: true
|
|
5283
|
-
});
|
|
5284
|
-
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5285
|
-
waitUntil: "commit"
|
|
5286
|
-
});
|
|
5287
|
-
var cachedCloakModulePromise = null;
|
|
5288
|
-
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5289
|
-
var loadCloakModule = async () => {
|
|
5290
|
-
if (!cachedCloakModulePromise) {
|
|
5291
|
-
cachedCloakModulePromise = import("cloakbrowser").catch((error) => {
|
|
5292
|
-
cachedCloakModulePromise = null;
|
|
5293
|
-
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", {
|
|
5294
|
-
cause: error
|
|
5295
|
-
});
|
|
5296
|
-
});
|
|
5297
|
-
}
|
|
5298
|
-
return cachedCloakModulePromise;
|
|
5299
|
-
};
|
|
5300
|
-
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5301
|
-
const { buildLaunchOptions } = await loadCloakModule();
|
|
5302
|
-
return await buildLaunchOptions(normalizeObject2(options));
|
|
5303
|
-
};
|
|
5304
|
-
var normalizeObject2 = (value) => {
|
|
5305
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5306
|
-
return {};
|
|
5307
|
-
}
|
|
5308
|
-
return value;
|
|
5309
|
-
};
|
|
5310
|
-
var normalizeStringArray = (value) => {
|
|
5311
|
-
if (!Array.isArray(value)) {
|
|
5312
|
-
return [];
|
|
5313
|
-
}
|
|
5314
|
-
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5315
|
-
};
|
|
5316
|
-
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5317
|
-
const config = normalizeObject2(proxyConfiguration);
|
|
5318
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5319
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5320
|
-
if (!enableProxy || !proxyUrl) {
|
|
5321
|
-
return null;
|
|
5322
|
-
}
|
|
5323
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5324
|
-
if (byPassDomains.length === 0) {
|
|
5325
|
-
return proxyUrl;
|
|
5326
|
-
}
|
|
5327
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5328
|
-
return {
|
|
5329
|
-
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5330
|
-
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5331
|
-
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5332
|
-
bypass: byPassDomains.join(",")
|
|
5333
|
-
};
|
|
5334
|
-
};
|
|
5335
|
-
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5336
|
-
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5337
|
-
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5338
|
-
};
|
|
5339
|
-
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5340
|
-
const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
|
|
5341
|
-
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5342
|
-
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5343
|
-
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5344
|
-
if (gotoOptions[key] == null) {
|
|
5345
|
-
gotoOptions[key] = value;
|
|
5346
|
-
}
|
|
5347
|
-
}
|
|
5348
|
-
};
|
|
5349
|
-
};
|
|
5350
|
-
var attachCloakHumanizeHook = ({
|
|
5351
|
-
browserPoolOptions = {},
|
|
5352
|
-
activeBrowsers,
|
|
5353
|
-
patchedBrowsers,
|
|
5354
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5355
|
-
} = {}) => {
|
|
5356
|
-
const normalizedBrowserPoolOptions = normalizeObject2(browserPoolOptions);
|
|
5357
|
-
const shouldHumanize = humanizeOptions !== false;
|
|
5358
|
-
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5359
|
-
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5360
|
-
...normalizeObject2(humanizeOptions)
|
|
5361
|
-
} : null;
|
|
5362
|
-
return {
|
|
5363
|
-
...normalizedBrowserPoolOptions,
|
|
5364
|
-
useFingerprints: false,
|
|
5365
|
-
postLaunchHooks: [
|
|
5366
|
-
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5367
|
-
async (_pageId, browserController) => {
|
|
5368
|
-
const browser = browserController?.browser;
|
|
5369
|
-
if (!browser || typeof browser.contexts !== "function") {
|
|
5370
|
-
return;
|
|
5371
|
-
}
|
|
5372
|
-
activeBrowsers.add(browser);
|
|
5373
|
-
if (typeof browser.once === "function") {
|
|
5374
|
-
browser.once("disconnected", () => {
|
|
5375
|
-
activeBrowsers.delete(browser);
|
|
5376
|
-
});
|
|
5377
|
-
}
|
|
5378
|
-
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5379
|
-
return;
|
|
5380
|
-
}
|
|
5381
|
-
const { humanizeBrowser } = await loadCloakModule();
|
|
5382
|
-
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5383
|
-
patchedBrowsers.add(browser);
|
|
5384
|
-
}
|
|
5385
|
-
]
|
|
5386
|
-
};
|
|
5387
|
-
};
|
|
5388
|
-
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5389
|
-
const browsers = Array.from(activeBrowsers || []);
|
|
5390
|
-
activeBrowsers?.clear?.();
|
|
5391
|
-
await Promise.allSettled(
|
|
5392
|
-
browsers.map(async (browser) => {
|
|
5393
|
-
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5394
|
-
return;
|
|
5395
|
-
}
|
|
5396
|
-
await browser.close().catch(() => {
|
|
5397
|
-
});
|
|
5398
|
-
})
|
|
5399
|
-
);
|
|
5400
|
-
};
|
|
5401
|
-
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5402
|
-
if (!fingerprintArg) {
|
|
5403
|
-
return;
|
|
5404
|
-
}
|
|
5405
|
-
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5406
|
-
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5407
|
-
return;
|
|
5408
|
-
}
|
|
5409
|
-
logger9.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5410
|
-
});
|
|
5411
|
-
};
|
|
5412
|
-
var CloakLaunch = {
|
|
5413
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5414
|
-
return resolveCloakProxy(proxyConfiguration);
|
|
5415
|
-
},
|
|
5416
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5417
|
-
return extractFingerprintArg(launchOptions);
|
|
5418
|
-
},
|
|
5419
|
-
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5420
|
-
return createStableGotoHook(recommendedGotoOptions);
|
|
5421
|
-
},
|
|
5422
|
-
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5423
|
-
const runtime2 = await CloakLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5424
|
-
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5425
|
-
cleanup: {
|
|
5426
|
-
enumerable: false,
|
|
5427
|
-
value: runtime2.cleanup
|
|
5428
|
-
},
|
|
5429
|
-
closeActiveBrowsers: {
|
|
5430
|
-
enumerable: false,
|
|
5431
|
-
value: runtime2.closeActiveBrowsers
|
|
5432
|
-
},
|
|
5433
|
-
forceTerminateActiveProcesses: {
|
|
5434
|
-
enumerable: false,
|
|
5435
|
-
value: runtime2.forceTerminateActiveProcesses
|
|
5436
|
-
}
|
|
5437
|
-
});
|
|
5438
|
-
},
|
|
5439
|
-
async buildLaunchOptions(options = {}) {
|
|
5440
|
-
return await buildCloakLaunchOptions(options);
|
|
5441
|
-
},
|
|
5442
|
-
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5443
|
-
const normalizedOptions = normalizeObject2(options);
|
|
5444
|
-
const {
|
|
5445
|
-
proxyConfiguration = {},
|
|
5446
|
-
log: logOptions = null,
|
|
5447
|
-
debugMode = false,
|
|
5448
|
-
runInHeadfulMode = false,
|
|
5449
|
-
isRunningOnApify = false,
|
|
5450
|
-
launcher = null,
|
|
5451
|
-
cloakOptions = {},
|
|
5452
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5453
|
-
crawlerBaseOptions = {},
|
|
5454
|
-
browserPoolOptions = {},
|
|
5455
|
-
launchContext = {},
|
|
5456
|
-
preNavigationHooks = [],
|
|
5457
|
-
postNavigationHooks = [],
|
|
5458
|
-
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5459
|
-
} = normalizedOptions;
|
|
5460
|
-
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5461
|
-
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5462
|
-
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5463
|
-
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5464
|
-
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5465
|
-
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5466
|
-
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5467
|
-
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
5468
|
-
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5469
|
-
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5470
|
-
const mergedCloakOptions = {
|
|
5471
|
-
...normalizedCloakOptions,
|
|
5472
|
-
headless,
|
|
5473
|
-
proxy,
|
|
5474
|
-
args: [...defaultArgs, ...extraArgs]
|
|
5475
|
-
};
|
|
5476
|
-
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5477
|
-
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5478
|
-
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5479
|
-
const trafficHook = createLaunchTrafficHook({
|
|
5480
|
-
byPassDomains: proxyLaunchState.byPassDomains,
|
|
5481
|
-
byPassRules: proxyLaunchState.byPassRules,
|
|
5482
|
-
enabled: enableByPassLogger,
|
|
5483
|
-
launchProxy: proxyLaunchState.launchProxy
|
|
5484
|
-
});
|
|
5485
|
-
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5486
|
-
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5487
|
-
logLaunchTraffic({
|
|
5488
|
-
...proxyLaunchState,
|
|
5489
|
-
debugMode,
|
|
5490
|
-
enabled: enableByPassLogger,
|
|
5491
|
-
explicitProxy: hasExplicitProxy
|
|
5492
|
-
});
|
|
5493
|
-
const crawlerOptions = {
|
|
5494
|
-
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5495
|
-
...normalizeObject2(crawlerBaseOptions),
|
|
5496
|
-
headless,
|
|
5497
|
-
launchContext: {
|
|
5498
|
-
useIncognitoPages: true,
|
|
5499
|
-
...normalizeObject2(launchContext),
|
|
5500
|
-
...launcher ? { launcher } : {},
|
|
5501
|
-
launchOptions
|
|
5502
|
-
},
|
|
5503
|
-
browserPoolOptions: attachCloakHumanizeHook({
|
|
5504
|
-
browserPoolOptions,
|
|
5505
|
-
activeBrowsers,
|
|
5506
|
-
patchedBrowsers,
|
|
5507
|
-
humanizeOptions
|
|
5508
|
-
}),
|
|
5509
|
-
preNavigationHooks: [
|
|
5510
|
-
async (crawlingContext, gotoOptions = {}) => {
|
|
5511
|
-
trafficHook(crawlingContext?.page);
|
|
5512
|
-
await internalPreNavigationHook(crawlingContext, gotoOptions);
|
|
5513
|
-
},
|
|
5514
|
-
...normalizedPreNavigationHooks
|
|
5515
|
-
],
|
|
5516
|
-
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5517
|
-
};
|
|
5518
|
-
const closeActiveBrowsers = async () => {
|
|
5519
|
-
await closeTrackedBrowsers(activeBrowsers);
|
|
5520
|
-
};
|
|
5521
|
-
const forceTerminateActiveProcesses = async () => {
|
|
5522
|
-
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5523
|
-
};
|
|
5524
|
-
const cleanup = async () => {
|
|
5525
|
-
await closeActiveBrowsers();
|
|
5526
|
-
await forceTerminateActiveProcesses();
|
|
5527
|
-
};
|
|
5528
|
-
return {
|
|
5529
|
-
headless,
|
|
5530
|
-
launchOptions,
|
|
5531
|
-
fingerprintArg,
|
|
5532
|
-
crawlerOptions,
|
|
5533
|
-
closeActiveBrowsers,
|
|
5534
|
-
forceTerminateActiveProcesses,
|
|
5535
|
-
cleanup
|
|
5536
|
-
};
|
|
5537
|
-
}
|
|
5538
|
-
};
|
|
5539
|
-
|
|
5540
|
-
// src/launch.js
|
|
5541
|
-
var launchStrategies = {
|
|
5542
|
-
[Mode.Default]: DefaultLaunch,
|
|
5543
|
-
[Mode.Cloak]: CloakLaunch
|
|
5544
|
-
};
|
|
5545
|
-
var Launch = withModeReflect("Launch", launchStrategies);
|
|
5546
|
-
|
|
5547
5074
|
// src/live-view.js
|
|
5548
5075
|
import express from "express";
|
|
5549
5076
|
import { Actor } from "apify";
|
|
5550
|
-
var
|
|
5077
|
+
var logger9 = createInternalLogger("LiveView");
|
|
5551
5078
|
async function startLiveViewServer(liveViewKey) {
|
|
5552
5079
|
const app = express();
|
|
5553
5080
|
app.get("/", async (req, res) => {
|
|
@@ -5572,13 +5099,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5572
5099
|
</html>
|
|
5573
5100
|
`);
|
|
5574
5101
|
} catch (error) {
|
|
5575
|
-
|
|
5102
|
+
logger9.fail("Live View Server", error);
|
|
5576
5103
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5577
5104
|
}
|
|
5578
5105
|
});
|
|
5579
5106
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5580
5107
|
app.listen(port, () => {
|
|
5581
|
-
|
|
5108
|
+
logger9.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5582
5109
|
});
|
|
5583
5110
|
}
|
|
5584
5111
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5586,10 +5113,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5586
5113
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5587
5114
|
await Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5588
5115
|
if (logMessage) {
|
|
5589
|
-
|
|
5116
|
+
logger9.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5590
5117
|
}
|
|
5591
5118
|
} catch (e) {
|
|
5592
|
-
|
|
5119
|
+
logger9.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5593
5120
|
}
|
|
5594
5121
|
}
|
|
5595
5122
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5606,6 +5133,9 @@ var LiveView = {
|
|
|
5606
5133
|
useLiveView
|
|
5607
5134
|
};
|
|
5608
5135
|
|
|
5136
|
+
// src/chaptcha.js
|
|
5137
|
+
import { v4 as uuidv4 } from "uuid";
|
|
5138
|
+
|
|
5609
5139
|
// src/internals/captcha/bytedance.js
|
|
5610
5140
|
import { mkdir, writeFile } from "fs/promises";
|
|
5611
5141
|
import path2 from "path";
|
|
@@ -5695,7 +5225,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5695
5225
|
};
|
|
5696
5226
|
|
|
5697
5227
|
// src/internals/captcha/bytedance.js
|
|
5698
|
-
var
|
|
5228
|
+
var logger10 = createInternalLogger("Captcha");
|
|
5699
5229
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5700
5230
|
apiType: "31234",
|
|
5701
5231
|
maxRetries: 3,
|
|
@@ -5827,7 +5357,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5827
5357
|
}
|
|
5828
5358
|
await writeFile(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5829
5359
|
}
|
|
5830
|
-
|
|
5360
|
+
logger10.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5831
5361
|
};
|
|
5832
5362
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5833
5363
|
if (!options.debugArtifacts) {
|
|
@@ -5864,14 +5394,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5864
5394
|
if (!isContainerVisible) {
|
|
5865
5395
|
return null;
|
|
5866
5396
|
}
|
|
5867
|
-
|
|
5397
|
+
logger10.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5868
5398
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5869
5399
|
let isIframeVisible = await waitForVisible(
|
|
5870
5400
|
iframeLocator,
|
|
5871
5401
|
options.iframeVisibleTimeoutMs
|
|
5872
5402
|
);
|
|
5873
5403
|
if (!isIframeVisible) {
|
|
5874
|
-
|
|
5404
|
+
logger10.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5875
5405
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5876
5406
|
isIframeVisible = await waitForVisible(
|
|
5877
5407
|
iframeLocator,
|
|
@@ -5881,7 +5411,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5881
5411
|
if (!isIframeVisible) {
|
|
5882
5412
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5883
5413
|
}
|
|
5884
|
-
|
|
5414
|
+
logger10.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5885
5415
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5886
5416
|
if (!frame) {
|
|
5887
5417
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -5997,11 +5527,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
5997
5527
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
5998
5528
|
...options,
|
|
5999
5529
|
page,
|
|
6000
|
-
logger:
|
|
5530
|
+
logger: logger10,
|
|
6001
5531
|
forceMouse: true
|
|
6002
5532
|
}).catch(() => false);
|
|
6003
5533
|
if (!clicked) {
|
|
6004
|
-
|
|
5534
|
+
logger10.warn("Refresh button not found.");
|
|
6005
5535
|
return false;
|
|
6006
5536
|
}
|
|
6007
5537
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -6032,24 +5562,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
6032
5562
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
6033
5563
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
6034
5564
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
6035
|
-
|
|
5565
|
+
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");
|
|
6036
5566
|
hasLoggedGuideMask = true;
|
|
6037
5567
|
}
|
|
6038
5568
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
6039
|
-
|
|
5569
|
+
logger10.info(
|
|
6040
5570
|
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"
|
|
6041
5571
|
);
|
|
6042
5572
|
return;
|
|
6043
5573
|
}
|
|
6044
5574
|
if (hasErrorTextVisible) {
|
|
6045
|
-
|
|
5575
|
+
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");
|
|
6046
5576
|
await refreshCaptcha(page, frame, options);
|
|
6047
5577
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6048
5578
|
hasSeenLoading = false;
|
|
6049
5579
|
continue;
|
|
6050
5580
|
}
|
|
6051
5581
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
6052
|
-
|
|
5582
|
+
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`);
|
|
6053
5583
|
await refreshCaptcha(page, frame, options);
|
|
6054
5584
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
6055
5585
|
hasSeenLoading = false;
|
|
@@ -6097,7 +5627,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6097
5627
|
accepted
|
|
6098
5628
|
};
|
|
6099
5629
|
dragAttempts.push(attemptInfo);
|
|
6100
|
-
|
|
5630
|
+
logger10.info(
|
|
6101
5631
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6102
5632
|
);
|
|
6103
5633
|
if (accepted) {
|
|
@@ -6115,7 +5645,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6115
5645
|
dragAttempts,
|
|
6116
5646
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6117
5647
|
}).catch((error) => {
|
|
6118
|
-
|
|
5648
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6119
5649
|
});
|
|
6120
5650
|
return {
|
|
6121
5651
|
accepted: false,
|
|
@@ -6132,16 +5662,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6132
5662
|
...options
|
|
6133
5663
|
};
|
|
6134
5664
|
if (!config.token) {
|
|
6135
|
-
|
|
5665
|
+
logger10.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6136
5666
|
return false;
|
|
6137
5667
|
}
|
|
6138
|
-
|
|
5668
|
+
logger10.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6139
5669
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6140
|
-
|
|
5670
|
+
logger10.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6141
5671
|
try {
|
|
6142
5672
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6143
5673
|
if (!captchaContext) {
|
|
6144
|
-
|
|
5674
|
+
logger10.info("Captcha container is not visible anymore.");
|
|
6145
5675
|
return true;
|
|
6146
5676
|
}
|
|
6147
5677
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6154,7 +5684,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6154
5684
|
"ready",
|
|
6155
5685
|
config
|
|
6156
5686
|
).catch((error) => {
|
|
6157
|
-
|
|
5687
|
+
logger10.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6158
5688
|
});
|
|
6159
5689
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6160
5690
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6166,16 +5696,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6166
5696
|
});
|
|
6167
5697
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6168
5698
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6169
|
-
|
|
5699
|
+
logger10.warn(
|
|
6170
5700
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6171
5701
|
);
|
|
6172
5702
|
await refreshCaptcha(page, frame, config);
|
|
6173
5703
|
continue;
|
|
6174
5704
|
}
|
|
6175
|
-
|
|
5705
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6176
5706
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6177
5707
|
if (!dropTarget) {
|
|
6178
|
-
|
|
5708
|
+
logger10.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6179
5709
|
await refreshCaptcha(page, frame, config);
|
|
6180
5710
|
continue;
|
|
6181
5711
|
}
|
|
@@ -6186,7 +5716,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6186
5716
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6187
5717
|
);
|
|
6188
5718
|
}
|
|
6189
|
-
|
|
5719
|
+
logger10.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6190
5720
|
for (const imageIndex of normalizedIndexes) {
|
|
6191
5721
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6192
5722
|
throw new Error(
|
|
@@ -6218,55 +5748,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6218
5748
|
}
|
|
6219
5749
|
}
|
|
6220
5750
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6221
|
-
|
|
5751
|
+
logger10.info(
|
|
6222
5752
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6223
5753
|
);
|
|
6224
5754
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6225
5755
|
...config,
|
|
6226
5756
|
page,
|
|
6227
|
-
logger:
|
|
5757
|
+
logger: logger10,
|
|
6228
5758
|
forceMouse: true,
|
|
6229
5759
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6230
5760
|
}).catch(() => false);
|
|
6231
5761
|
if (!submitted) {
|
|
6232
|
-
|
|
5762
|
+
logger10.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6233
5763
|
}
|
|
6234
5764
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6235
5765
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6236
|
-
|
|
5766
|
+
logger10.info(
|
|
6237
5767
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6238
5768
|
);
|
|
6239
5769
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6240
5770
|
if (!stillVisible) {
|
|
6241
|
-
|
|
5771
|
+
logger10.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6242
5772
|
return true;
|
|
6243
5773
|
}
|
|
6244
5774
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6245
5775
|
beforeSubmitState,
|
|
6246
5776
|
afterSubmitState
|
|
6247
5777
|
}).catch((error) => {
|
|
6248
|
-
|
|
5778
|
+
logger10.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6249
5779
|
});
|
|
6250
|
-
|
|
5780
|
+
logger10.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6251
5781
|
await page.waitForTimeout(2e3);
|
|
6252
5782
|
await refreshCaptcha(page, frame, config);
|
|
6253
5783
|
} catch (error) {
|
|
6254
|
-
|
|
5784
|
+
logger10.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6255
5785
|
}
|
|
6256
5786
|
if (attempt < config.maxRetries) {
|
|
6257
5787
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6258
5788
|
}
|
|
6259
5789
|
}
|
|
6260
|
-
|
|
5790
|
+
logger10.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6261
5791
|
return false;
|
|
6262
5792
|
}
|
|
6263
5793
|
var sloveCaptcha = solveCaptcha;
|
|
6264
5794
|
|
|
6265
5795
|
// src/chaptcha.js
|
|
6266
|
-
var
|
|
6267
|
-
var DOM_MONITOR_WAIT_TIMEOUT_MS = 1e3;
|
|
6268
|
-
var DOM_MONITOR_POST_DETECT_HIDDEN_WAIT_MS = 300;
|
|
6269
|
-
var DOM_MONITOR_RECOVERY_WAIT_MS = 100;
|
|
5796
|
+
var logger11 = createInternalLogger("Captcha");
|
|
6270
5797
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6271
5798
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6272
5799
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6287,15 +5814,6 @@ var mergeDefinedOptions = (...sources) => {
|
|
|
6287
5814
|
}
|
|
6288
5815
|
return merged;
|
|
6289
5816
|
};
|
|
6290
|
-
var sleep = (ms) => new Promise((resolve) => {
|
|
6291
|
-
setTimeout(resolve, ms);
|
|
6292
|
-
});
|
|
6293
|
-
var getErrorMessage = (error) => String(error?.message || error || "");
|
|
6294
|
-
var isTimeoutError = (error) => error?.name === "TimeoutError" || getErrorMessage(error).includes("Timeout");
|
|
6295
|
-
var isPageLifecycleError = (error) => {
|
|
6296
|
-
const message = getErrorMessage(error);
|
|
6297
|
-
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");
|
|
6298
|
-
};
|
|
6299
5817
|
function useCaptchaMonitor(page, options) {
|
|
6300
5818
|
const { domSelector, urlPattern, onDetected } = options;
|
|
6301
5819
|
if (!domSelector && !urlPattern) {
|
|
@@ -6307,13 +5825,10 @@ function useCaptchaMonitor(page, options) {
|
|
|
6307
5825
|
let isStopped = false;
|
|
6308
5826
|
let isHandling = false;
|
|
6309
5827
|
let frameHandler = null;
|
|
6310
|
-
let
|
|
6311
|
-
let lastTriggeredAt = 0;
|
|
5828
|
+
let exposedFunctionName = null;
|
|
6312
5829
|
const triggerDetected = async () => {
|
|
6313
|
-
|
|
6314
|
-
if (isStopped || isHandling || now - lastTriggeredAt < 250) return;
|
|
5830
|
+
if (isStopped || isHandling) return;
|
|
6315
5831
|
isHandling = true;
|
|
6316
|
-
lastTriggeredAt = now;
|
|
6317
5832
|
try {
|
|
6318
5833
|
await onDetected();
|
|
6319
5834
|
} finally {
|
|
@@ -6322,38 +5837,60 @@ function useCaptchaMonitor(page, options) {
|
|
|
6322
5837
|
};
|
|
6323
5838
|
const cleanupFns = [];
|
|
6324
5839
|
if (domSelector) {
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
}).catch(() => {
|
|
6337
|
-
});
|
|
6338
|
-
} catch (error) {
|
|
6339
|
-
if (isStopped) break;
|
|
6340
|
-
if (page?.isClosed?.() && isPageLifecycleError(error)) break;
|
|
6341
|
-
if (isTimeoutError(error) || isPageLifecycleError(error)) {
|
|
6342
|
-
await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
|
|
6343
|
-
continue;
|
|
5840
|
+
exposedFunctionName = `__c_d_${uuidv4().replace(/-/g, "_")}`;
|
|
5841
|
+
const cleanerName = `__c_cleaner_${uuidv4().replace(/-/g, "_")}`;
|
|
5842
|
+
page.exposeFunction(exposedFunctionName, triggerDetected).catch(() => {
|
|
5843
|
+
});
|
|
5844
|
+
page.addInitScript(({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
5845
|
+
(() => {
|
|
5846
|
+
let observer = null;
|
|
5847
|
+
const checkAndReport = () => {
|
|
5848
|
+
const element = document.querySelector(selector);
|
|
5849
|
+
if (!element) {
|
|
5850
|
+
return false;
|
|
6344
5851
|
}
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
5852
|
+
if (window[callbackName]) {
|
|
5853
|
+
window[callbackName]();
|
|
5854
|
+
}
|
|
5855
|
+
return true;
|
|
5856
|
+
};
|
|
5857
|
+
checkAndReport();
|
|
5858
|
+
observer = new MutationObserver((mutations) => {
|
|
5859
|
+
const shouldCheck = mutations.some((mutation) => mutation.addedNodes.length > 0);
|
|
5860
|
+
if (shouldCheck && observer) {
|
|
5861
|
+
checkAndReport();
|
|
5862
|
+
}
|
|
5863
|
+
});
|
|
5864
|
+
const mountObserver = () => {
|
|
5865
|
+
const target = document.documentElement;
|
|
5866
|
+
if (target && observer) {
|
|
5867
|
+
observer.observe(target, { childList: true, subtree: true });
|
|
5868
|
+
}
|
|
5869
|
+
};
|
|
5870
|
+
if (document.readyState === "loading") {
|
|
5871
|
+
window.addEventListener("DOMContentLoaded", mountObserver);
|
|
5872
|
+
} else {
|
|
5873
|
+
mountObserver();
|
|
6350
5874
|
}
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
5875
|
+
window[cleanupName] = () => {
|
|
5876
|
+
if (observer) {
|
|
5877
|
+
observer.disconnect();
|
|
5878
|
+
observer = null;
|
|
5879
|
+
}
|
|
5880
|
+
};
|
|
5881
|
+
})();
|
|
5882
|
+
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
5883
|
+
logger11.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6354
5884
|
cleanupFns.push(async () => {
|
|
6355
|
-
|
|
6356
|
-
|
|
5885
|
+
try {
|
|
5886
|
+
await page.evaluate((name) => {
|
|
5887
|
+
if (window[name]) {
|
|
5888
|
+
window[name]();
|
|
5889
|
+
delete window[name];
|
|
5890
|
+
}
|
|
5891
|
+
}, cleanerName);
|
|
5892
|
+
} catch {
|
|
5893
|
+
}
|
|
6357
5894
|
});
|
|
6358
5895
|
}
|
|
6359
5896
|
if (urlPattern) {
|
|
@@ -6367,24 +5904,18 @@ function useCaptchaMonitor(page, options) {
|
|
|
6367
5904
|
}
|
|
6368
5905
|
};
|
|
6369
5906
|
page.on("framenavigated", frameHandler);
|
|
6370
|
-
|
|
6371
|
-
Promise.resolve().then(async () => {
|
|
6372
|
-
if (!isStopped && page.url().includes(urlPattern)) {
|
|
6373
|
-
await triggerDetected();
|
|
6374
|
-
}
|
|
6375
|
-
}).catch(() => {
|
|
6376
|
-
});
|
|
5907
|
+
logger11.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6377
5908
|
cleanupFns.push(async () => {
|
|
6378
5909
|
page.off("framenavigated", frameHandler);
|
|
6379
5910
|
});
|
|
6380
5911
|
}
|
|
6381
5912
|
return {
|
|
6382
5913
|
stop: async () => {
|
|
6383
|
-
|
|
6384
|
-
isStopped = true;
|
|
5914
|
+
logger11.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6385
5915
|
for (const fn of cleanupFns) {
|
|
6386
5916
|
await fn();
|
|
6387
5917
|
}
|
|
5918
|
+
isStopped = true;
|
|
6388
5919
|
}
|
|
6389
5920
|
};
|
|
6390
5921
|
}
|
|
@@ -6419,7 +5950,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6419
5950
|
);
|
|
6420
5951
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6421
5952
|
callCaptchaRecognitionApi,
|
|
6422
|
-
logger:
|
|
5953
|
+
logger: logger11
|
|
6423
5954
|
});
|
|
6424
5955
|
}
|
|
6425
5956
|
var Captcha = {
|
|
@@ -6429,15 +5960,15 @@ var Captcha = {
|
|
|
6429
5960
|
|
|
6430
5961
|
// src/mutation.js
|
|
6431
5962
|
import { createHash } from "node:crypto";
|
|
6432
|
-
import { v4 as
|
|
6433
|
-
var
|
|
5963
|
+
import { v4 as uuidv42 } from "uuid";
|
|
5964
|
+
var logger12 = createInternalLogger("Mutation");
|
|
6434
5965
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6435
5966
|
Added: "added",
|
|
6436
5967
|
Changed: "changed",
|
|
6437
5968
|
All: "all"
|
|
6438
5969
|
});
|
|
6439
5970
|
function generateKey(prefix) {
|
|
6440
|
-
return `__${prefix}_${
|
|
5971
|
+
return `__${prefix}_${uuidv42().replace(/-/g, "_")}`;
|
|
6441
5972
|
}
|
|
6442
5973
|
var Mutation = {
|
|
6443
5974
|
Mode: MUTATION_MONITOR_MODE,
|
|
@@ -6463,14 +5994,14 @@ var Mutation = {
|
|
|
6463
5994
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6464
5995
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6465
5996
|
const onMutation = options.onMutation;
|
|
6466
|
-
|
|
5997
|
+
logger12.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6467
5998
|
if (initialTimeout > 0) {
|
|
6468
5999
|
const selectorQuery = selectorList.join(",");
|
|
6469
6000
|
try {
|
|
6470
6001
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6471
|
-
|
|
6002
|
+
logger12.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6472
6003
|
} catch (e) {
|
|
6473
|
-
|
|
6004
|
+
logger12.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6474
6005
|
throw e;
|
|
6475
6006
|
}
|
|
6476
6007
|
}
|
|
@@ -6486,7 +6017,7 @@ var Mutation = {
|
|
|
6486
6017
|
return "__CONTINUE__";
|
|
6487
6018
|
}
|
|
6488
6019
|
});
|
|
6489
|
-
|
|
6020
|
+
logger12.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6490
6021
|
} catch (e) {
|
|
6491
6022
|
}
|
|
6492
6023
|
}
|
|
@@ -6601,9 +6132,9 @@ var Mutation = {
|
|
|
6601
6132
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6602
6133
|
);
|
|
6603
6134
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6604
|
-
|
|
6135
|
+
logger12.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6605
6136
|
}
|
|
6606
|
-
|
|
6137
|
+
logger12.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6607
6138
|
return result;
|
|
6608
6139
|
},
|
|
6609
6140
|
/**
|
|
@@ -6627,7 +6158,7 @@ var Mutation = {
|
|
|
6627
6158
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6628
6159
|
const onMutation = options.onMutation;
|
|
6629
6160
|
const pollInterval = 500;
|
|
6630
|
-
const
|
|
6161
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6631
6162
|
setTimeout(resolve, ms);
|
|
6632
6163
|
});
|
|
6633
6164
|
const truncate = (value, max = 800) => {
|
|
@@ -6775,29 +6306,29 @@ var Mutation = {
|
|
|
6775
6306
|
return "__CONTINUE__";
|
|
6776
6307
|
}
|
|
6777
6308
|
};
|
|
6778
|
-
|
|
6309
|
+
logger12.start(
|
|
6779
6310
|
"waitForStableAcrossRoots",
|
|
6780
6311
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6781
6312
|
);
|
|
6782
6313
|
if (initialTimeout > 0) {
|
|
6783
6314
|
try {
|
|
6784
6315
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6785
|
-
|
|
6316
|
+
logger12.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6786
6317
|
} catch (e) {
|
|
6787
|
-
|
|
6318
|
+
logger12.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6788
6319
|
throw e;
|
|
6789
6320
|
}
|
|
6790
6321
|
}
|
|
6791
|
-
let
|
|
6792
|
-
if (!
|
|
6793
|
-
|
|
6322
|
+
let state = await buildState();
|
|
6323
|
+
if (!state?.hasMatched) {
|
|
6324
|
+
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6794
6325
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6795
6326
|
}
|
|
6796
6327
|
let mutationCount = 0;
|
|
6797
6328
|
let stableSince = 0;
|
|
6798
6329
|
let isPaused = false;
|
|
6799
6330
|
let wasPaused = false;
|
|
6800
|
-
let lastSnapshotKey =
|
|
6331
|
+
let lastSnapshotKey = state.snapshotKey;
|
|
6801
6332
|
const applyPauseSignal = (signal) => {
|
|
6802
6333
|
const nextPaused = signal === "__PAUSE__";
|
|
6803
6334
|
if (nextPaused) {
|
|
@@ -6811,15 +6342,15 @@ var Mutation = {
|
|
|
6811
6342
|
};
|
|
6812
6343
|
const initialSignal = await invokeMutationCallback({
|
|
6813
6344
|
mutationCount: 0,
|
|
6814
|
-
html:
|
|
6815
|
-
text:
|
|
6816
|
-
mutationNodes:
|
|
6345
|
+
html: state.html || "",
|
|
6346
|
+
text: state.text || "",
|
|
6347
|
+
mutationNodes: state.mutationNodes || []
|
|
6817
6348
|
});
|
|
6818
6349
|
applyPauseSignal(initialSignal);
|
|
6819
6350
|
const deadline = Date.now() + overallTimeout;
|
|
6820
|
-
let lastState =
|
|
6351
|
+
let lastState = state;
|
|
6821
6352
|
while (Date.now() < deadline) {
|
|
6822
|
-
await
|
|
6353
|
+
await sleep(pollInterval);
|
|
6823
6354
|
lastState = await buildState();
|
|
6824
6355
|
if (!lastState?.hasMatched) {
|
|
6825
6356
|
continue;
|
|
@@ -6827,7 +6358,7 @@ var Mutation = {
|
|
|
6827
6358
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6828
6359
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6829
6360
|
mutationCount += 1;
|
|
6830
|
-
|
|
6361
|
+
logger12.info(
|
|
6831
6362
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6832
6363
|
);
|
|
6833
6364
|
const signal = await invokeMutationCallback({
|
|
@@ -6840,7 +6371,7 @@ var Mutation = {
|
|
|
6840
6371
|
continue;
|
|
6841
6372
|
}
|
|
6842
6373
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6843
|
-
|
|
6374
|
+
logger12.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6844
6375
|
return {
|
|
6845
6376
|
mutationCount,
|
|
6846
6377
|
stableTime: waitForStableTime,
|
|
@@ -6867,7 +6398,7 @@ var Mutation = {
|
|
|
6867
6398
|
const onMutation = options.onMutation;
|
|
6868
6399
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6869
6400
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6870
|
-
|
|
6401
|
+
logger12.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6871
6402
|
const monitorKey = generateKey("pk_mon");
|
|
6872
6403
|
const callbackName = generateKey("pk_mon_cb");
|
|
6873
6404
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -7010,7 +6541,7 @@ var Mutation = {
|
|
|
7010
6541
|
return total;
|
|
7011
6542
|
};
|
|
7012
6543
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7013
|
-
|
|
6544
|
+
logger12.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7014
6545
|
return {
|
|
7015
6546
|
stop: async () => {
|
|
7016
6547
|
let totalMutations = 0;
|
|
@@ -7023,7 +6554,7 @@ var Mutation = {
|
|
|
7023
6554
|
}, cleanerName);
|
|
7024
6555
|
} catch (e) {
|
|
7025
6556
|
}
|
|
7026
|
-
|
|
6557
|
+
logger12.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
7027
6558
|
return { totalMutations };
|
|
7028
6559
|
}
|
|
7029
6560
|
};
|
|
@@ -7892,7 +7423,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7892
7423
|
};
|
|
7893
7424
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7894
7425
|
var Logger = {
|
|
7895
|
-
setLogger: (
|
|
7426
|
+
setLogger: (logger16) => setDefaultLogger(logger16),
|
|
7896
7427
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7897
7428
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7898
7429
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7900,14 +7431,14 @@ var Logger = {
|
|
|
7900
7431
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7901
7432
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7902
7433
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7903
|
-
useTemplate: (
|
|
7904
|
-
if (
|
|
7434
|
+
useTemplate: (logger16) => {
|
|
7435
|
+
if (logger16) return createTemplateLogger(createBaseLogger("", logger16));
|
|
7905
7436
|
return createTemplateLogger();
|
|
7906
7437
|
}
|
|
7907
7438
|
};
|
|
7908
7439
|
|
|
7909
7440
|
// src/share.js
|
|
7910
|
-
import
|
|
7441
|
+
import delay4 from "delay";
|
|
7911
7442
|
|
|
7912
7443
|
// src/internals/watermarkify.js
|
|
7913
7444
|
var DEFAULT_TIMEZONE_OFFSET = 8;
|
|
@@ -7975,7 +7506,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
7975
7506
|
];
|
|
7976
7507
|
var cachedStripLogoSrcPromise = null;
|
|
7977
7508
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
7978
|
-
var
|
|
7509
|
+
var logger13 = createInternalLogger("Watermarkify");
|
|
7979
7510
|
var normalizeText = (value) => String(value || "").trim();
|
|
7980
7511
|
var toInline = (value, maxLen = 200) => {
|
|
7981
7512
|
const text = normalizeText(value);
|
|
@@ -8217,9 +7748,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8217
7748
|
location: toInline(resolved.location, 80)
|
|
8218
7749
|
};
|
|
8219
7750
|
if (enrichment.ip || enrichment.location) {
|
|
8220
|
-
|
|
7751
|
+
logger13.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8221
7752
|
} else {
|
|
8222
|
-
|
|
7753
|
+
logger13.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8223
7754
|
}
|
|
8224
7755
|
return enrichment;
|
|
8225
7756
|
} finally {
|
|
@@ -8403,17 +7934,14 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8403
7934
|
</html>
|
|
8404
7935
|
`;
|
|
8405
7936
|
};
|
|
8406
|
-
var
|
|
8407
|
-
return String(value || "default").trim().toLowerCase() === "cloak" ? "cloak" : "default";
|
|
8408
|
-
};
|
|
8409
|
-
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
7937
|
+
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
8410
7938
|
if (!page || typeof page.context !== "function") {
|
|
8411
|
-
|
|
7939
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8412
7940
|
return buffer;
|
|
8413
7941
|
}
|
|
8414
7942
|
const renderScope = await openProbePage(page);
|
|
8415
7943
|
if (!renderScope?.page) {
|
|
8416
|
-
|
|
7944
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8417
7945
|
return buffer;
|
|
8418
7946
|
}
|
|
8419
7947
|
try {
|
|
@@ -8430,35 +7958,15 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8430
7958
|
height: viewportHeight
|
|
8431
7959
|
}).catch(() => {
|
|
8432
7960
|
});
|
|
8433
|
-
|
|
8434
|
-
|
|
8435
|
-
|
|
8436
|
-
|
|
8437
|
-
|
|
8438
|
-
|
|
8439
|
-
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
await renderPage.goto("about:blank", {
|
|
8443
|
-
waitUntil: "commit"
|
|
8444
|
-
}).catch(() => {
|
|
8445
|
-
});
|
|
8446
|
-
await renderPage.evaluate((html) => {
|
|
8447
|
-
document.open();
|
|
8448
|
-
document.write(html);
|
|
8449
|
-
document.close();
|
|
8450
|
-
}, renderHtml);
|
|
8451
|
-
} else {
|
|
8452
|
-
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
8453
|
-
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8454
|
-
overlaySvg,
|
|
8455
|
-
width: safeWidth,
|
|
8456
|
-
height: safeHeight,
|
|
8457
|
-
imageHeight: safeImageHeight
|
|
8458
|
-
}), {
|
|
8459
|
-
waitUntil: "load"
|
|
8460
|
-
});
|
|
8461
|
-
}
|
|
7961
|
+
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
7962
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
7963
|
+
overlaySvg,
|
|
7964
|
+
width: safeWidth,
|
|
7965
|
+
height: safeHeight,
|
|
7966
|
+
imageHeight: safeImageHeight
|
|
7967
|
+
}), {
|
|
7968
|
+
waitUntil: "load"
|
|
7969
|
+
});
|
|
8462
7970
|
await renderPage.waitForFunction(() => {
|
|
8463
7971
|
const image = document.getElementById("pk-base-image");
|
|
8464
7972
|
return image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0 && image.naturalHeight > 0;
|
|
@@ -8478,13 +7986,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8478
7986
|
fullPage: true,
|
|
8479
7987
|
animations: "disabled"
|
|
8480
7988
|
}).catch((error) => {
|
|
8481
|
-
|
|
7989
|
+
logger13.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8482
7990
|
return null;
|
|
8483
7991
|
});
|
|
8484
7992
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8485
7993
|
return composed;
|
|
8486
7994
|
}
|
|
8487
|
-
|
|
7995
|
+
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8488
7996
|
return buffer;
|
|
8489
7997
|
} finally {
|
|
8490
7998
|
await renderScope.close().catch(() => {
|
|
@@ -8497,7 +8005,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8497
8005
|
}
|
|
8498
8006
|
const probeScope = await openProbePage(page);
|
|
8499
8007
|
if (!probeScope?.page) {
|
|
8500
|
-
|
|
8008
|
+
logger13.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8501
8009
|
return null;
|
|
8502
8010
|
}
|
|
8503
8011
|
const timeoutMs = Math.max(
|
|
@@ -8506,12 +8014,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8506
8014
|
);
|
|
8507
8015
|
try {
|
|
8508
8016
|
const probePage = probeScope.page;
|
|
8509
|
-
|
|
8017
|
+
logger13.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8510
8018
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8511
8019
|
waitUntil: "commit",
|
|
8512
8020
|
timeout: timeoutMs
|
|
8513
8021
|
}).catch((error) => {
|
|
8514
|
-
|
|
8022
|
+
logger13.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8515
8023
|
return null;
|
|
8516
8024
|
});
|
|
8517
8025
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8533,13 +8041,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8533
8041
|
}
|
|
8534
8042
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8535
8043
|
if (parsed?.ip || parsed?.location) {
|
|
8536
|
-
|
|
8044
|
+
logger13.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8537
8045
|
return parsed;
|
|
8538
8046
|
}
|
|
8539
|
-
|
|
8047
|
+
logger13.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8540
8048
|
return null;
|
|
8541
8049
|
} catch (error) {
|
|
8542
|
-
|
|
8050
|
+
logger13.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8543
8051
|
return null;
|
|
8544
8052
|
} finally {
|
|
8545
8053
|
await probeScope.close().catch(() => {
|
|
@@ -8553,10 +8061,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8553
8061
|
ip: toInline(options.ip, 80),
|
|
8554
8062
|
location: toInline(options.location, 80)
|
|
8555
8063
|
};
|
|
8556
|
-
|
|
8064
|
+
logger13.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8557
8065
|
if (!merged.ip || !merged.location) {
|
|
8558
8066
|
if (cached?.ip || cached?.location) {
|
|
8559
|
-
|
|
8067
|
+
logger13.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8560
8068
|
}
|
|
8561
8069
|
fillEnrichment(merged, cached);
|
|
8562
8070
|
}
|
|
@@ -8580,15 +8088,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8580
8088
|
"x-geo-country"
|
|
8581
8089
|
]), 80);
|
|
8582
8090
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8583
|
-
|
|
8091
|
+
logger13.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8584
8092
|
merged.location = headerLocation || merged.location;
|
|
8585
8093
|
}
|
|
8586
8094
|
}
|
|
8587
8095
|
writeCachedEnrichment(page, merged);
|
|
8588
8096
|
if (merged.ip || merged.location) {
|
|
8589
|
-
|
|
8097
|
+
logger13.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8590
8098
|
} else {
|
|
8591
|
-
|
|
8099
|
+
logger13.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8592
8100
|
}
|
|
8593
8101
|
return merged;
|
|
8594
8102
|
};
|
|
@@ -9393,7 +8901,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
9393
8901
|
</svg>
|
|
9394
8902
|
`;
|
|
9395
8903
|
};
|
|
9396
|
-
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null
|
|
8904
|
+
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
9397
8905
|
const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
|
|
9398
8906
|
const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
|
|
9399
8907
|
if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
|
|
@@ -9401,7 +8909,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9401
8909
|
}
|
|
9402
8910
|
const imageInfo = readImageInfo(buffer);
|
|
9403
8911
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9404
|
-
|
|
8912
|
+
logger13.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9405
8913
|
return buffer;
|
|
9406
8914
|
}
|
|
9407
8915
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9414,12 +8922,12 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9414
8922
|
if (!overlaySvg) {
|
|
9415
8923
|
return buffer;
|
|
9416
8924
|
}
|
|
9417
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo
|
|
8925
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
9418
8926
|
};
|
|
9419
8927
|
|
|
9420
8928
|
// src/internals/compression.js
|
|
9421
8929
|
import { Jimp, JimpMime, ResizeStrategy } from "jimp";
|
|
9422
|
-
var
|
|
8930
|
+
var logger14 = createInternalLogger("Compression");
|
|
9423
8931
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9424
8932
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9425
8933
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9538,18 +9046,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9538
9046
|
return buffer.toString("base64");
|
|
9539
9047
|
}
|
|
9540
9048
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9541
|
-
|
|
9049
|
+
logger14.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9542
9050
|
return null;
|
|
9543
9051
|
});
|
|
9544
9052
|
if (!result?.buffer) {
|
|
9545
9053
|
return buffer.toString("base64");
|
|
9546
9054
|
}
|
|
9547
9055
|
if (result.withinLimit) {
|
|
9548
|
-
|
|
9056
|
+
logger14.info(
|
|
9549
9057
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9550
9058
|
);
|
|
9551
9059
|
} else {
|
|
9552
|
-
|
|
9060
|
+
logger14.warning(
|
|
9553
9061
|
`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}`
|
|
9554
9062
|
);
|
|
9555
9063
|
}
|
|
@@ -9557,7 +9065,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9557
9065
|
};
|
|
9558
9066
|
|
|
9559
9067
|
// src/share.js
|
|
9560
|
-
var
|
|
9068
|
+
var logger15 = createInternalLogger("Share");
|
|
9561
9069
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9562
9070
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9563
9071
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9694,7 +9202,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9694
9202
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9695
9203
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9696
9204
|
let matched = false;
|
|
9697
|
-
|
|
9205
|
+
logger15.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9698
9206
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9699
9207
|
mode,
|
|
9700
9208
|
onMutation: (context = {}) => {
|
|
@@ -9712,12 +9220,12 @@ ${text}`;
|
|
|
9712
9220
|
});
|
|
9713
9221
|
}
|
|
9714
9222
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9715
|
-
|
|
9223
|
+
logger15.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9716
9224
|
}
|
|
9717
9225
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9718
9226
|
if (!candidate) return;
|
|
9719
9227
|
matched = true;
|
|
9720
|
-
|
|
9228
|
+
logger15.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9721
9229
|
if (onMatch) {
|
|
9722
9230
|
onMatch({
|
|
9723
9231
|
link: candidate,
|
|
@@ -9733,7 +9241,7 @@ ${text}`;
|
|
|
9733
9241
|
return {
|
|
9734
9242
|
stop: async () => {
|
|
9735
9243
|
const result = await monitor.stop();
|
|
9736
|
-
|
|
9244
|
+
logger15.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9737
9245
|
return result;
|
|
9738
9246
|
}
|
|
9739
9247
|
};
|
|
@@ -9782,8 +9290,8 @@ var Share = {
|
|
|
9782
9290
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9783
9291
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9784
9292
|
}
|
|
9785
|
-
|
|
9786
|
-
|
|
9293
|
+
logger15.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9294
|
+
logger15.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9787
9295
|
const stats = {
|
|
9788
9296
|
actionTimedOut: false,
|
|
9789
9297
|
domMutationCount: 0,
|
|
@@ -9795,7 +9303,7 @@ var Share = {
|
|
|
9795
9303
|
responseSampleUrls: []
|
|
9796
9304
|
};
|
|
9797
9305
|
if (isAborted()) {
|
|
9798
|
-
|
|
9306
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9799
9307
|
return {
|
|
9800
9308
|
link: null,
|
|
9801
9309
|
payloadText: "",
|
|
@@ -9818,7 +9326,7 @@ var Share = {
|
|
|
9818
9326
|
link: validated,
|
|
9819
9327
|
payloadText: String(payloadText || "")
|
|
9820
9328
|
};
|
|
9821
|
-
|
|
9329
|
+
logger15.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9822
9330
|
return true;
|
|
9823
9331
|
};
|
|
9824
9332
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9853,7 +9361,7 @@ var Share = {
|
|
|
9853
9361
|
try {
|
|
9854
9362
|
await monitor.stop();
|
|
9855
9363
|
} catch (error) {
|
|
9856
|
-
|
|
9364
|
+
logger15.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9857
9365
|
}
|
|
9858
9366
|
};
|
|
9859
9367
|
const onResponse = async (response) => {
|
|
@@ -9867,29 +9375,29 @@ var Share = {
|
|
|
9867
9375
|
stats.responseSampleUrls.push(url);
|
|
9868
9376
|
}
|
|
9869
9377
|
if (stats.responseObserved <= 5) {
|
|
9870
|
-
|
|
9378
|
+
logger15.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9871
9379
|
}
|
|
9872
9380
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9873
9381
|
stats.responseMatched += 1;
|
|
9874
9382
|
stats.lastMatchedUrl = url;
|
|
9875
|
-
|
|
9383
|
+
logger15.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9876
9384
|
const text = await response.text();
|
|
9877
9385
|
const hit = resolveResponseCandidate(text);
|
|
9878
9386
|
if (!hit?.link) {
|
|
9879
9387
|
if (stats.responseMatched <= 3) {
|
|
9880
|
-
|
|
9388
|
+
logger15.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9881
9389
|
}
|
|
9882
9390
|
return;
|
|
9883
9391
|
}
|
|
9884
9392
|
stats.responseResolved += 1;
|
|
9885
|
-
|
|
9393
|
+
logger15.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9886
9394
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9887
9395
|
} catch (error) {
|
|
9888
|
-
|
|
9396
|
+
logger15.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9889
9397
|
}
|
|
9890
9398
|
};
|
|
9891
9399
|
if (share.mode === "dom") {
|
|
9892
|
-
|
|
9400
|
+
logger15.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9893
9401
|
domMonitor = await createDomShareMonitor(page, {
|
|
9894
9402
|
prefix: share.prefix,
|
|
9895
9403
|
selectors: domSelectors,
|
|
@@ -9904,17 +9412,17 @@ var Share = {
|
|
|
9904
9412
|
});
|
|
9905
9413
|
}
|
|
9906
9414
|
if (share.mode === "response") {
|
|
9907
|
-
|
|
9415
|
+
logger15.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9908
9416
|
page.on("response", onResponse);
|
|
9909
9417
|
}
|
|
9910
9418
|
if (share.mode === "custom") {
|
|
9911
|
-
|
|
9419
|
+
logger15.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9912
9420
|
}
|
|
9913
9421
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9914
9422
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9915
9423
|
try {
|
|
9916
9424
|
const actionTimeout = getRemainingMs();
|
|
9917
|
-
|
|
9425
|
+
logger15.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9918
9426
|
let actionValue;
|
|
9919
9427
|
if (!isAborted() && actionTimeout > 0) {
|
|
9920
9428
|
let timer = null;
|
|
@@ -9927,30 +9435,30 @@ var Share = {
|
|
|
9927
9435
|
]);
|
|
9928
9436
|
if (timer) clearTimeout(timer);
|
|
9929
9437
|
if (actionResult.type === "error") {
|
|
9930
|
-
|
|
9438
|
+
logger15.fail("captureLink.performActions", actionResult.error);
|
|
9931
9439
|
throw actionResult.error;
|
|
9932
9440
|
}
|
|
9933
9441
|
if (actionResult.type === "timeout") {
|
|
9934
9442
|
stats.actionTimedOut = true;
|
|
9935
|
-
|
|
9443
|
+
logger15.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9936
9444
|
} else {
|
|
9937
9445
|
actionValue = actionResult.result;
|
|
9938
|
-
|
|
9446
|
+
logger15.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9939
9447
|
}
|
|
9940
9448
|
}
|
|
9941
9449
|
if (share.mode === "custom") {
|
|
9942
9450
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9943
9451
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9944
9452
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9945
|
-
|
|
9453
|
+
logger15.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9946
9454
|
} else {
|
|
9947
|
-
|
|
9455
|
+
logger15.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9948
9456
|
}
|
|
9949
9457
|
}
|
|
9950
9458
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9951
9459
|
while (true) {
|
|
9952
9460
|
if (isAborted()) {
|
|
9953
|
-
|
|
9461
|
+
logger15.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9954
9462
|
return {
|
|
9955
9463
|
link: null,
|
|
9956
9464
|
payloadText: "",
|
|
@@ -9960,7 +9468,7 @@ var Share = {
|
|
|
9960
9468
|
}
|
|
9961
9469
|
const selected = candidates[share.mode];
|
|
9962
9470
|
if (selected?.link) {
|
|
9963
|
-
|
|
9471
|
+
logger15.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9964
9472
|
return {
|
|
9965
9473
|
link: selected.link,
|
|
9966
9474
|
payloadText: selected.payloadText,
|
|
@@ -9973,19 +9481,19 @@ var Share = {
|
|
|
9973
9481
|
if (remaining <= 0) break;
|
|
9974
9482
|
const now = Date.now();
|
|
9975
9483
|
if (now >= nextProgressLogTs) {
|
|
9976
|
-
|
|
9484
|
+
logger15.info(
|
|
9977
9485
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9978
9486
|
);
|
|
9979
9487
|
nextProgressLogTs = now + 5e3;
|
|
9980
9488
|
}
|
|
9981
|
-
await
|
|
9489
|
+
await delay4(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9982
9490
|
}
|
|
9983
9491
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9984
|
-
|
|
9492
|
+
logger15.warning(
|
|
9985
9493
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9986
9494
|
);
|
|
9987
9495
|
}
|
|
9988
|
-
|
|
9496
|
+
logger15.warning(
|
|
9989
9497
|
`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"}`
|
|
9990
9498
|
);
|
|
9991
9499
|
return {
|
|
@@ -9997,7 +9505,7 @@ var Share = {
|
|
|
9997
9505
|
} finally {
|
|
9998
9506
|
if (share.mode === "response") {
|
|
9999
9507
|
page.off("response", onResponse);
|
|
10000
|
-
|
|
9508
|
+
logger15.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
10001
9509
|
}
|
|
10002
9510
|
await stopDomMonitor();
|
|
10003
9511
|
}
|
|
@@ -10012,7 +9520,6 @@ var Share = {
|
|
|
10012
9520
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10013
9521
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10014
9522
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10015
|
-
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认 default
|
|
10016
9523
|
* @returns {Promise<string>} base64 image
|
|
10017
9524
|
*/
|
|
10018
9525
|
async captureScreen(page, options = {}) {
|
|
@@ -10033,9 +9540,7 @@ var Share = {
|
|
|
10033
9540
|
...screenshotWatermarkify,
|
|
10034
9541
|
capturedAt
|
|
10035
9542
|
});
|
|
10036
|
-
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page
|
|
10037
|
-
mode: options.mode
|
|
10038
|
-
});
|
|
9543
|
+
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page);
|
|
10039
9544
|
}
|
|
10040
9545
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
10041
9546
|
}
|
|
@@ -10043,9 +9548,8 @@ var Share = {
|
|
|
10043
9548
|
|
|
10044
9549
|
// entrys/node.js
|
|
10045
9550
|
Logger.setLogger(crawleeLog);
|
|
10046
|
-
var usePlaywrightToolKit = (
|
|
10047
|
-
|
|
10048
|
-
const toolkit = {
|
|
9551
|
+
var usePlaywrightToolKit = () => {
|
|
9552
|
+
return {
|
|
10049
9553
|
ApifyKit,
|
|
10050
9554
|
AntiCheat,
|
|
10051
9555
|
DeviceInput,
|
|
@@ -10065,7 +9569,6 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10065
9569
|
ByPass,
|
|
10066
9570
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
10067
9571
|
};
|
|
10068
|
-
return toolkit;
|
|
10069
9572
|
};
|
|
10070
9573
|
export {
|
|
10071
9574
|
usePlaywrightToolKit
|