@skrillex1224/playwright-toolkit 2.1.285 → 2.1.287
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 +245 -757
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +246 -758
- package/dist/index.js.map +4 -4
- package/dist/internals/proxy-meter.js +51 -5
- package/index.d.ts +6 -59
- package/package.json +1 -7
package/dist/index.cjs
CHANGED
|
@@ -40,11 +40,9 @@ __export(constants_exports, {
|
|
|
40
40
|
ActorInfo: () => ActorInfo,
|
|
41
41
|
Code: () => Code,
|
|
42
42
|
Device: () => Device,
|
|
43
|
-
Mode: () => Mode,
|
|
44
43
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
45
44
|
Status: () => Status,
|
|
46
|
-
normalizeDevice: () => normalizeDevice
|
|
47
|
-
normalizeMode: () => normalizeMode
|
|
45
|
+
normalizeDevice: () => normalizeDevice
|
|
48
46
|
});
|
|
49
47
|
var Code = {
|
|
50
48
|
Success: 0,
|
|
@@ -64,10 +62,6 @@ var Device = Object.freeze({
|
|
|
64
62
|
Desktop: "desktop",
|
|
65
63
|
Mobile: "mobile"
|
|
66
64
|
});
|
|
67
|
-
var Mode = Object.freeze({
|
|
68
|
-
Default: "default",
|
|
69
|
-
CloakBrowser: "cloakbrowser"
|
|
70
|
-
});
|
|
71
65
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
72
66
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
73
67
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -75,13 +69,6 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
75
69
|
if (raw === Device.Desktop) return Device.Desktop;
|
|
76
70
|
return normalizedFallback;
|
|
77
71
|
};
|
|
78
|
-
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
79
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.CloakBrowser ? Mode.CloakBrowser : Mode.Default;
|
|
80
|
-
const raw = String(value || "").trim().toLowerCase();
|
|
81
|
-
if (raw === Mode.CloakBrowser) return Mode.CloakBrowser;
|
|
82
|
-
if (raw === Mode.Default) return Mode.Default;
|
|
83
|
-
return normalizedFallback;
|
|
84
|
-
};
|
|
85
72
|
var createActorInfo = (info) => {
|
|
86
73
|
const normalizeDomain = (value) => {
|
|
87
74
|
if (!value) return "";
|
|
@@ -149,6 +136,7 @@ var createActorInfo = (info) => {
|
|
|
149
136
|
const buildLandingUrl = ({ protocol: protocol2, domain: domain2, path: path4 }) => {
|
|
150
137
|
const safeProtocol = String(protocol2).trim();
|
|
151
138
|
const safeDomain = normalizeDomain(domain2);
|
|
139
|
+
if (!safeDomain) return "";
|
|
152
140
|
const safePath = normalizePath(path4);
|
|
153
141
|
return `${safeProtocol}://${safeDomain}${safePath}`;
|
|
154
142
|
};
|
|
@@ -356,6 +344,18 @@ var ActorInfo = {
|
|
|
356
344
|
prefix: "",
|
|
357
345
|
xurl: []
|
|
358
346
|
}
|
|
347
|
+
}),
|
|
348
|
+
// 通用网页抓取 Actor:入口 URL 来自 query,因此这里只声明统一的 Actor 元信息。
|
|
349
|
+
webpage: createActorInfo({
|
|
350
|
+
key: "webpage",
|
|
351
|
+
name: "\u901A\u7528\u7F51\u9875",
|
|
352
|
+
domain: "",
|
|
353
|
+
path: "/",
|
|
354
|
+
share: {
|
|
355
|
+
mode: "dom",
|
|
356
|
+
prefix: "",
|
|
357
|
+
xurl: []
|
|
358
|
+
}
|
|
359
359
|
})
|
|
360
360
|
};
|
|
361
361
|
|
|
@@ -780,7 +780,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
780
780
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
781
781
|
return 0;
|
|
782
782
|
}
|
|
783
|
-
const
|
|
783
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
784
784
|
const isVisible = (el, style, rect) => {
|
|
785
785
|
if (!el || !style || !rect) return false;
|
|
786
786
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -820,7 +820,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
820
820
|
return true;
|
|
821
821
|
});
|
|
822
822
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
823
|
-
if (!
|
|
823
|
+
if (!hasOwn(el.dataset, "pkAffixedAdjusted")) {
|
|
824
824
|
el.dataset.pkAffixedAdjusted = "1";
|
|
825
825
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
826
826
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -851,7 +851,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
851
851
|
};
|
|
852
852
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
853
853
|
await page.evaluate((className) => {
|
|
854
|
-
const
|
|
854
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
855
855
|
const expansionKeys = [
|
|
856
856
|
"pkOrigOverflow",
|
|
857
857
|
"pkOrigHeight",
|
|
@@ -859,28 +859,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
859
859
|
"pkOrigMaxHeight"
|
|
860
860
|
];
|
|
861
861
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
862
|
-
if (
|
|
862
|
+
if (hasOwn(el.dataset, "pkOrigPosition")) {
|
|
863
863
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
864
864
|
delete el.dataset.pkOrigPosition;
|
|
865
865
|
delete el.dataset.pkOrigPositionPriority;
|
|
866
866
|
}
|
|
867
|
-
if (
|
|
867
|
+
if (hasOwn(el.dataset, "pkOrigTop")) {
|
|
868
868
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
869
869
|
delete el.dataset.pkOrigTop;
|
|
870
870
|
delete el.dataset.pkOrigTopPriority;
|
|
871
871
|
}
|
|
872
|
-
if (
|
|
872
|
+
if (hasOwn(el.dataset, "pkOrigBottom")) {
|
|
873
873
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
874
874
|
delete el.dataset.pkOrigBottom;
|
|
875
875
|
delete el.dataset.pkOrigBottomPriority;
|
|
876
876
|
}
|
|
877
|
-
if (
|
|
877
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
878
878
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
879
879
|
delete el.dataset.pkOrigTranslate;
|
|
880
880
|
delete el.dataset.pkOrigTranslatePriority;
|
|
881
881
|
}
|
|
882
882
|
delete el.dataset.pkAffixedAdjusted;
|
|
883
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
883
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
884
884
|
if (!stillExpanded) {
|
|
885
885
|
el.classList.remove(className);
|
|
886
886
|
}
|
|
@@ -923,7 +923,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
923
923
|
viewportResized
|
|
924
924
|
};
|
|
925
925
|
};
|
|
926
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
926
|
+
var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
927
927
|
await page.evaluate((className) => {
|
|
928
928
|
const targets = new Set([
|
|
929
929
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -947,8 +947,8 @@ var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
|
947
947
|
el.classList.remove(className);
|
|
948
948
|
});
|
|
949
949
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
950
|
-
if (
|
|
951
|
-
await page.setViewportSize(
|
|
950
|
+
if (state?.originalViewport && state?.viewportResized) {
|
|
951
|
+
await page.setViewportSize(state.originalViewport);
|
|
952
952
|
}
|
|
953
953
|
};
|
|
954
954
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -1005,21 +1005,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
1005
1005
|
}
|
|
1006
1006
|
};
|
|
1007
1007
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
1008
|
-
const
|
|
1008
|
+
const state = await prepareExpandedFullPageScreenshot(page, options);
|
|
1009
1009
|
try {
|
|
1010
1010
|
return await capturePageScreenshot(page, {
|
|
1011
1011
|
fullPage: true,
|
|
1012
1012
|
type: options.type || "png",
|
|
1013
1013
|
quality: options.quality,
|
|
1014
1014
|
timeout: options.timeout,
|
|
1015
|
-
maxClipHeight:
|
|
1015
|
+
maxClipHeight: state.targetHeight
|
|
1016
1016
|
});
|
|
1017
1017
|
} finally {
|
|
1018
1018
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
1019
1019
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
1020
1020
|
});
|
|
1021
1021
|
if (options.restore) {
|
|
1022
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
1022
|
+
await restoreExpandedFullPageScreenshot(page, state);
|
|
1023
1023
|
}
|
|
1024
1024
|
}
|
|
1025
1025
|
};
|
|
@@ -1196,6 +1196,19 @@ var ensureLogPath = () => {
|
|
|
1196
1196
|
const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
|
|
1197
1197
|
return import_path.default.join(baseDir, label);
|
|
1198
1198
|
};
|
|
1199
|
+
var ensureStdioLogPath = (logPath) => `${logPath}.stdio.log`;
|
|
1200
|
+
var writeChildOutput = (stream, output, prefix) => {
|
|
1201
|
+
if (!stream || !output) return;
|
|
1202
|
+
output.on("data", (chunk) => {
|
|
1203
|
+
const text = chunk?.toString?.() || String(chunk || "");
|
|
1204
|
+
if (!text) return;
|
|
1205
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1206
|
+
if (!line) continue;
|
|
1207
|
+
stream.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${prefix} ${line}
|
|
1208
|
+
`);
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
};
|
|
1199
1212
|
var readSnapshot = (logPath) => {
|
|
1200
1213
|
if (!logPath || !(0, import_fs.existsSync)(logPath)) return null;
|
|
1201
1214
|
try {
|
|
@@ -1363,6 +1376,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
1363
1376
|
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
1364
1377
|
const port = pickFreePort();
|
|
1365
1378
|
const logPath = ensureLogPath();
|
|
1379
|
+
const stdioLogPath = ensureStdioLogPath(logPath);
|
|
1366
1380
|
const scriptPath = resolveScriptPath();
|
|
1367
1381
|
const debugMode = Boolean(options.debugMode);
|
|
1368
1382
|
const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
|
|
@@ -1375,19 +1389,28 @@ var startProxyMeter = (options = {}) => {
|
|
|
1375
1389
|
PROXY_METER_DEBUG: debugMode ? "1" : "0",
|
|
1376
1390
|
PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
|
|
1377
1391
|
};
|
|
1392
|
+
const stdioLog = (0, import_fs.createWriteStream)(stdioLogPath, { flags: "a" });
|
|
1393
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] start script=${scriptPath} port=${port} snapshot=${logPath}
|
|
1394
|
+
`);
|
|
1378
1395
|
const child = (0, import_child_process.spawn)(process.execPath, [scriptPath], {
|
|
1379
1396
|
env,
|
|
1380
|
-
stdio: ["ignore", "
|
|
1397
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1381
1398
|
});
|
|
1382
|
-
child.
|
|
1399
|
+
writeChildOutput(stdioLog, child.stdout, "stdout");
|
|
1400
|
+
writeChildOutput(stdioLog, child.stderr, "stderr");
|
|
1401
|
+
child.once("exit", (code, signal) => {
|
|
1402
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] exit code=${code ?? ""} signal=${signal ?? ""}
|
|
1403
|
+
`);
|
|
1404
|
+
stdioLog.end();
|
|
1383
1405
|
if (code && code !== 0) {
|
|
1384
|
-
logger2.warn(`[proxy-meter] exited with code ${code}`);
|
|
1406
|
+
logger2.warn(`[proxy-meter] exited with code ${code}; stdio=${stdioLogPath}`);
|
|
1385
1407
|
}
|
|
1386
1408
|
});
|
|
1387
1409
|
runtime = {
|
|
1388
1410
|
proc: child,
|
|
1389
1411
|
port,
|
|
1390
1412
|
logPath,
|
|
1413
|
+
stdioLogPath,
|
|
1391
1414
|
startedAt: Date.now()
|
|
1392
1415
|
};
|
|
1393
1416
|
registerCleanup();
|
|
@@ -1915,8 +1938,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1915
1938
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1916
1939
|
};
|
|
1917
1940
|
};
|
|
1918
|
-
var rememberRuntimeState = (
|
|
1919
|
-
rememberedRuntimeState = deepClone(
|
|
1941
|
+
var rememberRuntimeState = (state) => {
|
|
1942
|
+
rememberedRuntimeState = deepClone(state);
|
|
1920
1943
|
return rememberedRuntimeState;
|
|
1921
1944
|
};
|
|
1922
1945
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1975,7 +1998,7 @@ var RuntimeEnv = {
|
|
|
1975
1998
|
} else {
|
|
1976
1999
|
delete normalizedRuntime.browser_profile;
|
|
1977
2000
|
}
|
|
1978
|
-
const
|
|
2001
|
+
const state = {
|
|
1979
2002
|
actor: resolvedActor,
|
|
1980
2003
|
device,
|
|
1981
2004
|
runtime: normalizedRuntime,
|
|
@@ -1989,73 +2012,73 @@ var RuntimeEnv = {
|
|
|
1989
2012
|
browserProfileCore: browserProfile.core,
|
|
1990
2013
|
browserProfileObserved: browserProfile.observed
|
|
1991
2014
|
};
|
|
1992
|
-
rememberRuntimeState(
|
|
1993
|
-
return
|
|
2015
|
+
rememberRuntimeState(state);
|
|
2016
|
+
return state;
|
|
1994
2017
|
},
|
|
1995
2018
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
1996
2019
|
buildEnvPatch(source = {}, actor = "") {
|
|
1997
|
-
const
|
|
1998
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
2020
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2021
|
+
const browserProfile = buildBrowserProfilePayload(state.browserProfileCore, state.browserProfileObserved);
|
|
1999
2022
|
const envPatch = {
|
|
2000
|
-
...Array.isArray(
|
|
2001
|
-
...Object.keys(
|
|
2002
|
-
...Object.keys(
|
|
2023
|
+
...Array.isArray(state.cookies) && state.cookies.length > 0 ? { cookies: state.cookies } : {},
|
|
2024
|
+
...Object.keys(state.localStorage || {}).length > 0 ? { local_storage: state.localStorage } : {},
|
|
2025
|
+
...Object.keys(state.sessionStorage || {}).length > 0 ? { session_storage: state.sessionStorage } : {},
|
|
2003
2026
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
2004
2027
|
};
|
|
2005
2028
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
2006
2029
|
},
|
|
2007
2030
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
2008
2031
|
hasLoginState(source = {}, actor = "") {
|
|
2009
|
-
const
|
|
2010
|
-
return isPlainObject(
|
|
2032
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2033
|
+
return isPlainObject(state.runtime) && Object.keys(state.runtime || {}).length > 0;
|
|
2011
2034
|
},
|
|
2012
2035
|
rememberState(source = {}) {
|
|
2013
|
-
const
|
|
2014
|
-
rememberRuntimeState(
|
|
2036
|
+
const state = normalizeRuntimeState(source);
|
|
2037
|
+
rememberRuntimeState(state);
|
|
2015
2038
|
return RuntimeEnv.peekRememberedState();
|
|
2016
2039
|
},
|
|
2017
2040
|
peekRememberedState() {
|
|
2018
2041
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
2019
2042
|
},
|
|
2020
2043
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
2021
|
-
const
|
|
2022
|
-
return deepClone(
|
|
2044
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2045
|
+
return deepClone(state.browserProfileCore || {});
|
|
2023
2046
|
},
|
|
2024
2047
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
2025
|
-
const
|
|
2048
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2026
2049
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
2027
2050
|
...core,
|
|
2028
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2051
|
+
device: normalizeKnownDevice(core?.device) || state.device
|
|
2029
2052
|
});
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
if (Object.keys(
|
|
2033
|
-
|
|
2053
|
+
state.browserProfileCore = normalizedCore;
|
|
2054
|
+
state.browserProfile = buildBrowserProfilePayload(normalizedCore, state.browserProfileObserved);
|
|
2055
|
+
if (Object.keys(state.browserProfile).length > 0) {
|
|
2056
|
+
state.runtime.browser_profile = state.browserProfile;
|
|
2034
2057
|
} else {
|
|
2035
|
-
delete
|
|
2058
|
+
delete state.runtime.browser_profile;
|
|
2036
2059
|
}
|
|
2037
|
-
rememberRuntimeState(
|
|
2038
|
-
return
|
|
2060
|
+
rememberRuntimeState(state);
|
|
2061
|
+
return state;
|
|
2039
2062
|
},
|
|
2040
2063
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2041
2064
|
// cookies / localStorage / sessionStorage。
|
|
2042
2065
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2043
2066
|
async applyToPage(page, source = {}, options = {}) {
|
|
2044
2067
|
if (!page) return;
|
|
2045
|
-
let
|
|
2068
|
+
let state = normalizeRuntimeState(source, options?.actor || "");
|
|
2046
2069
|
if (typeof options?.preapply === "function") {
|
|
2047
|
-
|
|
2048
|
-
rememberRuntimeState(
|
|
2070
|
+
state = await options.preapply(state) || state;
|
|
2071
|
+
rememberRuntimeState(state);
|
|
2049
2072
|
}
|
|
2050
2073
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2051
2074
|
configurable: true,
|
|
2052
2075
|
enumerable: false,
|
|
2053
2076
|
writable: true,
|
|
2054
|
-
value:
|
|
2077
|
+
value: state
|
|
2055
2078
|
});
|
|
2056
|
-
const localStorage =
|
|
2057
|
-
const sessionStorage =
|
|
2058
|
-
const cookies = (
|
|
2079
|
+
const localStorage = state.localStorage || {};
|
|
2080
|
+
const sessionStorage = state.sessionStorage || {};
|
|
2081
|
+
const cookies = (state.cookies || []).map((cookie) => {
|
|
2059
2082
|
const normalized = { ...cookie };
|
|
2060
2083
|
if (!normalized.path) {
|
|
2061
2084
|
normalized.path = "/";
|
|
@@ -2093,8 +2116,8 @@ var RuntimeEnv = {
|
|
|
2093
2116
|
},
|
|
2094
2117
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2095
2118
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2096
|
-
const
|
|
2097
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2119
|
+
const state = normalizeRuntimeState(source, options?.actor || "");
|
|
2120
|
+
const baseline = RuntimeEnv.buildEnvPatch(state) || {};
|
|
2098
2121
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2099
2122
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2100
2123
|
}
|
|
@@ -2113,7 +2136,7 @@ var RuntimeEnv = {
|
|
|
2113
2136
|
cookies
|
|
2114
2137
|
},
|
|
2115
2138
|
{
|
|
2116
|
-
browserProfileCore:
|
|
2139
|
+
browserProfileCore: state.browserProfileCore
|
|
2117
2140
|
}
|
|
2118
2141
|
);
|
|
2119
2142
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2127,11 +2150,11 @@ var RuntimeEnv = {
|
|
|
2127
2150
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2128
2151
|
var resolveRuntimeContext = (input) => {
|
|
2129
2152
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2130
|
-
const
|
|
2131
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2153
|
+
const state = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2154
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state) || null;
|
|
2132
2155
|
return {
|
|
2133
|
-
actor:
|
|
2134
|
-
runtime:
|
|
2156
|
+
actor: state.actor,
|
|
2157
|
+
runtime: state.runtime,
|
|
2135
2158
|
envPatch
|
|
2136
2159
|
};
|
|
2137
2160
|
};
|
|
@@ -2490,58 +2513,8 @@ var Utils = {
|
|
|
2490
2513
|
}
|
|
2491
2514
|
};
|
|
2492
2515
|
|
|
2493
|
-
// src/
|
|
2494
|
-
var
|
|
2495
|
-
mode: Mode.Default
|
|
2496
|
-
};
|
|
2497
|
-
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2498
|
-
var ToolkitContext = {
|
|
2499
|
-
get mode() {
|
|
2500
|
-
return state.mode;
|
|
2501
|
-
},
|
|
2502
|
-
setMode(mode = Mode.Default) {
|
|
2503
|
-
state.mode = normalizeMode(mode, Mode.Default);
|
|
2504
|
-
return state.mode;
|
|
2505
|
-
}
|
|
2506
|
-
};
|
|
2507
|
-
var getToolkitMode = () => state.mode;
|
|
2508
|
-
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2509
|
-
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2510
|
-
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2511
|
-
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2512
|
-
const delegate = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2513
|
-
return {
|
|
2514
|
-
mode: normalizedMode,
|
|
2515
|
-
delegate
|
|
2516
|
-
};
|
|
2517
|
-
};
|
|
2518
|
-
|
|
2519
|
-
// src/internals/delegate.js
|
|
2520
|
-
var normalizeMethodDefinition = (definition) => typeof definition === "string" ? { name: definition, enumerable: true } : {
|
|
2521
|
-
name: String(definition?.name || "").trim(),
|
|
2522
|
-
enumerable: definition?.enumerable !== false
|
|
2523
|
-
};
|
|
2524
|
-
var createMethodDescriptor = (namespace, methodName, enumerable, strategies) => ({
|
|
2525
|
-
enumerable,
|
|
2526
|
-
value: (...args) => {
|
|
2527
|
-
const { mode, delegate } = resolveModeStrategy(strategies);
|
|
2528
|
-
if (typeof delegate?.[methodName] !== "function") {
|
|
2529
|
-
throw new Error(`${namespace}.${methodName} is not available in ${mode} mode`);
|
|
2530
|
-
}
|
|
2531
|
-
return delegate[methodName](...args);
|
|
2532
|
-
}
|
|
2533
|
-
});
|
|
2534
|
-
var createDelegatedFacade = (namespace, strategies = {}, methods = []) => {
|
|
2535
|
-
const descriptors = Object.fromEntries(
|
|
2536
|
-
methods.map(normalizeMethodDefinition).filter((method) => method.name).map((method) => [
|
|
2537
|
-
method.name,
|
|
2538
|
-
createMethodDescriptor(namespace, method.name, method.enumerable, strategies)
|
|
2539
|
-
])
|
|
2540
|
-
);
|
|
2541
|
-
return Object.defineProperties({}, descriptors);
|
|
2542
|
-
};
|
|
2543
|
-
|
|
2544
|
-
// src/internals/anti-cheat/default.js
|
|
2516
|
+
// src/anti-cheat.js
|
|
2517
|
+
var logger5 = createInternalLogger("AntiCheat");
|
|
2545
2518
|
var BASE_CONFIG = Object.freeze({
|
|
2546
2519
|
locale: "zh-CN",
|
|
2547
2520
|
acceptLanguage: "zh-CN,zh;q=0.9",
|
|
@@ -2576,7 +2549,7 @@ function buildFingerprintOptions({ locale = BASE_CONFIG.locale, browserMajorVers
|
|
|
2576
2549
|
}
|
|
2577
2550
|
return options;
|
|
2578
2551
|
}
|
|
2579
|
-
var
|
|
2552
|
+
var AntiCheat = {
|
|
2580
2553
|
/**
|
|
2581
2554
|
* 获取统一的基础配置
|
|
2582
2555
|
*/
|
|
@@ -2613,53 +2586,6 @@ var DefaultAntiCheat = {
|
|
|
2613
2586
|
}
|
|
2614
2587
|
};
|
|
2615
2588
|
|
|
2616
|
-
// src/internals/anti-cheat/cloakbrowser.js
|
|
2617
|
-
var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
2618
|
-
locale: "",
|
|
2619
|
-
acceptLanguage: "",
|
|
2620
|
-
timezoneId: "",
|
|
2621
|
-
timezoneOffset: null,
|
|
2622
|
-
geolocation: null
|
|
2623
|
-
});
|
|
2624
|
-
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2625
|
-
var CloakBrowserAntiCheat = {
|
|
2626
|
-
/**
|
|
2627
|
-
* CloakBrowser 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2628
|
-
*/
|
|
2629
|
-
getBaseConfig() {
|
|
2630
|
-
return { ...CLOAK_BROWSER_BASE_CONFIG };
|
|
2631
|
-
},
|
|
2632
|
-
getFingerprintGeneratorOptions() {
|
|
2633
|
-
return {};
|
|
2634
|
-
},
|
|
2635
|
-
getLaunchArgs() {
|
|
2636
|
-
return [];
|
|
2637
|
-
},
|
|
2638
|
-
getTlsFingerprintOptions() {
|
|
2639
|
-
return {};
|
|
2640
|
-
},
|
|
2641
|
-
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2642
|
-
const normalizedHeaders = normalizeHeaders(headers);
|
|
2643
|
-
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2644
|
-
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2645
|
-
}
|
|
2646
|
-
return normalizedHeaders;
|
|
2647
|
-
}
|
|
2648
|
-
};
|
|
2649
|
-
|
|
2650
|
-
// src/anti-cheat.js
|
|
2651
|
-
var antiCheatStrategies = {
|
|
2652
|
-
[Mode.Default]: DefaultAntiCheat,
|
|
2653
|
-
[Mode.CloakBrowser]: CloakBrowserAntiCheat
|
|
2654
|
-
};
|
|
2655
|
-
var AntiCheat = createDelegatedFacade("AntiCheat", antiCheatStrategies, [
|
|
2656
|
-
"getBaseConfig",
|
|
2657
|
-
"getFingerprintGeneratorOptions",
|
|
2658
|
-
"getLaunchArgs",
|
|
2659
|
-
"getTlsFingerprintOptions",
|
|
2660
|
-
"applyLocaleHeaders"
|
|
2661
|
-
]);
|
|
2662
|
-
|
|
2663
2589
|
// src/device-input.js
|
|
2664
2590
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2665
2591
|
var assertPage = (page, method) => {
|
|
@@ -3059,12 +2985,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
3059
2985
|
}
|
|
3060
2986
|
return resolved;
|
|
3061
2987
|
};
|
|
3062
|
-
var attachRuntimeState = (page,
|
|
2988
|
+
var attachRuntimeState = (page, state) => {
|
|
3063
2989
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
3064
2990
|
configurable: true,
|
|
3065
2991
|
enumerable: false,
|
|
3066
2992
|
writable: true,
|
|
3067
|
-
value:
|
|
2993
|
+
value: state
|
|
3068
2994
|
});
|
|
3069
2995
|
};
|
|
3070
2996
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -3213,7 +3139,7 @@ var DeviceView = {
|
|
|
3213
3139
|
// src/internals/humanize/desktop.js
|
|
3214
3140
|
var import_delay2 = __toESM(require("delay"), 1);
|
|
3215
3141
|
var import_ghost_cursor_playwright = require("ghost-cursor-playwright");
|
|
3216
|
-
var
|
|
3142
|
+
var logger6 = createInternalLogger("Humanize");
|
|
3217
3143
|
var $CursorWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3218
3144
|
function $GetCursor(page) {
|
|
3219
3145
|
const cursor = $CursorWeakMap.get(page);
|
|
@@ -3241,13 +3167,13 @@ var Humanize = {
|
|
|
3241
3167
|
*/
|
|
3242
3168
|
async initializeCursor(page) {
|
|
3243
3169
|
if ($CursorWeakMap.has(page)) {
|
|
3244
|
-
|
|
3170
|
+
logger6.debug("initializeCursor: cursor already exists, skipping");
|
|
3245
3171
|
return;
|
|
3246
3172
|
}
|
|
3247
|
-
|
|
3173
|
+
logger6.start("initializeCursor", "creating cursor");
|
|
3248
3174
|
const cursor = await (0, import_ghost_cursor_playwright.createCursor)(page);
|
|
3249
3175
|
$CursorWeakMap.set(page, cursor);
|
|
3250
|
-
|
|
3176
|
+
logger6.success("initializeCursor", "cursor initialized");
|
|
3251
3177
|
},
|
|
3252
3178
|
/**
|
|
3253
3179
|
* 人类化鼠标移动 - 使用 ghost-cursor 移动到指定位置或元素
|
|
@@ -3257,17 +3183,17 @@ var Humanize = {
|
|
|
3257
3183
|
*/
|
|
3258
3184
|
async humanMove(page, target) {
|
|
3259
3185
|
const cursor = $GetCursor(page);
|
|
3260
|
-
|
|
3186
|
+
logger6.start("humanMove", `target=${typeof target === "string" ? target : "element/coords"}`);
|
|
3261
3187
|
try {
|
|
3262
3188
|
if (typeof target === "string") {
|
|
3263
3189
|
const element = await page.$(target);
|
|
3264
3190
|
if (!element) {
|
|
3265
|
-
|
|
3191
|
+
logger6.warn(`humanMove: \u5143\u7D20\u4E0D\u5B58\u5728 ${target}`);
|
|
3266
3192
|
return false;
|
|
3267
3193
|
}
|
|
3268
3194
|
const box = await element.boundingBox();
|
|
3269
3195
|
if (!box) {
|
|
3270
|
-
|
|
3196
|
+
logger6.warn(`humanMove: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E ${target}`);
|
|
3271
3197
|
return false;
|
|
3272
3198
|
}
|
|
3273
3199
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.2;
|
|
@@ -3283,10 +3209,10 @@ var Humanize = {
|
|
|
3283
3209
|
await cursor.actions.move({ x, y });
|
|
3284
3210
|
}
|
|
3285
3211
|
}
|
|
3286
|
-
|
|
3212
|
+
logger6.success("humanMove");
|
|
3287
3213
|
return true;
|
|
3288
3214
|
} catch (error) {
|
|
3289
|
-
|
|
3215
|
+
logger6.fail("humanMove", error);
|
|
3290
3216
|
throw error;
|
|
3291
3217
|
}
|
|
3292
3218
|
},
|
|
@@ -3310,12 +3236,12 @@ var Humanize = {
|
|
|
3310
3236
|
maxDurationMs = maxSteps * 220 + 800
|
|
3311
3237
|
} = options;
|
|
3312
3238
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
3313
|
-
|
|
3239
|
+
logger6.start("humanScroll", `target=${targetDesc}`);
|
|
3314
3240
|
let element;
|
|
3315
3241
|
if (typeof target === "string") {
|
|
3316
3242
|
element = await page.$(target);
|
|
3317
3243
|
if (!element) {
|
|
3318
|
-
|
|
3244
|
+
logger6.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${target}`);
|
|
3319
3245
|
return { element: null, didScroll: false };
|
|
3320
3246
|
}
|
|
3321
3247
|
} else {
|
|
@@ -3390,26 +3316,26 @@ var Humanize = {
|
|
|
3390
3316
|
try {
|
|
3391
3317
|
for (let i = 0; i < maxSteps; i++) {
|
|
3392
3318
|
if (Date.now() - startTime > maxDurationMs) {
|
|
3393
|
-
|
|
3319
|
+
logger6.warn(`humanScroll | \u8D85\u65F6\u4FDD\u62A4\u89E6\u53D1 (${maxDurationMs}ms)`);
|
|
3394
3320
|
return { element, didScroll };
|
|
3395
3321
|
}
|
|
3396
3322
|
const status = await checkVisibility();
|
|
3397
3323
|
if (status.code === "VISIBLE") {
|
|
3398
3324
|
if (status.isFixed) {
|
|
3399
|
-
|
|
3325
|
+
logger6.info("humanScroll | fixed \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3400
3326
|
} else {
|
|
3401
|
-
|
|
3327
|
+
logger6.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
3402
3328
|
}
|
|
3403
|
-
|
|
3329
|
+
logger6.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
3404
3330
|
return { element, didScroll };
|
|
3405
3331
|
}
|
|
3406
|
-
|
|
3332
|
+
logger6.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason} ${status.direction ? `(${status.direction})` : ""}`);
|
|
3407
3333
|
if (status.code === "OBSTRUCTED" && status.obstruction) {
|
|
3408
|
-
|
|
3334
|
+
logger6.debug(`humanScroll | \u88AB\u4EE5\u4E0B\u5143\u7D20\u906E\u6321 <${status.obstruction.tag} id="${status.obstruction.id}">`);
|
|
3409
3335
|
}
|
|
3410
3336
|
const scrollRect = await getScrollableRect2();
|
|
3411
3337
|
if (!scrollRect && status.isFixed) {
|
|
3412
|
-
|
|
3338
|
+
logger6.warn("humanScroll | fixed \u5BB9\u5668\u5185\u4E14\u65E0\u53EF\u6EDA\u52A8\u7956\u5148\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3413
3339
|
return { element, didScroll };
|
|
3414
3340
|
}
|
|
3415
3341
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
@@ -3445,10 +3371,10 @@ var Humanize = {
|
|
|
3445
3371
|
didScroll = true;
|
|
3446
3372
|
await (0, import_delay2.default)(this.jitterMs(20 + Math.random() * 40, 0.2));
|
|
3447
3373
|
}
|
|
3448
|
-
|
|
3374
|
+
logger6.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
3449
3375
|
return { element, didScroll };
|
|
3450
3376
|
} catch (error) {
|
|
3451
|
-
|
|
3377
|
+
logger6.fail("humanScroll", error);
|
|
3452
3378
|
throw error;
|
|
3453
3379
|
}
|
|
3454
3380
|
},
|
|
@@ -3466,7 +3392,7 @@ var Humanize = {
|
|
|
3466
3392
|
const cursor = $GetCursor(page);
|
|
3467
3393
|
const { reactionDelay = 250, throwOnMissing = true, scrollIfNeeded = true, restore = false } = options;
|
|
3468
3394
|
const targetDesc = target == null ? "Current Position" : typeof target === "string" ? target : "ElementHandle";
|
|
3469
|
-
|
|
3395
|
+
logger6.start("humanClick", `target=${targetDesc}`);
|
|
3470
3396
|
const restoreOnce = async () => {
|
|
3471
3397
|
if (restoreOnce.restored) return;
|
|
3472
3398
|
restoreOnce.restored = true;
|
|
@@ -3475,14 +3401,14 @@ var Humanize = {
|
|
|
3475
3401
|
await (0, import_delay2.default)(this.jitterMs(1e3));
|
|
3476
3402
|
await restoreOnce.do();
|
|
3477
3403
|
} catch (restoreError) {
|
|
3478
|
-
|
|
3404
|
+
logger6.warn(`humanClick: \u6062\u590D\u6EDA\u52A8\u4F4D\u7F6E\u5931\u8D25: ${restoreError.message}`);
|
|
3479
3405
|
}
|
|
3480
3406
|
};
|
|
3481
3407
|
try {
|
|
3482
3408
|
if (target == null) {
|
|
3483
3409
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3484
3410
|
await cursor.actions.click();
|
|
3485
|
-
|
|
3411
|
+
logger6.success("humanClick", "Clicked current position");
|
|
3486
3412
|
return true;
|
|
3487
3413
|
}
|
|
3488
3414
|
let element;
|
|
@@ -3492,7 +3418,7 @@ var Humanize = {
|
|
|
3492
3418
|
if (throwOnMissing) {
|
|
3493
3419
|
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${target}`);
|
|
3494
3420
|
}
|
|
3495
|
-
|
|
3421
|
+
logger6.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${target}`);
|
|
3496
3422
|
return false;
|
|
3497
3423
|
}
|
|
3498
3424
|
} else {
|
|
@@ -3508,7 +3434,7 @@ var Humanize = {
|
|
|
3508
3434
|
if (throwOnMissing) {
|
|
3509
3435
|
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
3510
3436
|
}
|
|
3511
|
-
|
|
3437
|
+
logger6.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
3512
3438
|
return false;
|
|
3513
3439
|
}
|
|
3514
3440
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.3;
|
|
@@ -3517,11 +3443,11 @@ var Humanize = {
|
|
|
3517
3443
|
await (0, import_delay2.default)(this.jitterMs(reactionDelay, 0.4));
|
|
3518
3444
|
await cursor.actions.click();
|
|
3519
3445
|
await restoreOnce();
|
|
3520
|
-
|
|
3446
|
+
logger6.success("humanClick");
|
|
3521
3447
|
return true;
|
|
3522
3448
|
} catch (error) {
|
|
3523
3449
|
await restoreOnce();
|
|
3524
|
-
|
|
3450
|
+
logger6.fail("humanClick", error);
|
|
3525
3451
|
throw error;
|
|
3526
3452
|
}
|
|
3527
3453
|
},
|
|
@@ -3532,9 +3458,9 @@ var Humanize = {
|
|
|
3532
3458
|
*/
|
|
3533
3459
|
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
3534
3460
|
const ms = this.jitterMs(baseMs, jitterPercent);
|
|
3535
|
-
|
|
3461
|
+
logger6.start("randomSleep", `base=${baseMs}, actual=${ms}ms`);
|
|
3536
3462
|
await (0, import_delay2.default)(ms);
|
|
3537
|
-
|
|
3463
|
+
logger6.success("randomSleep");
|
|
3538
3464
|
},
|
|
3539
3465
|
/**
|
|
3540
3466
|
* 模拟人类"注视"或"阅读"行为:鼠标在页面上随机微动
|
|
@@ -3544,7 +3470,7 @@ var Humanize = {
|
|
|
3544
3470
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
3545
3471
|
const cursor = $GetCursor(page);
|
|
3546
3472
|
const durationMs = this.jitterMs(baseDurationMs, 0.4);
|
|
3547
|
-
|
|
3473
|
+
logger6.start("simulateGaze", `duration=${durationMs}ms`);
|
|
3548
3474
|
const startTime = Date.now();
|
|
3549
3475
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3550
3476
|
while (Date.now() - startTime < durationMs) {
|
|
@@ -3553,7 +3479,7 @@ var Humanize = {
|
|
|
3553
3479
|
await cursor.actions.move({ x, y });
|
|
3554
3480
|
await (0, import_delay2.default)(this.jitterMs(600, 0.5));
|
|
3555
3481
|
}
|
|
3556
|
-
|
|
3482
|
+
logger6.success("simulateGaze");
|
|
3557
3483
|
},
|
|
3558
3484
|
/**
|
|
3559
3485
|
* 人类化输入 - 带节奏变化(快-慢-停顿-偶尔加速)
|
|
@@ -3566,7 +3492,7 @@ var Humanize = {
|
|
|
3566
3492
|
* @param {number} [options.pauseBase=800] - 停顿时长基础值 (ms),实际 ±50% 抖动
|
|
3567
3493
|
*/
|
|
3568
3494
|
async humanType(page, selector, text, options = {}) {
|
|
3569
|
-
|
|
3495
|
+
logger6.start("humanType", `selector=${selector}, textLen=${text.length}`);
|
|
3570
3496
|
const {
|
|
3571
3497
|
baseDelay = 180,
|
|
3572
3498
|
pauseProbability = 0.08,
|
|
@@ -3590,13 +3516,13 @@ var Humanize = {
|
|
|
3590
3516
|
await (0, import_delay2.default)(charDelay);
|
|
3591
3517
|
if (Math.random() < pauseProbability && i < text.length - 1) {
|
|
3592
3518
|
const pauseTime = this.jitterMs(pauseBase, 0.5);
|
|
3593
|
-
|
|
3519
|
+
logger6.debug(`\u505C\u987F ${pauseTime}ms...`);
|
|
3594
3520
|
await (0, import_delay2.default)(pauseTime);
|
|
3595
3521
|
}
|
|
3596
3522
|
}
|
|
3597
|
-
|
|
3523
|
+
logger6.success("humanType");
|
|
3598
3524
|
} catch (error) {
|
|
3599
|
-
|
|
3525
|
+
logger6.fail("humanType", error);
|
|
3600
3526
|
throw error;
|
|
3601
3527
|
}
|
|
3602
3528
|
},
|
|
@@ -3620,7 +3546,7 @@ var Humanize = {
|
|
|
3620
3546
|
keyboardOptions = {}
|
|
3621
3547
|
} = pressOptions || {};
|
|
3622
3548
|
const targetDesc = hasTarget ? typeof targetOrKey === "string" ? targetOrKey : "ElementHandle" : "current focus";
|
|
3623
|
-
|
|
3549
|
+
logger6.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
3624
3550
|
try {
|
|
3625
3551
|
if (hasTarget) {
|
|
3626
3552
|
await this.humanClick(page, targetOrKey, { reactionDelay: focusDelay, scrollIfNeeded, throwOnMissing });
|
|
@@ -3630,10 +3556,10 @@ var Humanize = {
|
|
|
3630
3556
|
...keyboardOptions,
|
|
3631
3557
|
delay: this.jitterMs(holdDelay, 0.5)
|
|
3632
3558
|
});
|
|
3633
|
-
|
|
3559
|
+
logger6.success("humanPress");
|
|
3634
3560
|
return true;
|
|
3635
3561
|
} catch (error) {
|
|
3636
|
-
|
|
3562
|
+
logger6.fail("humanPress", error);
|
|
3637
3563
|
throw error;
|
|
3638
3564
|
}
|
|
3639
3565
|
},
|
|
@@ -3643,22 +3569,22 @@ var Humanize = {
|
|
|
3643
3569
|
* @param {string} selector - 输入框选择器
|
|
3644
3570
|
*/
|
|
3645
3571
|
async humanClear(page, selector) {
|
|
3646
|
-
|
|
3572
|
+
logger6.start("humanClear", `selector=${selector}`);
|
|
3647
3573
|
try {
|
|
3648
3574
|
const locator = page.locator(selector);
|
|
3649
3575
|
await locator.click();
|
|
3650
3576
|
await (0, import_delay2.default)(this.jitterMs(200, 0.4));
|
|
3651
3577
|
const currentValue = await locator.inputValue();
|
|
3652
3578
|
if (!currentValue || currentValue.length === 0) {
|
|
3653
|
-
|
|
3579
|
+
logger6.success("humanClear", "already empty");
|
|
3654
3580
|
return;
|
|
3655
3581
|
}
|
|
3656
3582
|
await page.keyboard.press("Meta+A");
|
|
3657
3583
|
await (0, import_delay2.default)(this.jitterMs(100, 0.4));
|
|
3658
3584
|
await page.keyboard.press("Backspace");
|
|
3659
|
-
|
|
3585
|
+
logger6.success("humanClear");
|
|
3660
3586
|
} catch (error) {
|
|
3661
|
-
|
|
3587
|
+
logger6.fail("humanClear", error);
|
|
3662
3588
|
throw error;
|
|
3663
3589
|
}
|
|
3664
3590
|
},
|
|
@@ -3670,7 +3596,7 @@ var Humanize = {
|
|
|
3670
3596
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
3671
3597
|
const cursor = $GetCursor(page);
|
|
3672
3598
|
const durationMs = this.jitterMs(baseDuration, 0.4);
|
|
3673
|
-
|
|
3599
|
+
logger6.start("warmUpBrowsing", `duration=${durationMs}ms`);
|
|
3674
3600
|
const startTime = Date.now();
|
|
3675
3601
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3676
3602
|
try {
|
|
@@ -3689,9 +3615,9 @@ var Humanize = {
|
|
|
3689
3615
|
await (0, import_delay2.default)(this.jitterMs(800, 0.5));
|
|
3690
3616
|
}
|
|
3691
3617
|
}
|
|
3692
|
-
|
|
3618
|
+
logger6.success("warmUpBrowsing");
|
|
3693
3619
|
} catch (error) {
|
|
3694
|
-
|
|
3620
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3695
3621
|
throw error;
|
|
3696
3622
|
}
|
|
3697
3623
|
},
|
|
@@ -3705,7 +3631,7 @@ var Humanize = {
|
|
|
3705
3631
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3706
3632
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3707
3633
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
3708
|
-
|
|
3634
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
3709
3635
|
const sign = direction === "down" ? 1 : -1;
|
|
3710
3636
|
const stepDistance = actualDistance / steps;
|
|
3711
3637
|
try {
|
|
@@ -3717,9 +3643,9 @@ var Humanize = {
|
|
|
3717
3643
|
const baseDelay = 60 + i * 25;
|
|
3718
3644
|
await (0, import_delay2.default)(this.jitterMs(baseDelay, 0.3));
|
|
3719
3645
|
}
|
|
3720
|
-
|
|
3646
|
+
logger6.success("naturalScroll");
|
|
3721
3647
|
} catch (error) {
|
|
3722
|
-
|
|
3648
|
+
logger6.fail("naturalScroll", error);
|
|
3723
3649
|
throw error;
|
|
3724
3650
|
}
|
|
3725
3651
|
}
|
|
@@ -3748,7 +3674,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
3748
3674
|
var waitJitter = (base, jitterPercent = 0.3) => (0, import_delay3.default)(jitterMs(base, jitterPercent));
|
|
3749
3675
|
|
|
3750
3676
|
// src/internals/humanize/mobile.js
|
|
3751
|
-
var
|
|
3677
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
3752
3678
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
3753
3679
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
3754
3680
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4118,7 +4044,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4118
4044
|
return;
|
|
4119
4045
|
}
|
|
4120
4046
|
await page.evaluate(
|
|
4121
|
-
(
|
|
4047
|
+
(state) => window.scrollTo(state.x, state.y),
|
|
4122
4048
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4123
4049
|
).catch(() => {
|
|
4124
4050
|
});
|
|
@@ -4205,7 +4131,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4205
4131
|
}
|
|
4206
4132
|
return true;
|
|
4207
4133
|
} catch (error) {
|
|
4208
|
-
|
|
4134
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4209
4135
|
try {
|
|
4210
4136
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4211
4137
|
await waitJitter(120, 0.35);
|
|
@@ -4239,7 +4165,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4239
4165
|
);
|
|
4240
4166
|
return { method: "touchscreen" };
|
|
4241
4167
|
} catch (error) {
|
|
4242
|
-
|
|
4168
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4243
4169
|
if (!allowMouseFallback) throw error;
|
|
4244
4170
|
}
|
|
4245
4171
|
}
|
|
@@ -4255,10 +4181,10 @@ var MobileHumanize = {
|
|
|
4255
4181
|
async initializeCursor(page) {
|
|
4256
4182
|
if (initializedPages.has(page)) return;
|
|
4257
4183
|
initializedPages.add(page);
|
|
4258
|
-
|
|
4184
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4259
4185
|
},
|
|
4260
4186
|
async humanMove(page, target) {
|
|
4261
|
-
|
|
4187
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4262
4188
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4263
4189
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4264
4190
|
if (!element) {
|
|
@@ -4277,10 +4203,10 @@ var MobileHumanize = {
|
|
|
4277
4203
|
throwOnMissing = false
|
|
4278
4204
|
} = options;
|
|
4279
4205
|
const targetDesc = describeTarget(target);
|
|
4280
|
-
|
|
4206
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4281
4207
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4282
4208
|
if (!element) {
|
|
4283
|
-
|
|
4209
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4284
4210
|
return { element: null, didScroll: false, restore: null };
|
|
4285
4211
|
}
|
|
4286
4212
|
const startTime = Date.now();
|
|
@@ -4289,42 +4215,42 @@ var MobileHumanize = {
|
|
|
4289
4215
|
const status = await checkElementVisibility(element);
|
|
4290
4216
|
if (status.code === "VISIBLE") {
|
|
4291
4217
|
if (status.isFixed) {
|
|
4292
|
-
|
|
4218
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4293
4219
|
} else {
|
|
4294
|
-
|
|
4220
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4295
4221
|
}
|
|
4296
|
-
|
|
4222
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4297
4223
|
return { element, didScroll, restore: null };
|
|
4298
4224
|
}
|
|
4299
4225
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4300
|
-
|
|
4226
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4301
4227
|
return { element, didScroll, restore: null };
|
|
4302
4228
|
}
|
|
4303
4229
|
const scrollRect = await getScrollableRect(element);
|
|
4304
4230
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4305
|
-
|
|
4231
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u4E0D\u5728\u89C6\u53E3\u5185\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (direction=${status.direction || "unknown"})`);
|
|
4306
4232
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4307
4233
|
}
|
|
4308
4234
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4309
|
-
|
|
4235
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4310
4236
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4311
4237
|
}
|
|
4312
4238
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4313
4239
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4314
4240
|
if (moved.moved) {
|
|
4315
|
-
|
|
4241
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4316
4242
|
await waitJitter(90, 0.3);
|
|
4317
4243
|
didScroll = true;
|
|
4318
4244
|
continue;
|
|
4319
4245
|
}
|
|
4320
4246
|
}
|
|
4321
4247
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4322
|
-
|
|
4248
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4323
4249
|
return { element, didScroll, restore: null };
|
|
4324
4250
|
}
|
|
4325
4251
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4326
4252
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4327
|
-
|
|
4253
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4328
4254
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4329
4255
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4330
4256
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4364,8 +4290,8 @@ var MobileHumanize = {
|
|
|
4364
4290
|
if (scrollRect && beforeWindowState) {
|
|
4365
4291
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4366
4292
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4367
|
-
await page.evaluate((
|
|
4368
|
-
|
|
4293
|
+
await page.evaluate((state) => window.scrollTo(state.x, state.y), beforeWindowState);
|
|
4294
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4369
4295
|
}
|
|
4370
4296
|
}
|
|
4371
4297
|
let afterElementSnapshot = null;
|
|
@@ -4379,7 +4305,7 @@ var MobileHumanize = {
|
|
|
4379
4305
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4380
4306
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4381
4307
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4382
|
-
|
|
4308
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u9875\u9762\u6EDA\u52A8\u79FB\u52A8\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4383
4309
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4384
4310
|
}
|
|
4385
4311
|
}
|
|
@@ -4411,12 +4337,12 @@ var MobileHumanize = {
|
|
|
4411
4337
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4412
4338
|
if (!moved) {
|
|
4413
4339
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4414
|
-
|
|
4340
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u65E0\u6548\uFF0C\u76F4\u63A5\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4415
4341
|
} else if (beforeState.kind === afterState.kind && Math.abs(expectedDelta) > 24 && Math.sign(topDelta || expectedDelta) === Math.sign(expectedDelta) && Math.abs(topDelta) < Math.min(Math.abs(expectedDelta) * 0.45, 96)) {
|
|
4416
4342
|
const residualDelta = expectedDelta - topDelta;
|
|
4417
4343
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4418
4344
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4419
|
-
|
|
4345
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u8DDD\u79BB\u4E0D\u8DB3\uFF0C\u8865\u507F\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4420
4346
|
}
|
|
4421
4347
|
}
|
|
4422
4348
|
}
|
|
@@ -4424,7 +4350,7 @@ var MobileHumanize = {
|
|
|
4424
4350
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4425
4351
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4426
4352
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4427
|
-
|
|
4353
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u6EDA\u52A8\u5BB9\u5668\u79FB\u52A8\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4428
4354
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4429
4355
|
}
|
|
4430
4356
|
}
|
|
@@ -4435,14 +4361,14 @@ var MobileHumanize = {
|
|
|
4435
4361
|
await waitJitter(80, 0.3);
|
|
4436
4362
|
const finalStatus = await checkElementVisibility(element);
|
|
4437
4363
|
if (finalStatus.code === "VISIBLE") {
|
|
4438
|
-
|
|
4439
|
-
|
|
4364
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4365
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4440
4366
|
return { element, didScroll: true, restore: null };
|
|
4441
4367
|
}
|
|
4442
4368
|
} catch (fallbackError) {
|
|
4443
|
-
|
|
4369
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4444
4370
|
}
|
|
4445
|
-
|
|
4371
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4446
4372
|
return { element, didScroll, restore: null };
|
|
4447
4373
|
},
|
|
4448
4374
|
async humanClick(page, target, options = {}) {
|
|
@@ -4457,7 +4383,7 @@ var MobileHumanize = {
|
|
|
4457
4383
|
fallbackDomClickOnTapError = true
|
|
4458
4384
|
} = options;
|
|
4459
4385
|
const targetDesc = describeTarget(target);
|
|
4460
|
-
|
|
4386
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4461
4387
|
try {
|
|
4462
4388
|
if (target == null) {
|
|
4463
4389
|
const viewport = resolveViewport(page);
|
|
@@ -4469,12 +4395,12 @@ var MobileHumanize = {
|
|
|
4469
4395
|
timeoutMs: tapTimeoutMs,
|
|
4470
4396
|
mouseFallbackTimeoutMs
|
|
4471
4397
|
});
|
|
4472
|
-
|
|
4398
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4473
4399
|
return true;
|
|
4474
4400
|
}
|
|
4475
4401
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4476
4402
|
if (!element) {
|
|
4477
|
-
|
|
4403
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4478
4404
|
return false;
|
|
4479
4405
|
}
|
|
4480
4406
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4498,19 +4424,19 @@ var MobileHumanize = {
|
|
|
4498
4424
|
).catch(() => null);
|
|
4499
4425
|
}
|
|
4500
4426
|
if (fallback?.activated) {
|
|
4501
|
-
|
|
4427
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4502
4428
|
return true;
|
|
4503
4429
|
}
|
|
4504
4430
|
}
|
|
4505
4431
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4506
4432
|
if (throwOnMissing) throw new Error(message);
|
|
4507
|
-
|
|
4433
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4508
4434
|
return false;
|
|
4509
4435
|
}
|
|
4510
4436
|
const box = await element.boundingBox();
|
|
4511
4437
|
if (!box) {
|
|
4512
4438
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4513
|
-
|
|
4439
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4514
4440
|
return false;
|
|
4515
4441
|
}
|
|
4516
4442
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4531,13 +4457,13 @@ var MobileHumanize = {
|
|
|
4531
4457
|
"activation fallback"
|
|
4532
4458
|
).catch(() => null);
|
|
4533
4459
|
if (!fallback?.activated) throw tapError;
|
|
4534
|
-
|
|
4460
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4535
4461
|
}
|
|
4536
4462
|
await waitJitter(120, 0.35);
|
|
4537
|
-
|
|
4463
|
+
logger7.success("humanClick");
|
|
4538
4464
|
return true;
|
|
4539
4465
|
} catch (error) {
|
|
4540
|
-
|
|
4466
|
+
logger7.fail("humanClick", error);
|
|
4541
4467
|
throw error;
|
|
4542
4468
|
}
|
|
4543
4469
|
},
|
|
@@ -4590,7 +4516,7 @@ var MobileHumanize = {
|
|
|
4590
4516
|
keyboardOptions = {}
|
|
4591
4517
|
} = pressOptions || {};
|
|
4592
4518
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4593
|
-
|
|
4519
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4594
4520
|
try {
|
|
4595
4521
|
if (hasTarget) {
|
|
4596
4522
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4604,10 +4530,10 @@ var MobileHumanize = {
|
|
|
4604
4530
|
...keyboardOptions,
|
|
4605
4531
|
delay: jitterMs(holdDelay, 0.5)
|
|
4606
4532
|
});
|
|
4607
|
-
|
|
4533
|
+
logger7.success("humanPress");
|
|
4608
4534
|
return true;
|
|
4609
4535
|
} catch (error) {
|
|
4610
|
-
|
|
4536
|
+
logger7.fail("humanPress", error);
|
|
4611
4537
|
throw error;
|
|
4612
4538
|
}
|
|
4613
4539
|
},
|
|
@@ -4674,7 +4600,7 @@ var MobileHumanize = {
|
|
|
4674
4600
|
}
|
|
4675
4601
|
};
|
|
4676
4602
|
|
|
4677
|
-
// src/
|
|
4603
|
+
// src/humanize.js
|
|
4678
4604
|
var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4679
4605
|
var resolveDelegate = (page) => {
|
|
4680
4606
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
@@ -4683,7 +4609,7 @@ var callDelegate = (method, page, args) => {
|
|
|
4683
4609
|
const delegate = resolveDelegate(page);
|
|
4684
4610
|
return delegate[method](page, ...args);
|
|
4685
4611
|
};
|
|
4686
|
-
var
|
|
4612
|
+
var Humanize2 = {
|
|
4687
4613
|
jitterMs(base, jitterPercent = 0.3) {
|
|
4688
4614
|
return Humanize.jitterMs(base, jitterPercent);
|
|
4689
4615
|
},
|
|
@@ -4729,169 +4655,7 @@ var DefaultHumanize = {
|
|
|
4729
4655
|
}
|
|
4730
4656
|
};
|
|
4731
4657
|
|
|
4732
|
-
// src/
|
|
4733
|
-
var import_delay4 = __toESM(require("delay"), 1);
|
|
4734
|
-
var resolveDeviceFromPage3 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4735
|
-
var isMobilePage = (page) => resolveDeviceFromPage3(page) === Device.Mobile;
|
|
4736
|
-
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4737
|
-
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4738
|
-
var resolveTarget = (page, target) => typeof target === "string" ? page.locator(target).first() : target;
|
|
4739
|
-
var sleep = (base, jitter = 0.3) => (0, import_delay4.default)(jitterMs(base, jitter));
|
|
4740
|
-
var FORCE_OPTIONS = Object.freeze({ force: true });
|
|
4741
|
-
var DesktopCloakHumanize = {
|
|
4742
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4743
|
-
return jitterMs(base, jitterPercent);
|
|
4744
|
-
},
|
|
4745
|
-
async initializeCursor(page) {
|
|
4746
|
-
return Boolean(page);
|
|
4747
|
-
},
|
|
4748
|
-
async humanMove(page, target) {
|
|
4749
|
-
if (target == null) return false;
|
|
4750
|
-
if (isPoint2(target)) {
|
|
4751
|
-
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4752
|
-
return true;
|
|
4753
|
-
}
|
|
4754
|
-
await resolveTarget(page, target).hover(FORCE_OPTIONS);
|
|
4755
|
-
return true;
|
|
4756
|
-
},
|
|
4757
|
-
async humanScroll(page, target) {
|
|
4758
|
-
const element = resolveTarget(page, target);
|
|
4759
|
-
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4760
|
-
await element.scrollIntoViewIfNeeded?.();
|
|
4761
|
-
return { element, didScroll: true, restore: null };
|
|
4762
|
-
},
|
|
4763
|
-
async humanClick(page, target) {
|
|
4764
|
-
if (target == null) {
|
|
4765
|
-
await page.mouse.click(0, 0);
|
|
4766
|
-
return true;
|
|
4767
|
-
}
|
|
4768
|
-
if (isPoint2(target)) {
|
|
4769
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4770
|
-
return true;
|
|
4771
|
-
}
|
|
4772
|
-
if (typeof target === "string") {
|
|
4773
|
-
await page.click(target, FORCE_OPTIONS);
|
|
4774
|
-
return true;
|
|
4775
|
-
}
|
|
4776
|
-
await target.click(FORCE_OPTIONS);
|
|
4777
|
-
return true;
|
|
4778
|
-
},
|
|
4779
|
-
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4780
|
-
await sleep(baseMs, jitterPercent);
|
|
4781
|
-
},
|
|
4782
|
-
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4783
|
-
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4784
|
-
const startedAt = Date.now();
|
|
4785
|
-
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4786
|
-
while (Date.now() - startedAt < durationMs) {
|
|
4787
|
-
await page.mouse.move(
|
|
4788
|
-
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4789
|
-
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4790
|
-
);
|
|
4791
|
-
await sleep(300, 0.5);
|
|
4792
|
-
}
|
|
4793
|
-
},
|
|
4794
|
-
async humanType(page, selector, text) {
|
|
4795
|
-
const target = resolveTarget(page, selector);
|
|
4796
|
-
await target.click(FORCE_OPTIONS);
|
|
4797
|
-
await page.keyboard.type(text);
|
|
4798
|
-
},
|
|
4799
|
-
async humanPress(page, targetOrKey, maybeKey) {
|
|
4800
|
-
if (typeof maybeKey !== "string") {
|
|
4801
|
-
await page.keyboard.press(targetOrKey);
|
|
4802
|
-
return true;
|
|
4803
|
-
}
|
|
4804
|
-
await resolveTarget(page, targetOrKey).click(FORCE_OPTIONS);
|
|
4805
|
-
await page.keyboard.press(maybeKey);
|
|
4806
|
-
return true;
|
|
4807
|
-
},
|
|
4808
|
-
async humanClear(page, selector) {
|
|
4809
|
-
if (typeof selector === "string") {
|
|
4810
|
-
await page.fill(selector, "", FORCE_OPTIONS);
|
|
4811
|
-
return;
|
|
4812
|
-
}
|
|
4813
|
-
await selector.fill("", FORCE_OPTIONS);
|
|
4814
|
-
},
|
|
4815
|
-
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
4816
|
-
await this.simulateGaze(page, Math.min(baseDuration, 900));
|
|
4817
|
-
},
|
|
4818
|
-
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4819
|
-
const steps = Math.max(1, Number(baseSteps) || 1);
|
|
4820
|
-
const delta = (Number(distance) || 0) / steps * (direction === "down" ? 1 : -1);
|
|
4821
|
-
for (let index = 0; index < steps; index += 1) {
|
|
4822
|
-
await page.mouse.wheel(0, delta);
|
|
4823
|
-
await sleep(60 + index * 20, 0.3);
|
|
4824
|
-
}
|
|
4825
|
-
}
|
|
4826
|
-
};
|
|
4827
|
-
var resolveDelegate2 = (page) => isMobilePage(page) ? MobileHumanize : DesktopCloakHumanize;
|
|
4828
|
-
var callDelegate2 = (method, page, args) => resolveDelegate2(page)[method](page, ...args);
|
|
4829
|
-
var CloakBrowserHumanize = {
|
|
4830
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4831
|
-
return jitterMs(base, jitterPercent);
|
|
4832
|
-
},
|
|
4833
|
-
initializeCursor(page) {
|
|
4834
|
-
return callDelegate2("initializeCursor", page, []);
|
|
4835
|
-
},
|
|
4836
|
-
humanMove(page, target) {
|
|
4837
|
-
return callDelegate2("humanMove", page, [target]);
|
|
4838
|
-
},
|
|
4839
|
-
humanScroll(page, target, options = {}) {
|
|
4840
|
-
return callDelegate2("humanScroll", page, [target, options]);
|
|
4841
|
-
},
|
|
4842
|
-
humanClick(page, target, options = {}) {
|
|
4843
|
-
return callDelegate2("humanClick", page, [target, options]);
|
|
4844
|
-
},
|
|
4845
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4846
|
-
if (isPageLike2(pageOrBaseMs)) {
|
|
4847
|
-
return resolveDelegate2(pageOrBaseMs).randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4848
|
-
}
|
|
4849
|
-
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4850
|
-
},
|
|
4851
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4852
|
-
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
4853
|
-
},
|
|
4854
|
-
humanType(page, selector, text, options = {}) {
|
|
4855
|
-
return callDelegate2("humanType", page, [selector, text, options]);
|
|
4856
|
-
},
|
|
4857
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4858
|
-
if (typeof maybeKey === "string") {
|
|
4859
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4860
|
-
}
|
|
4861
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4862
|
-
},
|
|
4863
|
-
humanClear(page, selector) {
|
|
4864
|
-
return callDelegate2("humanClear", page, [selector]);
|
|
4865
|
-
},
|
|
4866
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4867
|
-
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
4868
|
-
},
|
|
4869
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4870
|
-
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4871
|
-
}
|
|
4872
|
-
};
|
|
4873
|
-
|
|
4874
|
-
// src/humanize.js
|
|
4875
|
-
var humanizeStrategies = {
|
|
4876
|
-
[Mode.Default]: DefaultHumanize,
|
|
4877
|
-
[Mode.CloakBrowser]: CloakBrowserHumanize
|
|
4878
|
-
};
|
|
4879
|
-
var Humanize2 = createDelegatedFacade("Humanize", humanizeStrategies, [
|
|
4880
|
-
"jitterMs",
|
|
4881
|
-
"initializeCursor",
|
|
4882
|
-
"humanMove",
|
|
4883
|
-
"humanScroll",
|
|
4884
|
-
"humanClick",
|
|
4885
|
-
"randomSleep",
|
|
4886
|
-
"simulateGaze",
|
|
4887
|
-
"humanType",
|
|
4888
|
-
"humanPress",
|
|
4889
|
-
"humanClear",
|
|
4890
|
-
"warmUpBrowsing",
|
|
4891
|
-
"naturalScroll"
|
|
4892
|
-
]);
|
|
4893
|
-
|
|
4894
|
-
// src/internals/launch/default.js
|
|
4658
|
+
// src/launch.js
|
|
4895
4659
|
var import_node_child_process = require("node:child_process");
|
|
4896
4660
|
var import_fingerprint_generator = require("fingerprint-generator");
|
|
4897
4661
|
var import_fingerprint_injector = require("fingerprint-injector");
|
|
@@ -4976,8 +4740,8 @@ var ByPass = {
|
|
|
4976
4740
|
resolveRouteByProxy
|
|
4977
4741
|
};
|
|
4978
4742
|
|
|
4979
|
-
// src/
|
|
4980
|
-
var
|
|
4743
|
+
// src/launch.js
|
|
4744
|
+
var logger8 = createInternalLogger("Launch");
|
|
4981
4745
|
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
4982
4746
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4983
4747
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
@@ -5029,7 +4793,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5029
4793
|
});
|
|
5030
4794
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5031
4795
|
} catch (error) {
|
|
5032
|
-
|
|
4796
|
+
logger8.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5033
4797
|
}
|
|
5034
4798
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5035
4799
|
return detectedVersion;
|
|
@@ -5043,7 +4807,7 @@ var resolveCoreDevice = (core = {}) => {
|
|
|
5043
4807
|
};
|
|
5044
4808
|
var buildFingerprintGenerator = ({ locale, browserMajorVersion, device }) => {
|
|
5045
4809
|
return new import_fingerprint_generator.FingerprintGenerator(
|
|
5046
|
-
|
|
4810
|
+
AntiCheat.getFingerprintGeneratorOptions({
|
|
5047
4811
|
locale,
|
|
5048
4812
|
browserMajorVersion,
|
|
5049
4813
|
device
|
|
@@ -5066,7 +4830,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5066
4830
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5067
4831
|
throw error;
|
|
5068
4832
|
}
|
|
5069
|
-
|
|
4833
|
+
logger8.warn(
|
|
5070
4834
|
`\u5F53\u524D\u6D4F\u89C8\u5668\u5927\u7248\u672C ${requestedBrowserMajorVersion} \u65E0\u53EF\u7528 strict \u6307\u7EB9\u6837\u672C\uFF0C\u9000\u56DE\u4E0D\u7ED1\u5B9A\u5927\u7248\u672C\u751F\u6210: ${error?.message || error}`
|
|
5071
4835
|
);
|
|
5072
4836
|
}
|
|
@@ -5087,7 +4851,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5087
4851
|
}
|
|
5088
4852
|
let nextState = RuntimeEnv.rememberState(runtimeState);
|
|
5089
4853
|
let browserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
|
|
5090
|
-
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() ||
|
|
4854
|
+
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() || AntiCheat.getBaseConfig().timezoneId;
|
|
5091
4855
|
const locale = DEFAULT_LOCALE;
|
|
5092
4856
|
const currentBrowserMajorVersion = detectBrowserMajorVersion(launcher);
|
|
5093
4857
|
const storedBrowserMajorVersion = Number(browserProfileCore?.browser_major_version || 0);
|
|
@@ -5111,7 +4875,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5111
4875
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5112
4876
|
};
|
|
5113
4877
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5114
|
-
|
|
4878
|
+
logger8.info(
|
|
5115
4879
|
`\u5DF2\u751F\u6210\u6D4F\u89C8\u5668\u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | device=${device} | version=${browserProfileCore.browser_major_version || "-"} | fingerprintVersion=${fingerprintBrowserMajorVersion || "-"} | exactVersion=${generated.exactBrowserMajorVersion ? "true" : "false"} | timezone=${timezoneId}`
|
|
5116
4880
|
);
|
|
5117
4881
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5166,7 +4930,7 @@ var applyFingerprintPageOptions = (pageOptions = {}, { fingerprintWithHeaders =
|
|
|
5166
4930
|
pageOptions.timezoneId = timezoneId;
|
|
5167
4931
|
}
|
|
5168
4932
|
};
|
|
5169
|
-
var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
4933
|
+
var buildReplayBrowserPoolOptions = (browserProfileCore, modifyPageOptions = null) => {
|
|
5170
4934
|
const fingerprintWithHeaders = browserProfileCore?.fingerprint;
|
|
5171
4935
|
const fingerprint = fingerprintWithHeaders?.fingerprint;
|
|
5172
4936
|
if (!fingerprintWithHeaders || !fingerprint) {
|
|
@@ -5175,13 +4939,16 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5175
4939
|
return {
|
|
5176
4940
|
useFingerprints: false,
|
|
5177
4941
|
prePageCreateHooks: [
|
|
5178
|
-
(
|
|
4942
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5179
4943
|
if (!pageOptions || typeof pageOptions !== "object") return;
|
|
5180
4944
|
applyFingerprintPageOptions(pageOptions, {
|
|
5181
4945
|
fingerprintWithHeaders,
|
|
5182
4946
|
locale: browserProfileCore.locale,
|
|
5183
4947
|
timezoneId: browserProfileCore.timezone_id
|
|
5184
4948
|
});
|
|
4949
|
+
if (modifyPageOptions) {
|
|
4950
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
4951
|
+
}
|
|
5185
4952
|
}
|
|
5186
4953
|
],
|
|
5187
4954
|
postPageCreateHooks: [
|
|
@@ -5196,7 +4963,7 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5196
4963
|
]
|
|
5197
4964
|
};
|
|
5198
4965
|
};
|
|
5199
|
-
var
|
|
4966
|
+
var Launch = {
|
|
5200
4967
|
getPlaywrightCrawlerOptions(options = {}) {
|
|
5201
4968
|
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
5202
4969
|
const {
|
|
@@ -5207,11 +4974,13 @@ var DefaultLaunch = {
|
|
|
5207
4974
|
debugMode = false,
|
|
5208
4975
|
isRunningOnApify = false,
|
|
5209
4976
|
launcher = null,
|
|
4977
|
+
hooks = {},
|
|
5210
4978
|
preNavigationHooks = [],
|
|
5211
4979
|
postNavigationHooks = [],
|
|
5212
4980
|
runtimeState = null
|
|
5213
4981
|
} = normalizedOptions;
|
|
5214
4982
|
const device = resolveRuntimeDevice(runtimeState);
|
|
4983
|
+
const modifyPageOptions = typeof hooks?.modifyPageOptions === "function" ? hooks.modifyPageOptions : null;
|
|
5215
4984
|
const { byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
5216
4985
|
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
5217
4986
|
const proxyMeter = enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
@@ -5220,11 +4989,11 @@ var DefaultLaunch = {
|
|
|
5220
4989
|
launchProxy.bypass = byPassDomains.join(",");
|
|
5221
4990
|
}
|
|
5222
4991
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5223
|
-
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
4992
|
+
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore, modifyPageOptions);
|
|
5224
4993
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5225
4994
|
const launchOptions = {
|
|
5226
4995
|
args: [
|
|
5227
|
-
...
|
|
4996
|
+
...AntiCheat.getLaunchArgs({ locale: launchLocale }),
|
|
5228
4997
|
...customArgs
|
|
5229
4998
|
],
|
|
5230
4999
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
@@ -5240,18 +5009,18 @@ var DefaultLaunch = {
|
|
|
5240
5009
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5241
5010
|
} catch {
|
|
5242
5011
|
}
|
|
5243
|
-
|
|
5012
|
+
logger8.info(
|
|
5244
5013
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5245
5014
|
);
|
|
5246
|
-
|
|
5015
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5247
5016
|
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5248
|
-
|
|
5249
|
-
|
|
5017
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5018
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5250
5019
|
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5251
|
-
|
|
5252
|
-
|
|
5020
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5021
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5253
5022
|
} else if (enableByPassLogger) {
|
|
5254
|
-
|
|
5023
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5255
5024
|
}
|
|
5256
5025
|
const onPageCreated = (page) => {
|
|
5257
5026
|
const recommendedGotoOptions = {
|
|
@@ -5273,7 +5042,7 @@ var DefaultLaunch = {
|
|
|
5273
5042
|
}
|
|
5274
5043
|
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5275
5044
|
if (!matched || !matched.rule) return;
|
|
5276
|
-
|
|
5045
|
+
logger8.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
5277
5046
|
};
|
|
5278
5047
|
page.on("request", requestHandler);
|
|
5279
5048
|
return recommendedGotoOptions;
|
|
@@ -5292,20 +5061,23 @@ var DefaultLaunch = {
|
|
|
5292
5061
|
browserPoolOptions: replayBrowserPoolOptions || {
|
|
5293
5062
|
useFingerprints: true,
|
|
5294
5063
|
fingerprintOptions: {
|
|
5295
|
-
fingerprintGeneratorOptions:
|
|
5064
|
+
fingerprintGeneratorOptions: AntiCheat.getFingerprintGeneratorOptions({
|
|
5296
5065
|
locale: launchLocale,
|
|
5297
5066
|
device
|
|
5298
5067
|
})
|
|
5299
5068
|
},
|
|
5300
5069
|
prePageCreateHooks: [
|
|
5301
|
-
(
|
|
5070
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5302
5071
|
const fingerprintWithHeaders = browserController?.launchContext?.fingerprint;
|
|
5303
|
-
const timezoneId =
|
|
5072
|
+
const timezoneId = AntiCheat.getBaseConfig().timezoneId;
|
|
5304
5073
|
applyFingerprintPageOptions(pageOptions, {
|
|
5305
5074
|
fingerprintWithHeaders,
|
|
5306
5075
|
locale: launchLocale,
|
|
5307
5076
|
timezoneId
|
|
5308
5077
|
});
|
|
5078
|
+
if (modifyPageOptions) {
|
|
5079
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
5080
|
+
}
|
|
5309
5081
|
}
|
|
5310
5082
|
]
|
|
5311
5083
|
},
|
|
@@ -5327,262 +5099,6 @@ var DefaultLaunch = {
|
|
|
5327
5099
|
}
|
|
5328
5100
|
};
|
|
5329
5101
|
|
|
5330
|
-
// src/internals/launch/cloakbrowser.js
|
|
5331
|
-
var import_node_child_process2 = require("node:child_process");
|
|
5332
|
-
var import_node_util = require("node:util");
|
|
5333
|
-
var logger8 = createInternalLogger("CloakBrowser");
|
|
5334
|
-
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5335
|
-
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5336
|
-
maxConcurrency: 1,
|
|
5337
|
-
maxRequestRetries: 0,
|
|
5338
|
-
requestHandlerTimeoutSecs: 240,
|
|
5339
|
-
navigationTimeoutSecs: 120
|
|
5340
|
-
});
|
|
5341
|
-
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5342
|
-
humanize: true
|
|
5343
|
-
});
|
|
5344
|
-
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5345
|
-
waitUntil: "commit"
|
|
5346
|
-
});
|
|
5347
|
-
var cachedCloakBrowserModulePromise = null;
|
|
5348
|
-
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5349
|
-
var loadCloakBrowserModule = async () => {
|
|
5350
|
-
if (!cachedCloakBrowserModulePromise) {
|
|
5351
|
-
cachedCloakBrowserModulePromise = import("cloakbrowser").catch((error) => {
|
|
5352
|
-
cachedCloakBrowserModulePromise = null;
|
|
5353
|
-
throw new Error("cloakbrowser \u6A21\u5757\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5 cloakbrowser\u3002", {
|
|
5354
|
-
cause: error
|
|
5355
|
-
});
|
|
5356
|
-
});
|
|
5357
|
-
}
|
|
5358
|
-
return cachedCloakBrowserModulePromise;
|
|
5359
|
-
};
|
|
5360
|
-
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5361
|
-
const { buildLaunchOptions } = await loadCloakBrowserModule();
|
|
5362
|
-
return await buildLaunchOptions(normalizeObject(options));
|
|
5363
|
-
};
|
|
5364
|
-
var normalizeObject = (value) => {
|
|
5365
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5366
|
-
return {};
|
|
5367
|
-
}
|
|
5368
|
-
return value;
|
|
5369
|
-
};
|
|
5370
|
-
var normalizeStringArray = (value) => {
|
|
5371
|
-
if (!Array.isArray(value)) {
|
|
5372
|
-
return [];
|
|
5373
|
-
}
|
|
5374
|
-
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5375
|
-
};
|
|
5376
|
-
var resolveCloakBrowserProxy = (proxyConfiguration = {}) => {
|
|
5377
|
-
const config = normalizeObject(proxyConfiguration);
|
|
5378
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5379
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5380
|
-
if (!enableProxy || !proxyUrl) {
|
|
5381
|
-
return null;
|
|
5382
|
-
}
|
|
5383
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5384
|
-
if (byPassDomains.length === 0) {
|
|
5385
|
-
return proxyUrl;
|
|
5386
|
-
}
|
|
5387
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5388
|
-
return {
|
|
5389
|
-
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5390
|
-
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5391
|
-
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5392
|
-
bypass: byPassDomains.join(",")
|
|
5393
|
-
};
|
|
5394
|
-
};
|
|
5395
|
-
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5396
|
-
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5397
|
-
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5398
|
-
};
|
|
5399
|
-
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5400
|
-
const normalizedRecommendedGotoOptions = normalizeObject(recommendedGotoOptions);
|
|
5401
|
-
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5402
|
-
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5403
|
-
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5404
|
-
if (gotoOptions[key] == null) {
|
|
5405
|
-
gotoOptions[key] = value;
|
|
5406
|
-
}
|
|
5407
|
-
}
|
|
5408
|
-
};
|
|
5409
|
-
};
|
|
5410
|
-
var attachCloakBrowserHumanizeHook = ({
|
|
5411
|
-
browserPoolOptions = {},
|
|
5412
|
-
activeBrowsers,
|
|
5413
|
-
patchedBrowsers,
|
|
5414
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5415
|
-
} = {}) => {
|
|
5416
|
-
const normalizedBrowserPoolOptions = normalizeObject(browserPoolOptions);
|
|
5417
|
-
const shouldHumanize = humanizeOptions !== false;
|
|
5418
|
-
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5419
|
-
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5420
|
-
...normalizeObject(humanizeOptions)
|
|
5421
|
-
} : null;
|
|
5422
|
-
return {
|
|
5423
|
-
...normalizedBrowserPoolOptions,
|
|
5424
|
-
useFingerprints: false,
|
|
5425
|
-
postLaunchHooks: [
|
|
5426
|
-
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5427
|
-
async (_pageId, browserController) => {
|
|
5428
|
-
const browser = browserController?.browser;
|
|
5429
|
-
if (!browser || typeof browser.contexts !== "function") {
|
|
5430
|
-
return;
|
|
5431
|
-
}
|
|
5432
|
-
activeBrowsers.add(browser);
|
|
5433
|
-
if (typeof browser.once === "function") {
|
|
5434
|
-
browser.once("disconnected", () => {
|
|
5435
|
-
activeBrowsers.delete(browser);
|
|
5436
|
-
});
|
|
5437
|
-
}
|
|
5438
|
-
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5439
|
-
return;
|
|
5440
|
-
}
|
|
5441
|
-
const { humanizeBrowser } = await loadCloakBrowserModule();
|
|
5442
|
-
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5443
|
-
patchedBrowsers.add(browser);
|
|
5444
|
-
}
|
|
5445
|
-
]
|
|
5446
|
-
};
|
|
5447
|
-
};
|
|
5448
|
-
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5449
|
-
const browsers = Array.from(activeBrowsers || []);
|
|
5450
|
-
activeBrowsers?.clear?.();
|
|
5451
|
-
await Promise.allSettled(
|
|
5452
|
-
browsers.map(async (browser) => {
|
|
5453
|
-
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5454
|
-
return;
|
|
5455
|
-
}
|
|
5456
|
-
await browser.close().catch(() => {
|
|
5457
|
-
});
|
|
5458
|
-
})
|
|
5459
|
-
);
|
|
5460
|
-
};
|
|
5461
|
-
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5462
|
-
if (!fingerprintArg) {
|
|
5463
|
-
return;
|
|
5464
|
-
}
|
|
5465
|
-
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5466
|
-
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5467
|
-
return;
|
|
5468
|
-
}
|
|
5469
|
-
logger8.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5470
|
-
});
|
|
5471
|
-
};
|
|
5472
|
-
var CloakBrowserLaunch = {
|
|
5473
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5474
|
-
return resolveCloakBrowserProxy(proxyConfiguration);
|
|
5475
|
-
},
|
|
5476
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5477
|
-
return extractFingerprintArg(launchOptions);
|
|
5478
|
-
},
|
|
5479
|
-
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5480
|
-
return createStableGotoHook(recommendedGotoOptions);
|
|
5481
|
-
},
|
|
5482
|
-
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5483
|
-
const runtime2 = await CloakBrowserLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5484
|
-
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5485
|
-
cleanup: {
|
|
5486
|
-
enumerable: false,
|
|
5487
|
-
value: runtime2.cleanup
|
|
5488
|
-
},
|
|
5489
|
-
closeActiveBrowsers: {
|
|
5490
|
-
enumerable: false,
|
|
5491
|
-
value: runtime2.closeActiveBrowsers
|
|
5492
|
-
},
|
|
5493
|
-
forceTerminateActiveProcesses: {
|
|
5494
|
-
enumerable: false,
|
|
5495
|
-
value: runtime2.forceTerminateActiveProcesses
|
|
5496
|
-
}
|
|
5497
|
-
});
|
|
5498
|
-
},
|
|
5499
|
-
async buildLaunchOptions(options = {}) {
|
|
5500
|
-
return await buildCloakLaunchOptions(options);
|
|
5501
|
-
},
|
|
5502
|
-
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5503
|
-
const normalizedOptions = normalizeObject(options);
|
|
5504
|
-
const {
|
|
5505
|
-
proxyConfiguration = {},
|
|
5506
|
-
runInHeadfulMode = false,
|
|
5507
|
-
isRunningOnApify = false,
|
|
5508
|
-
launcher = null,
|
|
5509
|
-
cloakOptions = {},
|
|
5510
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5511
|
-
crawlerBaseOptions = {},
|
|
5512
|
-
browserPoolOptions = {},
|
|
5513
|
-
launchContext = {},
|
|
5514
|
-
preNavigationHooks = [],
|
|
5515
|
-
postNavigationHooks = [],
|
|
5516
|
-
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5517
|
-
} = normalizedOptions;
|
|
5518
|
-
const normalizedCloakOptions = normalizeObject(cloakOptions);
|
|
5519
|
-
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5520
|
-
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5521
|
-
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5522
|
-
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5523
|
-
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakBrowserProxy(proxyConfiguration);
|
|
5524
|
-
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5525
|
-
const mergedCloakOptions = {
|
|
5526
|
-
...normalizedCloakOptions,
|
|
5527
|
-
headless,
|
|
5528
|
-
proxy,
|
|
5529
|
-
args: [...defaultArgs, ...extraArgs]
|
|
5530
|
-
};
|
|
5531
|
-
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5532
|
-
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5533
|
-
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5534
|
-
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5535
|
-
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5536
|
-
const crawlerOptions = {
|
|
5537
|
-
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5538
|
-
...normalizeObject(crawlerBaseOptions),
|
|
5539
|
-
headless,
|
|
5540
|
-
launchContext: {
|
|
5541
|
-
useIncognitoPages: true,
|
|
5542
|
-
...normalizeObject(launchContext),
|
|
5543
|
-
...launcher ? { launcher } : {},
|
|
5544
|
-
launchOptions
|
|
5545
|
-
},
|
|
5546
|
-
browserPoolOptions: attachCloakBrowserHumanizeHook({
|
|
5547
|
-
browserPoolOptions,
|
|
5548
|
-
activeBrowsers,
|
|
5549
|
-
patchedBrowsers,
|
|
5550
|
-
humanizeOptions
|
|
5551
|
-
}),
|
|
5552
|
-
preNavigationHooks: [internalPreNavigationHook, ...normalizedPreNavigationHooks],
|
|
5553
|
-
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5554
|
-
};
|
|
5555
|
-
const closeActiveBrowsers = async () => {
|
|
5556
|
-
await closeTrackedBrowsers(activeBrowsers);
|
|
5557
|
-
};
|
|
5558
|
-
const forceTerminateActiveProcesses = async () => {
|
|
5559
|
-
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5560
|
-
};
|
|
5561
|
-
const cleanup = async () => {
|
|
5562
|
-
await closeActiveBrowsers();
|
|
5563
|
-
await forceTerminateActiveProcesses();
|
|
5564
|
-
};
|
|
5565
|
-
return {
|
|
5566
|
-
headless,
|
|
5567
|
-
launchOptions,
|
|
5568
|
-
fingerprintArg,
|
|
5569
|
-
crawlerOptions,
|
|
5570
|
-
closeActiveBrowsers,
|
|
5571
|
-
forceTerminateActiveProcesses,
|
|
5572
|
-
cleanup
|
|
5573
|
-
};
|
|
5574
|
-
}
|
|
5575
|
-
};
|
|
5576
|
-
|
|
5577
|
-
// src/launch.js
|
|
5578
|
-
var launchStrategies = {
|
|
5579
|
-
[Mode.Default]: DefaultLaunch,
|
|
5580
|
-
[Mode.CloakBrowser]: CloakBrowserLaunch
|
|
5581
|
-
};
|
|
5582
|
-
var Launch = createDelegatedFacade("Launch", launchStrategies, [
|
|
5583
|
-
"getPlaywrightCrawlerOptions"
|
|
5584
|
-
]);
|
|
5585
|
-
|
|
5586
5102
|
// src/live-view.js
|
|
5587
5103
|
var import_express = __toESM(require("express"), 1);
|
|
5588
5104
|
var import_apify = require("apify");
|
|
@@ -6670,7 +6186,7 @@ var Mutation = {
|
|
|
6670
6186
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6671
6187
|
const onMutation = options.onMutation;
|
|
6672
6188
|
const pollInterval = 500;
|
|
6673
|
-
const
|
|
6189
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6674
6190
|
setTimeout(resolve, ms);
|
|
6675
6191
|
});
|
|
6676
6192
|
const truncate = (value, max = 800) => {
|
|
@@ -6831,8 +6347,8 @@ var Mutation = {
|
|
|
6831
6347
|
throw e;
|
|
6832
6348
|
}
|
|
6833
6349
|
}
|
|
6834
|
-
let
|
|
6835
|
-
if (!
|
|
6350
|
+
let state = await buildState();
|
|
6351
|
+
if (!state?.hasMatched) {
|
|
6836
6352
|
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6837
6353
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6838
6354
|
}
|
|
@@ -6840,7 +6356,7 @@ var Mutation = {
|
|
|
6840
6356
|
let stableSince = 0;
|
|
6841
6357
|
let isPaused = false;
|
|
6842
6358
|
let wasPaused = false;
|
|
6843
|
-
let lastSnapshotKey =
|
|
6359
|
+
let lastSnapshotKey = state.snapshotKey;
|
|
6844
6360
|
const applyPauseSignal = (signal) => {
|
|
6845
6361
|
const nextPaused = signal === "__PAUSE__";
|
|
6846
6362
|
if (nextPaused) {
|
|
@@ -6854,15 +6370,15 @@ var Mutation = {
|
|
|
6854
6370
|
};
|
|
6855
6371
|
const initialSignal = await invokeMutationCallback({
|
|
6856
6372
|
mutationCount: 0,
|
|
6857
|
-
html:
|
|
6858
|
-
text:
|
|
6859
|
-
mutationNodes:
|
|
6373
|
+
html: state.html || "",
|
|
6374
|
+
text: state.text || "",
|
|
6375
|
+
mutationNodes: state.mutationNodes || []
|
|
6860
6376
|
});
|
|
6861
6377
|
applyPauseSignal(initialSignal);
|
|
6862
6378
|
const deadline = Date.now() + overallTimeout;
|
|
6863
|
-
let lastState =
|
|
6379
|
+
let lastState = state;
|
|
6864
6380
|
while (Date.now() < deadline) {
|
|
6865
|
-
await
|
|
6381
|
+
await sleep(pollInterval);
|
|
6866
6382
|
lastState = await buildState();
|
|
6867
6383
|
if (!lastState?.hasMatched) {
|
|
6868
6384
|
continue;
|
|
@@ -7950,7 +7466,7 @@ var Logger = {
|
|
|
7950
7466
|
};
|
|
7951
7467
|
|
|
7952
7468
|
// src/share.js
|
|
7953
|
-
var
|
|
7469
|
+
var import_delay4 = __toESM(require("delay"), 1);
|
|
7954
7470
|
|
|
7955
7471
|
// src/internals/watermarkify.js
|
|
7956
7472
|
var DEFAULT_TIMEZONE_OFFSET = 8;
|
|
@@ -8446,10 +7962,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8446
7962
|
</html>
|
|
8447
7963
|
`;
|
|
8448
7964
|
};
|
|
8449
|
-
var
|
|
8450
|
-
return String(value || "default").trim().toLowerCase() === "cloakbrowser" ? "cloakbrowser" : "default";
|
|
8451
|
-
};
|
|
8452
|
-
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
7965
|
+
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
8453
7966
|
if (!page || typeof page.context !== "function") {
|
|
8454
7967
|
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8455
7968
|
return buffer;
|
|
@@ -8473,35 +7986,15 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8473
7986
|
height: viewportHeight
|
|
8474
7987
|
}).catch(() => {
|
|
8475
7988
|
});
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
|
|
8484
|
-
|
|
8485
|
-
await renderPage.goto("about:blank", {
|
|
8486
|
-
waitUntil: "commit"
|
|
8487
|
-
}).catch(() => {
|
|
8488
|
-
});
|
|
8489
|
-
await renderPage.evaluate((html) => {
|
|
8490
|
-
document.open();
|
|
8491
|
-
document.write(html);
|
|
8492
|
-
document.close();
|
|
8493
|
-
}, renderHtml);
|
|
8494
|
-
} else {
|
|
8495
|
-
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
8496
|
-
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8497
|
-
overlaySvg,
|
|
8498
|
-
width: safeWidth,
|
|
8499
|
-
height: safeHeight,
|
|
8500
|
-
imageHeight: safeImageHeight
|
|
8501
|
-
}), {
|
|
8502
|
-
waitUntil: "load"
|
|
8503
|
-
});
|
|
8504
|
-
}
|
|
7989
|
+
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
7990
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
7991
|
+
overlaySvg,
|
|
7992
|
+
width: safeWidth,
|
|
7993
|
+
height: safeHeight,
|
|
7994
|
+
imageHeight: safeImageHeight
|
|
7995
|
+
}), {
|
|
7996
|
+
waitUntil: "load"
|
|
7997
|
+
});
|
|
8505
7998
|
await renderPage.waitForFunction(() => {
|
|
8506
7999
|
const image = document.getElementById("pk-base-image");
|
|
8507
8000
|
return image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0 && image.naturalHeight > 0;
|
|
@@ -9436,7 +8929,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
9436
8929
|
</svg>
|
|
9437
8930
|
`;
|
|
9438
8931
|
};
|
|
9439
|
-
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null
|
|
8932
|
+
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
9440
8933
|
const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
|
|
9441
8934
|
const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
|
|
9442
8935
|
if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
|
|
@@ -9457,7 +8950,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9457
8950
|
if (!overlaySvg) {
|
|
9458
8951
|
return buffer;
|
|
9459
8952
|
}
|
|
9460
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo
|
|
8953
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
9461
8954
|
};
|
|
9462
8955
|
|
|
9463
8956
|
// src/internals/compression.js
|
|
@@ -10021,7 +9514,7 @@ var Share = {
|
|
|
10021
9514
|
);
|
|
10022
9515
|
nextProgressLogTs = now + 5e3;
|
|
10023
9516
|
}
|
|
10024
|
-
await (0,
|
|
9517
|
+
await (0, import_delay4.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
10025
9518
|
}
|
|
10026
9519
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
10027
9520
|
logger15.warning(
|
|
@@ -10055,7 +9548,6 @@ var Share = {
|
|
|
10055
9548
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10056
9549
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10057
9550
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10058
|
-
* @param {'default'|'cloakbrowser'} [options.mode] 截图水印合成模式,默认 default
|
|
10059
9551
|
* @returns {Promise<string>} base64 image
|
|
10060
9552
|
*/
|
|
10061
9553
|
async captureScreen(page, options = {}) {
|
|
@@ -10076,9 +9568,7 @@ var Share = {
|
|
|
10076
9568
|
...screenshotWatermarkify,
|
|
10077
9569
|
capturedAt
|
|
10078
9570
|
});
|
|
10079
|
-
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page
|
|
10080
|
-
mode: options.mode === "cloakbrowser" ? "cloakbrowser" : "default"
|
|
10081
|
-
});
|
|
9571
|
+
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page);
|
|
10082
9572
|
}
|
|
10083
9573
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
10084
9574
|
}
|
|
@@ -10086,9 +9576,8 @@ var Share = {
|
|
|
10086
9576
|
|
|
10087
9577
|
// entrys/node.js
|
|
10088
9578
|
Logger.setLogger(import_crawlee.log);
|
|
10089
|
-
var usePlaywrightToolKit = (
|
|
10090
|
-
|
|
10091
|
-
const toolkit = {
|
|
9579
|
+
var usePlaywrightToolKit = () => {
|
|
9580
|
+
return {
|
|
10092
9581
|
ApifyKit,
|
|
10093
9582
|
AntiCheat,
|
|
10094
9583
|
DeviceInput,
|
|
@@ -10108,7 +9597,6 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10108
9597
|
ByPass,
|
|
10109
9598
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
10110
9599
|
};
|
|
10111
|
-
return toolkit;
|
|
10112
9600
|
};
|
|
10113
9601
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10114
9602
|
0 && (module.exports = {
|