@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.js
CHANGED
|
@@ -13,11 +13,9 @@ __export(constants_exports, {
|
|
|
13
13
|
ActorInfo: () => ActorInfo,
|
|
14
14
|
Code: () => Code,
|
|
15
15
|
Device: () => Device,
|
|
16
|
-
Mode: () => Mode,
|
|
17
16
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
18
17
|
Status: () => Status,
|
|
19
|
-
normalizeDevice: () => normalizeDevice
|
|
20
|
-
normalizeMode: () => normalizeMode
|
|
18
|
+
normalizeDevice: () => normalizeDevice
|
|
21
19
|
});
|
|
22
20
|
var Code = {
|
|
23
21
|
Success: 0,
|
|
@@ -37,10 +35,6 @@ var Device = Object.freeze({
|
|
|
37
35
|
Desktop: "desktop",
|
|
38
36
|
Mobile: "mobile"
|
|
39
37
|
});
|
|
40
|
-
var Mode = Object.freeze({
|
|
41
|
-
Default: "default",
|
|
42
|
-
CloakBrowser: "cloakbrowser"
|
|
43
|
-
});
|
|
44
38
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
45
39
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
46
40
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -48,13 +42,6 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
48
42
|
if (raw === Device.Desktop) return Device.Desktop;
|
|
49
43
|
return normalizedFallback;
|
|
50
44
|
};
|
|
51
|
-
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
52
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.CloakBrowser ? Mode.CloakBrowser : Mode.Default;
|
|
53
|
-
const raw = String(value || "").trim().toLowerCase();
|
|
54
|
-
if (raw === Mode.CloakBrowser) return Mode.CloakBrowser;
|
|
55
|
-
if (raw === Mode.Default) return Mode.Default;
|
|
56
|
-
return normalizedFallback;
|
|
57
|
-
};
|
|
58
45
|
var createActorInfo = (info) => {
|
|
59
46
|
const normalizeDomain = (value) => {
|
|
60
47
|
if (!value) return "";
|
|
@@ -122,6 +109,7 @@ var createActorInfo = (info) => {
|
|
|
122
109
|
const buildLandingUrl = ({ protocol: protocol2, domain: domain2, path: path4 }) => {
|
|
123
110
|
const safeProtocol = String(protocol2).trim();
|
|
124
111
|
const safeDomain = normalizeDomain(domain2);
|
|
112
|
+
if (!safeDomain) return "";
|
|
125
113
|
const safePath = normalizePath(path4);
|
|
126
114
|
return `${safeProtocol}://${safeDomain}${safePath}`;
|
|
127
115
|
};
|
|
@@ -329,6 +317,18 @@ var ActorInfo = {
|
|
|
329
317
|
prefix: "",
|
|
330
318
|
xurl: []
|
|
331
319
|
}
|
|
320
|
+
}),
|
|
321
|
+
// 通用网页抓取 Actor:入口 URL 来自 query,因此这里只声明统一的 Actor 元信息。
|
|
322
|
+
webpage: createActorInfo({
|
|
323
|
+
key: "webpage",
|
|
324
|
+
name: "\u901A\u7528\u7F51\u9875",
|
|
325
|
+
domain: "",
|
|
326
|
+
path: "/",
|
|
327
|
+
share: {
|
|
328
|
+
mode: "dom",
|
|
329
|
+
prefix: "",
|
|
330
|
+
xurl: []
|
|
331
|
+
}
|
|
332
332
|
})
|
|
333
333
|
};
|
|
334
334
|
|
|
@@ -753,7 +753,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
753
753
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
754
754
|
return 0;
|
|
755
755
|
}
|
|
756
|
-
const
|
|
756
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
757
757
|
const isVisible = (el, style, rect) => {
|
|
758
758
|
if (!el || !style || !rect) return false;
|
|
759
759
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -793,7 +793,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
793
793
|
return true;
|
|
794
794
|
});
|
|
795
795
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
796
|
-
if (!
|
|
796
|
+
if (!hasOwn(el.dataset, "pkAffixedAdjusted")) {
|
|
797
797
|
el.dataset.pkAffixedAdjusted = "1";
|
|
798
798
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
799
799
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -824,7 +824,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
824
824
|
};
|
|
825
825
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
826
826
|
await page.evaluate((className) => {
|
|
827
|
-
const
|
|
827
|
+
const hasOwn = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
828
828
|
const expansionKeys = [
|
|
829
829
|
"pkOrigOverflow",
|
|
830
830
|
"pkOrigHeight",
|
|
@@ -832,28 +832,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
832
832
|
"pkOrigMaxHeight"
|
|
833
833
|
];
|
|
834
834
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
835
|
-
if (
|
|
835
|
+
if (hasOwn(el.dataset, "pkOrigPosition")) {
|
|
836
836
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
837
837
|
delete el.dataset.pkOrigPosition;
|
|
838
838
|
delete el.dataset.pkOrigPositionPriority;
|
|
839
839
|
}
|
|
840
|
-
if (
|
|
840
|
+
if (hasOwn(el.dataset, "pkOrigTop")) {
|
|
841
841
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
842
842
|
delete el.dataset.pkOrigTop;
|
|
843
843
|
delete el.dataset.pkOrigTopPriority;
|
|
844
844
|
}
|
|
845
|
-
if (
|
|
845
|
+
if (hasOwn(el.dataset, "pkOrigBottom")) {
|
|
846
846
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
847
847
|
delete el.dataset.pkOrigBottom;
|
|
848
848
|
delete el.dataset.pkOrigBottomPriority;
|
|
849
849
|
}
|
|
850
|
-
if (
|
|
850
|
+
if (hasOwn(el.dataset, "pkOrigTranslate")) {
|
|
851
851
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
852
852
|
delete el.dataset.pkOrigTranslate;
|
|
853
853
|
delete el.dataset.pkOrigTranslatePriority;
|
|
854
854
|
}
|
|
855
855
|
delete el.dataset.pkAffixedAdjusted;
|
|
856
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
856
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn(el.dataset, key));
|
|
857
857
|
if (!stillExpanded) {
|
|
858
858
|
el.classList.remove(className);
|
|
859
859
|
}
|
|
@@ -896,7 +896,7 @@ var prepareExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
|
896
896
|
viewportResized
|
|
897
897
|
};
|
|
898
898
|
};
|
|
899
|
-
var restoreExpandedFullPageScreenshot = async (page,
|
|
899
|
+
var restoreExpandedFullPageScreenshot = async (page, state = {}) => {
|
|
900
900
|
await page.evaluate((className) => {
|
|
901
901
|
const targets = new Set([
|
|
902
902
|
...document.querySelectorAll(`.${className}`),
|
|
@@ -920,8 +920,8 @@ var restoreExpandedFullPageScreenshot = async (page, state2 = {}) => {
|
|
|
920
920
|
el.classList.remove(className);
|
|
921
921
|
});
|
|
922
922
|
}, EXPANDED_SCROLLABLE_CLASS);
|
|
923
|
-
if (
|
|
924
|
-
await page.setViewportSize(
|
|
923
|
+
if (state?.originalViewport && state?.viewportResized) {
|
|
924
|
+
await page.setViewportSize(state.originalViewport);
|
|
925
925
|
}
|
|
926
926
|
};
|
|
927
927
|
var capturePageScreenshot = async (page, options = {}) => {
|
|
@@ -978,21 +978,21 @@ var capturePageScreenshot = async (page, options = {}) => {
|
|
|
978
978
|
}
|
|
979
979
|
};
|
|
980
980
|
var captureExpandedFullPageScreenshot = async (page, options = {}) => {
|
|
981
|
-
const
|
|
981
|
+
const state = await prepareExpandedFullPageScreenshot(page, options);
|
|
982
982
|
try {
|
|
983
983
|
return await capturePageScreenshot(page, {
|
|
984
984
|
fullPage: true,
|
|
985
985
|
type: options.type || "png",
|
|
986
986
|
quality: options.quality,
|
|
987
987
|
timeout: options.timeout,
|
|
988
|
-
maxClipHeight:
|
|
988
|
+
maxClipHeight: state.targetHeight
|
|
989
989
|
});
|
|
990
990
|
} finally {
|
|
991
991
|
await restoreAffixedElementsForExpandedScreenshot(page).catch((error) => {
|
|
992
992
|
logger.warning(`\u79FB\u52A8\u7AEF\u5438\u9644\u5143\u7D20\u6062\u590D\u5931\u8D25: ${error?.message || error}`);
|
|
993
993
|
});
|
|
994
994
|
if (options.restore) {
|
|
995
|
-
await restoreExpandedFullPageScreenshot(page,
|
|
995
|
+
await restoreExpandedFullPageScreenshot(page, state);
|
|
996
996
|
}
|
|
997
997
|
}
|
|
998
998
|
};
|
|
@@ -1059,7 +1059,7 @@ import { serializeError as serializeError2 } from "serialize-error";
|
|
|
1059
1059
|
|
|
1060
1060
|
// src/internals/proxy-meter-runtime.js
|
|
1061
1061
|
import { spawn, spawnSync } from "child_process";
|
|
1062
|
-
import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
1062
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
1063
1063
|
import { tmpdir } from "os";
|
|
1064
1064
|
import path from "path";
|
|
1065
1065
|
import { fileURLToPath } from "url";
|
|
@@ -1168,6 +1168,19 @@ var ensureLogPath = () => {
|
|
|
1168
1168
|
const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
|
|
1169
1169
|
return path.join(baseDir, label);
|
|
1170
1170
|
};
|
|
1171
|
+
var ensureStdioLogPath = (logPath) => `${logPath}.stdio.log`;
|
|
1172
|
+
var writeChildOutput = (stream, output, prefix) => {
|
|
1173
|
+
if (!stream || !output) return;
|
|
1174
|
+
output.on("data", (chunk) => {
|
|
1175
|
+
const text = chunk?.toString?.() || String(chunk || "");
|
|
1176
|
+
if (!text) return;
|
|
1177
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1178
|
+
if (!line) continue;
|
|
1179
|
+
stream.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${prefix} ${line}
|
|
1180
|
+
`);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
};
|
|
1171
1184
|
var readSnapshot = (logPath) => {
|
|
1172
1185
|
if (!logPath || !existsSync(logPath)) return null;
|
|
1173
1186
|
try {
|
|
@@ -1335,6 +1348,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
1335
1348
|
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
1336
1349
|
const port = pickFreePort();
|
|
1337
1350
|
const logPath = ensureLogPath();
|
|
1351
|
+
const stdioLogPath = ensureStdioLogPath(logPath);
|
|
1338
1352
|
const scriptPath = resolveScriptPath();
|
|
1339
1353
|
const debugMode = Boolean(options.debugMode);
|
|
1340
1354
|
const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
|
|
@@ -1347,19 +1361,28 @@ var startProxyMeter = (options = {}) => {
|
|
|
1347
1361
|
PROXY_METER_DEBUG: debugMode ? "1" : "0",
|
|
1348
1362
|
PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
|
|
1349
1363
|
};
|
|
1364
|
+
const stdioLog = createWriteStream(stdioLogPath, { flags: "a" });
|
|
1365
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] start script=${scriptPath} port=${port} snapshot=${logPath}
|
|
1366
|
+
`);
|
|
1350
1367
|
const child = spawn(process.execPath, [scriptPath], {
|
|
1351
1368
|
env,
|
|
1352
|
-
stdio: ["ignore", "
|
|
1369
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1353
1370
|
});
|
|
1354
|
-
child.
|
|
1371
|
+
writeChildOutput(stdioLog, child.stdout, "stdout");
|
|
1372
|
+
writeChildOutput(stdioLog, child.stderr, "stderr");
|
|
1373
|
+
child.once("exit", (code, signal) => {
|
|
1374
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] exit code=${code ?? ""} signal=${signal ?? ""}
|
|
1375
|
+
`);
|
|
1376
|
+
stdioLog.end();
|
|
1355
1377
|
if (code && code !== 0) {
|
|
1356
|
-
logger2.warn(`[proxy-meter] exited with code ${code}`);
|
|
1378
|
+
logger2.warn(`[proxy-meter] exited with code ${code}; stdio=${stdioLogPath}`);
|
|
1357
1379
|
}
|
|
1358
1380
|
});
|
|
1359
1381
|
runtime = {
|
|
1360
1382
|
proc: child,
|
|
1361
1383
|
port,
|
|
1362
1384
|
logPath,
|
|
1385
|
+
stdioLogPath,
|
|
1363
1386
|
startedAt: Date.now()
|
|
1364
1387
|
};
|
|
1365
1388
|
registerCleanup();
|
|
@@ -1887,8 +1910,8 @@ var normalizeBrowserProfile = (value) => {
|
|
|
1887
1910
|
payload: buildBrowserProfilePayload(core, observed)
|
|
1888
1911
|
};
|
|
1889
1912
|
};
|
|
1890
|
-
var rememberRuntimeState = (
|
|
1891
|
-
rememberedRuntimeState = deepClone(
|
|
1913
|
+
var rememberRuntimeState = (state) => {
|
|
1914
|
+
rememberedRuntimeState = deepClone(state);
|
|
1892
1915
|
return rememberedRuntimeState;
|
|
1893
1916
|
};
|
|
1894
1917
|
var normalizeRuntimeState = (source = {}, actor = "") => {
|
|
@@ -1947,7 +1970,7 @@ var RuntimeEnv = {
|
|
|
1947
1970
|
} else {
|
|
1948
1971
|
delete normalizedRuntime.browser_profile;
|
|
1949
1972
|
}
|
|
1950
|
-
const
|
|
1973
|
+
const state = {
|
|
1951
1974
|
actor: resolvedActor,
|
|
1952
1975
|
device,
|
|
1953
1976
|
runtime: normalizedRuntime,
|
|
@@ -1961,73 +1984,73 @@ var RuntimeEnv = {
|
|
|
1961
1984
|
browserProfileCore: browserProfile.core,
|
|
1962
1985
|
browserProfileObserved: browserProfile.observed
|
|
1963
1986
|
};
|
|
1964
|
-
rememberRuntimeState(
|
|
1965
|
-
return
|
|
1987
|
+
rememberRuntimeState(state);
|
|
1988
|
+
return state;
|
|
1966
1989
|
},
|
|
1967
1990
|
// buildEnvPatch 只构造允许回写到后端 env 的字段集合。
|
|
1968
1991
|
buildEnvPatch(source = {}, actor = "") {
|
|
1969
|
-
const
|
|
1970
|
-
const browserProfile = buildBrowserProfilePayload(
|
|
1992
|
+
const state = normalizeRuntimeState(source, actor);
|
|
1993
|
+
const browserProfile = buildBrowserProfilePayload(state.browserProfileCore, state.browserProfileObserved);
|
|
1971
1994
|
const envPatch = {
|
|
1972
|
-
...Array.isArray(
|
|
1973
|
-
...Object.keys(
|
|
1974
|
-
...Object.keys(
|
|
1995
|
+
...Array.isArray(state.cookies) && state.cookies.length > 0 ? { cookies: state.cookies } : {},
|
|
1996
|
+
...Object.keys(state.localStorage || {}).length > 0 ? { local_storage: state.localStorage } : {},
|
|
1997
|
+
...Object.keys(state.sessionStorage || {}).length > 0 ? { session_storage: state.sessionStorage } : {},
|
|
1975
1998
|
...Object.keys(browserProfile).length > 0 ? { browser_profile: browserProfile } : {}
|
|
1976
1999
|
};
|
|
1977
2000
|
return Object.keys(envPatch).length > 0 ? envPatch : null;
|
|
1978
2001
|
},
|
|
1979
2002
|
// hasLoginState 只判断 runtime 是否存在有效载荷,不再区分具体字段来源。
|
|
1980
2003
|
hasLoginState(source = {}, actor = "") {
|
|
1981
|
-
const
|
|
1982
|
-
return isPlainObject(
|
|
2004
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2005
|
+
return isPlainObject(state.runtime) && Object.keys(state.runtime || {}).length > 0;
|
|
1983
2006
|
},
|
|
1984
2007
|
rememberState(source = {}) {
|
|
1985
|
-
const
|
|
1986
|
-
rememberRuntimeState(
|
|
2008
|
+
const state = normalizeRuntimeState(source);
|
|
2009
|
+
rememberRuntimeState(state);
|
|
1987
2010
|
return RuntimeEnv.peekRememberedState();
|
|
1988
2011
|
},
|
|
1989
2012
|
peekRememberedState() {
|
|
1990
2013
|
return rememberedRuntimeState ? deepClone(rememberedRuntimeState) : null;
|
|
1991
2014
|
},
|
|
1992
2015
|
getBrowserProfileCore(source = {}, actor = "") {
|
|
1993
|
-
const
|
|
1994
|
-
return deepClone(
|
|
2016
|
+
const state = normalizeRuntimeState(source, actor);
|
|
2017
|
+
return deepClone(state.browserProfileCore || {});
|
|
1995
2018
|
},
|
|
1996
2019
|
setBrowserProfileCore(source = {}, core = {}, actor = "") {
|
|
1997
|
-
const
|
|
2020
|
+
const state = normalizeRuntimeState(source, actor);
|
|
1998
2021
|
const normalizedCore = normalizeBrowserProfileCore({
|
|
1999
2022
|
...core,
|
|
2000
|
-
device: normalizeKnownDevice(core?.device) ||
|
|
2023
|
+
device: normalizeKnownDevice(core?.device) || state.device
|
|
2001
2024
|
});
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
if (Object.keys(
|
|
2005
|
-
|
|
2025
|
+
state.browserProfileCore = normalizedCore;
|
|
2026
|
+
state.browserProfile = buildBrowserProfilePayload(normalizedCore, state.browserProfileObserved);
|
|
2027
|
+
if (Object.keys(state.browserProfile).length > 0) {
|
|
2028
|
+
state.runtime.browser_profile = state.browserProfile;
|
|
2006
2029
|
} else {
|
|
2007
|
-
delete
|
|
2030
|
+
delete state.runtime.browser_profile;
|
|
2008
2031
|
}
|
|
2009
|
-
rememberRuntimeState(
|
|
2010
|
-
return
|
|
2032
|
+
rememberRuntimeState(state);
|
|
2033
|
+
return state;
|
|
2011
2034
|
},
|
|
2012
2035
|
// applyToPage 只负责把登录态相关字段注入页面:
|
|
2013
2036
|
// cookies / localStorage / sessionStorage。
|
|
2014
2037
|
// 指纹、时区、UA、viewport 的回放发生在 launch.js 启动阶段,不在这里做。
|
|
2015
2038
|
async applyToPage(page, source = {}, options = {}) {
|
|
2016
2039
|
if (!page) return;
|
|
2017
|
-
let
|
|
2040
|
+
let state = normalizeRuntimeState(source, options?.actor || "");
|
|
2018
2041
|
if (typeof options?.preapply === "function") {
|
|
2019
|
-
|
|
2020
|
-
rememberRuntimeState(
|
|
2042
|
+
state = await options.preapply(state) || state;
|
|
2043
|
+
rememberRuntimeState(state);
|
|
2021
2044
|
}
|
|
2022
2045
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
2023
2046
|
configurable: true,
|
|
2024
2047
|
enumerable: false,
|
|
2025
2048
|
writable: true,
|
|
2026
|
-
value:
|
|
2049
|
+
value: state
|
|
2027
2050
|
});
|
|
2028
|
-
const localStorage =
|
|
2029
|
-
const sessionStorage =
|
|
2030
|
-
const cookies = (
|
|
2051
|
+
const localStorage = state.localStorage || {};
|
|
2052
|
+
const sessionStorage = state.sessionStorage || {};
|
|
2053
|
+
const cookies = (state.cookies || []).map((cookie) => {
|
|
2031
2054
|
const normalized = { ...cookie };
|
|
2032
2055
|
if (!normalized.path) {
|
|
2033
2056
|
normalized.path = "/";
|
|
@@ -2065,8 +2088,8 @@ var RuntimeEnv = {
|
|
|
2065
2088
|
},
|
|
2066
2089
|
// captureEnvPatch 在任务结束时采集最新环境快照,用于 pushSuccess / pushFailed 自动回写。
|
|
2067
2090
|
async captureEnvPatch(page, source = {}, options = {}) {
|
|
2068
|
-
const
|
|
2069
|
-
const baseline = RuntimeEnv.buildEnvPatch(
|
|
2091
|
+
const state = normalizeRuntimeState(source, options?.actor || "");
|
|
2092
|
+
const baseline = RuntimeEnv.buildEnvPatch(state) || {};
|
|
2070
2093
|
if (!page || typeof page.evaluate !== "function" || typeof page.context !== "function") {
|
|
2071
2094
|
return Object.keys(baseline).length > 0 ? baseline : null;
|
|
2072
2095
|
}
|
|
@@ -2085,7 +2108,7 @@ var RuntimeEnv = {
|
|
|
2085
2108
|
cookies
|
|
2086
2109
|
},
|
|
2087
2110
|
{
|
|
2088
|
-
browserProfileCore:
|
|
2111
|
+
browserProfileCore: state.browserProfileCore
|
|
2089
2112
|
}
|
|
2090
2113
|
);
|
|
2091
2114
|
return RuntimeEnv.mergeEnvPatches(baseline, capturedPatch);
|
|
@@ -2099,11 +2122,11 @@ var RuntimeEnv = {
|
|
|
2099
2122
|
var logger3 = createInternalLogger("ApifyKit");
|
|
2100
2123
|
var resolveRuntimeContext = (input) => {
|
|
2101
2124
|
const rememberedState = RuntimeEnv.peekRememberedState();
|
|
2102
|
-
const
|
|
2103
|
-
const envPatch = RuntimeEnv.buildEnvPatch(
|
|
2125
|
+
const state = rememberedState || RuntimeEnv.parseInput(input || {});
|
|
2126
|
+
const envPatch = RuntimeEnv.buildEnvPatch(state) || null;
|
|
2104
2127
|
return {
|
|
2105
|
-
actor:
|
|
2106
|
-
runtime:
|
|
2128
|
+
actor: state.actor,
|
|
2129
|
+
runtime: state.runtime,
|
|
2107
2130
|
envPatch
|
|
2108
2131
|
};
|
|
2109
2132
|
};
|
|
@@ -2462,58 +2485,8 @@ var Utils = {
|
|
|
2462
2485
|
}
|
|
2463
2486
|
};
|
|
2464
2487
|
|
|
2465
|
-
// src/
|
|
2466
|
-
var
|
|
2467
|
-
mode: Mode.Default
|
|
2468
|
-
};
|
|
2469
|
-
var normalizeStrategies = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2470
|
-
var ToolkitContext = {
|
|
2471
|
-
get mode() {
|
|
2472
|
-
return state.mode;
|
|
2473
|
-
},
|
|
2474
|
-
setMode(mode = Mode.Default) {
|
|
2475
|
-
state.mode = normalizeMode(mode, Mode.Default);
|
|
2476
|
-
return state.mode;
|
|
2477
|
-
}
|
|
2478
|
-
};
|
|
2479
|
-
var getToolkitMode = () => state.mode;
|
|
2480
|
-
var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
2481
|
-
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2482
|
-
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2483
|
-
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2484
|
-
const delegate = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2485
|
-
return {
|
|
2486
|
-
mode: normalizedMode,
|
|
2487
|
-
delegate
|
|
2488
|
-
};
|
|
2489
|
-
};
|
|
2490
|
-
|
|
2491
|
-
// src/internals/delegate.js
|
|
2492
|
-
var normalizeMethodDefinition = (definition) => typeof definition === "string" ? { name: definition, enumerable: true } : {
|
|
2493
|
-
name: String(definition?.name || "").trim(),
|
|
2494
|
-
enumerable: definition?.enumerable !== false
|
|
2495
|
-
};
|
|
2496
|
-
var createMethodDescriptor = (namespace, methodName, enumerable, strategies) => ({
|
|
2497
|
-
enumerable,
|
|
2498
|
-
value: (...args) => {
|
|
2499
|
-
const { mode, delegate } = resolveModeStrategy(strategies);
|
|
2500
|
-
if (typeof delegate?.[methodName] !== "function") {
|
|
2501
|
-
throw new Error(`${namespace}.${methodName} is not available in ${mode} mode`);
|
|
2502
|
-
}
|
|
2503
|
-
return delegate[methodName](...args);
|
|
2504
|
-
}
|
|
2505
|
-
});
|
|
2506
|
-
var createDelegatedFacade = (namespace, strategies = {}, methods = []) => {
|
|
2507
|
-
const descriptors = Object.fromEntries(
|
|
2508
|
-
methods.map(normalizeMethodDefinition).filter((method) => method.name).map((method) => [
|
|
2509
|
-
method.name,
|
|
2510
|
-
createMethodDescriptor(namespace, method.name, method.enumerable, strategies)
|
|
2511
|
-
])
|
|
2512
|
-
);
|
|
2513
|
-
return Object.defineProperties({}, descriptors);
|
|
2514
|
-
};
|
|
2515
|
-
|
|
2516
|
-
// src/internals/anti-cheat/default.js
|
|
2488
|
+
// src/anti-cheat.js
|
|
2489
|
+
var logger5 = createInternalLogger("AntiCheat");
|
|
2517
2490
|
var BASE_CONFIG = Object.freeze({
|
|
2518
2491
|
locale: "zh-CN",
|
|
2519
2492
|
acceptLanguage: "zh-CN,zh;q=0.9",
|
|
@@ -2548,7 +2521,7 @@ function buildFingerprintOptions({ locale = BASE_CONFIG.locale, browserMajorVers
|
|
|
2548
2521
|
}
|
|
2549
2522
|
return options;
|
|
2550
2523
|
}
|
|
2551
|
-
var
|
|
2524
|
+
var AntiCheat = {
|
|
2552
2525
|
/**
|
|
2553
2526
|
* 获取统一的基础配置
|
|
2554
2527
|
*/
|
|
@@ -2585,53 +2558,6 @@ var DefaultAntiCheat = {
|
|
|
2585
2558
|
}
|
|
2586
2559
|
};
|
|
2587
2560
|
|
|
2588
|
-
// src/internals/anti-cheat/cloakbrowser.js
|
|
2589
|
-
var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
2590
|
-
locale: "",
|
|
2591
|
-
acceptLanguage: "",
|
|
2592
|
-
timezoneId: "",
|
|
2593
|
-
timezoneOffset: null,
|
|
2594
|
-
geolocation: null
|
|
2595
|
-
});
|
|
2596
|
-
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2597
|
-
var CloakBrowserAntiCheat = {
|
|
2598
|
-
/**
|
|
2599
|
-
* CloakBrowser 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2600
|
-
*/
|
|
2601
|
-
getBaseConfig() {
|
|
2602
|
-
return { ...CLOAK_BROWSER_BASE_CONFIG };
|
|
2603
|
-
},
|
|
2604
|
-
getFingerprintGeneratorOptions() {
|
|
2605
|
-
return {};
|
|
2606
|
-
},
|
|
2607
|
-
getLaunchArgs() {
|
|
2608
|
-
return [];
|
|
2609
|
-
},
|
|
2610
|
-
getTlsFingerprintOptions() {
|
|
2611
|
-
return {};
|
|
2612
|
-
},
|
|
2613
|
-
applyLocaleHeaders(headers, acceptLanguage = "") {
|
|
2614
|
-
const normalizedHeaders = normalizeHeaders(headers);
|
|
2615
|
-
if (acceptLanguage && !normalizedHeaders["accept-language"]) {
|
|
2616
|
-
normalizedHeaders["accept-language"] = acceptLanguage;
|
|
2617
|
-
}
|
|
2618
|
-
return normalizedHeaders;
|
|
2619
|
-
}
|
|
2620
|
-
};
|
|
2621
|
-
|
|
2622
|
-
// src/anti-cheat.js
|
|
2623
|
-
var antiCheatStrategies = {
|
|
2624
|
-
[Mode.Default]: DefaultAntiCheat,
|
|
2625
|
-
[Mode.CloakBrowser]: CloakBrowserAntiCheat
|
|
2626
|
-
};
|
|
2627
|
-
var AntiCheat = createDelegatedFacade("AntiCheat", antiCheatStrategies, [
|
|
2628
|
-
"getBaseConfig",
|
|
2629
|
-
"getFingerprintGeneratorOptions",
|
|
2630
|
-
"getLaunchArgs",
|
|
2631
|
-
"getTlsFingerprintOptions",
|
|
2632
|
-
"applyLocaleHeaders"
|
|
2633
|
-
]);
|
|
2634
|
-
|
|
2635
2561
|
// src/device-input.js
|
|
2636
2562
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
2637
2563
|
var assertPage = (page, method) => {
|
|
@@ -3031,12 +2957,12 @@ var resolveDescriptor = (descriptor, device) => {
|
|
|
3031
2957
|
}
|
|
3032
2958
|
return resolved;
|
|
3033
2959
|
};
|
|
3034
|
-
var attachRuntimeState = (page,
|
|
2960
|
+
var attachRuntimeState = (page, state) => {
|
|
3035
2961
|
Object.defineProperty(page, PageRuntimeStateKey, {
|
|
3036
2962
|
configurable: true,
|
|
3037
2963
|
enumerable: false,
|
|
3038
2964
|
writable: true,
|
|
3039
|
-
value:
|
|
2965
|
+
value: state
|
|
3040
2966
|
});
|
|
3041
2967
|
};
|
|
3042
2968
|
var restoreRuntimeState = (page, snapshot) => {
|
|
@@ -3185,7 +3111,7 @@ var DeviceView = {
|
|
|
3185
3111
|
// src/internals/humanize/desktop.js
|
|
3186
3112
|
import delay2 from "delay";
|
|
3187
3113
|
import { createCursor } from "ghost-cursor-playwright";
|
|
3188
|
-
var
|
|
3114
|
+
var logger6 = createInternalLogger("Humanize");
|
|
3189
3115
|
var $CursorWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3190
3116
|
function $GetCursor(page) {
|
|
3191
3117
|
const cursor = $CursorWeakMap.get(page);
|
|
@@ -3213,13 +3139,13 @@ var Humanize = {
|
|
|
3213
3139
|
*/
|
|
3214
3140
|
async initializeCursor(page) {
|
|
3215
3141
|
if ($CursorWeakMap.has(page)) {
|
|
3216
|
-
|
|
3142
|
+
logger6.debug("initializeCursor: cursor already exists, skipping");
|
|
3217
3143
|
return;
|
|
3218
3144
|
}
|
|
3219
|
-
|
|
3145
|
+
logger6.start("initializeCursor", "creating cursor");
|
|
3220
3146
|
const cursor = await createCursor(page);
|
|
3221
3147
|
$CursorWeakMap.set(page, cursor);
|
|
3222
|
-
|
|
3148
|
+
logger6.success("initializeCursor", "cursor initialized");
|
|
3223
3149
|
},
|
|
3224
3150
|
/**
|
|
3225
3151
|
* 人类化鼠标移动 - 使用 ghost-cursor 移动到指定位置或元素
|
|
@@ -3229,17 +3155,17 @@ var Humanize = {
|
|
|
3229
3155
|
*/
|
|
3230
3156
|
async humanMove(page, target) {
|
|
3231
3157
|
const cursor = $GetCursor(page);
|
|
3232
|
-
|
|
3158
|
+
logger6.start("humanMove", `target=${typeof target === "string" ? target : "element/coords"}`);
|
|
3233
3159
|
try {
|
|
3234
3160
|
if (typeof target === "string") {
|
|
3235
3161
|
const element = await page.$(target);
|
|
3236
3162
|
if (!element) {
|
|
3237
|
-
|
|
3163
|
+
logger6.warn(`humanMove: \u5143\u7D20\u4E0D\u5B58\u5728 ${target}`);
|
|
3238
3164
|
return false;
|
|
3239
3165
|
}
|
|
3240
3166
|
const box = await element.boundingBox();
|
|
3241
3167
|
if (!box) {
|
|
3242
|
-
|
|
3168
|
+
logger6.warn(`humanMove: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E ${target}`);
|
|
3243
3169
|
return false;
|
|
3244
3170
|
}
|
|
3245
3171
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.2;
|
|
@@ -3255,10 +3181,10 @@ var Humanize = {
|
|
|
3255
3181
|
await cursor.actions.move({ x, y });
|
|
3256
3182
|
}
|
|
3257
3183
|
}
|
|
3258
|
-
|
|
3184
|
+
logger6.success("humanMove");
|
|
3259
3185
|
return true;
|
|
3260
3186
|
} catch (error) {
|
|
3261
|
-
|
|
3187
|
+
logger6.fail("humanMove", error);
|
|
3262
3188
|
throw error;
|
|
3263
3189
|
}
|
|
3264
3190
|
},
|
|
@@ -3282,12 +3208,12 @@ var Humanize = {
|
|
|
3282
3208
|
maxDurationMs = maxSteps * 220 + 800
|
|
3283
3209
|
} = options;
|
|
3284
3210
|
const targetDesc = typeof target === "string" ? target : "ElementHandle";
|
|
3285
|
-
|
|
3211
|
+
logger6.start("humanScroll", `target=${targetDesc}`);
|
|
3286
3212
|
let element;
|
|
3287
3213
|
if (typeof target === "string") {
|
|
3288
3214
|
element = await page.$(target);
|
|
3289
3215
|
if (!element) {
|
|
3290
|
-
|
|
3216
|
+
logger6.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${target}`);
|
|
3291
3217
|
return { element: null, didScroll: false };
|
|
3292
3218
|
}
|
|
3293
3219
|
} else {
|
|
@@ -3362,26 +3288,26 @@ var Humanize = {
|
|
|
3362
3288
|
try {
|
|
3363
3289
|
for (let i = 0; i < maxSteps; i++) {
|
|
3364
3290
|
if (Date.now() - startTime > maxDurationMs) {
|
|
3365
|
-
|
|
3291
|
+
logger6.warn(`humanScroll | \u8D85\u65F6\u4FDD\u62A4\u89E6\u53D1 (${maxDurationMs}ms)`);
|
|
3366
3292
|
return { element, didScroll };
|
|
3367
3293
|
}
|
|
3368
3294
|
const status = await checkVisibility();
|
|
3369
3295
|
if (status.code === "VISIBLE") {
|
|
3370
3296
|
if (status.isFixed) {
|
|
3371
|
-
|
|
3297
|
+
logger6.info("humanScroll | fixed \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3372
3298
|
} else {
|
|
3373
|
-
|
|
3299
|
+
logger6.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
3374
3300
|
}
|
|
3375
|
-
|
|
3301
|
+
logger6.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
3376
3302
|
return { element, didScroll };
|
|
3377
3303
|
}
|
|
3378
|
-
|
|
3304
|
+
logger6.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason} ${status.direction ? `(${status.direction})` : ""}`);
|
|
3379
3305
|
if (status.code === "OBSTRUCTED" && status.obstruction) {
|
|
3380
|
-
|
|
3306
|
+
logger6.debug(`humanScroll | \u88AB\u4EE5\u4E0B\u5143\u7D20\u906E\u6321 <${status.obstruction.tag} id="${status.obstruction.id}">`);
|
|
3381
3307
|
}
|
|
3382
3308
|
const scrollRect = await getScrollableRect2();
|
|
3383
3309
|
if (!scrollRect && status.isFixed) {
|
|
3384
|
-
|
|
3310
|
+
logger6.warn("humanScroll | fixed \u5BB9\u5668\u5185\u4E14\u65E0\u53EF\u6EDA\u52A8\u7956\u5148\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
3385
3311
|
return { element, didScroll };
|
|
3386
3312
|
}
|
|
3387
3313
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
@@ -3417,10 +3343,10 @@ var Humanize = {
|
|
|
3417
3343
|
didScroll = true;
|
|
3418
3344
|
await delay2(this.jitterMs(20 + Math.random() * 40, 0.2));
|
|
3419
3345
|
}
|
|
3420
|
-
|
|
3346
|
+
logger6.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
3421
3347
|
return { element, didScroll };
|
|
3422
3348
|
} catch (error) {
|
|
3423
|
-
|
|
3349
|
+
logger6.fail("humanScroll", error);
|
|
3424
3350
|
throw error;
|
|
3425
3351
|
}
|
|
3426
3352
|
},
|
|
@@ -3438,7 +3364,7 @@ var Humanize = {
|
|
|
3438
3364
|
const cursor = $GetCursor(page);
|
|
3439
3365
|
const { reactionDelay = 250, throwOnMissing = true, scrollIfNeeded = true, restore = false } = options;
|
|
3440
3366
|
const targetDesc = target == null ? "Current Position" : typeof target === "string" ? target : "ElementHandle";
|
|
3441
|
-
|
|
3367
|
+
logger6.start("humanClick", `target=${targetDesc}`);
|
|
3442
3368
|
const restoreOnce = async () => {
|
|
3443
3369
|
if (restoreOnce.restored) return;
|
|
3444
3370
|
restoreOnce.restored = true;
|
|
@@ -3447,14 +3373,14 @@ var Humanize = {
|
|
|
3447
3373
|
await delay2(this.jitterMs(1e3));
|
|
3448
3374
|
await restoreOnce.do();
|
|
3449
3375
|
} catch (restoreError) {
|
|
3450
|
-
|
|
3376
|
+
logger6.warn(`humanClick: \u6062\u590D\u6EDA\u52A8\u4F4D\u7F6E\u5931\u8D25: ${restoreError.message}`);
|
|
3451
3377
|
}
|
|
3452
3378
|
};
|
|
3453
3379
|
try {
|
|
3454
3380
|
if (target == null) {
|
|
3455
3381
|
await delay2(this.jitterMs(reactionDelay, 0.4));
|
|
3456
3382
|
await cursor.actions.click();
|
|
3457
|
-
|
|
3383
|
+
logger6.success("humanClick", "Clicked current position");
|
|
3458
3384
|
return true;
|
|
3459
3385
|
}
|
|
3460
3386
|
let element;
|
|
@@ -3464,7 +3390,7 @@ var Humanize = {
|
|
|
3464
3390
|
if (throwOnMissing) {
|
|
3465
3391
|
throw new Error(`\u627E\u4E0D\u5230\u5143\u7D20 ${target}`);
|
|
3466
3392
|
}
|
|
3467
|
-
|
|
3393
|
+
logger6.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${target}`);
|
|
3468
3394
|
return false;
|
|
3469
3395
|
}
|
|
3470
3396
|
} else {
|
|
@@ -3480,7 +3406,7 @@ var Humanize = {
|
|
|
3480
3406
|
if (throwOnMissing) {
|
|
3481
3407
|
throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
3482
3408
|
}
|
|
3483
|
-
|
|
3409
|
+
logger6.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
3484
3410
|
return false;
|
|
3485
3411
|
}
|
|
3486
3412
|
const x = box.x + box.width / 2 + (Math.random() - 0.5) * box.width * 0.3;
|
|
@@ -3489,11 +3415,11 @@ var Humanize = {
|
|
|
3489
3415
|
await delay2(this.jitterMs(reactionDelay, 0.4));
|
|
3490
3416
|
await cursor.actions.click();
|
|
3491
3417
|
await restoreOnce();
|
|
3492
|
-
|
|
3418
|
+
logger6.success("humanClick");
|
|
3493
3419
|
return true;
|
|
3494
3420
|
} catch (error) {
|
|
3495
3421
|
await restoreOnce();
|
|
3496
|
-
|
|
3422
|
+
logger6.fail("humanClick", error);
|
|
3497
3423
|
throw error;
|
|
3498
3424
|
}
|
|
3499
3425
|
},
|
|
@@ -3504,9 +3430,9 @@ var Humanize = {
|
|
|
3504
3430
|
*/
|
|
3505
3431
|
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
3506
3432
|
const ms = this.jitterMs(baseMs, jitterPercent);
|
|
3507
|
-
|
|
3433
|
+
logger6.start("randomSleep", `base=${baseMs}, actual=${ms}ms`);
|
|
3508
3434
|
await delay2(ms);
|
|
3509
|
-
|
|
3435
|
+
logger6.success("randomSleep");
|
|
3510
3436
|
},
|
|
3511
3437
|
/**
|
|
3512
3438
|
* 模拟人类"注视"或"阅读"行为:鼠标在页面上随机微动
|
|
@@ -3516,7 +3442,7 @@ var Humanize = {
|
|
|
3516
3442
|
async simulateGaze(page, baseDurationMs = 2500) {
|
|
3517
3443
|
const cursor = $GetCursor(page);
|
|
3518
3444
|
const durationMs = this.jitterMs(baseDurationMs, 0.4);
|
|
3519
|
-
|
|
3445
|
+
logger6.start("simulateGaze", `duration=${durationMs}ms`);
|
|
3520
3446
|
const startTime = Date.now();
|
|
3521
3447
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3522
3448
|
while (Date.now() - startTime < durationMs) {
|
|
@@ -3525,7 +3451,7 @@ var Humanize = {
|
|
|
3525
3451
|
await cursor.actions.move({ x, y });
|
|
3526
3452
|
await delay2(this.jitterMs(600, 0.5));
|
|
3527
3453
|
}
|
|
3528
|
-
|
|
3454
|
+
logger6.success("simulateGaze");
|
|
3529
3455
|
},
|
|
3530
3456
|
/**
|
|
3531
3457
|
* 人类化输入 - 带节奏变化(快-慢-停顿-偶尔加速)
|
|
@@ -3538,7 +3464,7 @@ var Humanize = {
|
|
|
3538
3464
|
* @param {number} [options.pauseBase=800] - 停顿时长基础值 (ms),实际 ±50% 抖动
|
|
3539
3465
|
*/
|
|
3540
3466
|
async humanType(page, selector, text, options = {}) {
|
|
3541
|
-
|
|
3467
|
+
logger6.start("humanType", `selector=${selector}, textLen=${text.length}`);
|
|
3542
3468
|
const {
|
|
3543
3469
|
baseDelay = 180,
|
|
3544
3470
|
pauseProbability = 0.08,
|
|
@@ -3562,13 +3488,13 @@ var Humanize = {
|
|
|
3562
3488
|
await delay2(charDelay);
|
|
3563
3489
|
if (Math.random() < pauseProbability && i < text.length - 1) {
|
|
3564
3490
|
const pauseTime = this.jitterMs(pauseBase, 0.5);
|
|
3565
|
-
|
|
3491
|
+
logger6.debug(`\u505C\u987F ${pauseTime}ms...`);
|
|
3566
3492
|
await delay2(pauseTime);
|
|
3567
3493
|
}
|
|
3568
3494
|
}
|
|
3569
|
-
|
|
3495
|
+
logger6.success("humanType");
|
|
3570
3496
|
} catch (error) {
|
|
3571
|
-
|
|
3497
|
+
logger6.fail("humanType", error);
|
|
3572
3498
|
throw error;
|
|
3573
3499
|
}
|
|
3574
3500
|
},
|
|
@@ -3592,7 +3518,7 @@ var Humanize = {
|
|
|
3592
3518
|
keyboardOptions = {}
|
|
3593
3519
|
} = pressOptions || {};
|
|
3594
3520
|
const targetDesc = hasTarget ? typeof targetOrKey === "string" ? targetOrKey : "ElementHandle" : "current focus";
|
|
3595
|
-
|
|
3521
|
+
logger6.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
3596
3522
|
try {
|
|
3597
3523
|
if (hasTarget) {
|
|
3598
3524
|
await this.humanClick(page, targetOrKey, { reactionDelay: focusDelay, scrollIfNeeded, throwOnMissing });
|
|
@@ -3602,10 +3528,10 @@ var Humanize = {
|
|
|
3602
3528
|
...keyboardOptions,
|
|
3603
3529
|
delay: this.jitterMs(holdDelay, 0.5)
|
|
3604
3530
|
});
|
|
3605
|
-
|
|
3531
|
+
logger6.success("humanPress");
|
|
3606
3532
|
return true;
|
|
3607
3533
|
} catch (error) {
|
|
3608
|
-
|
|
3534
|
+
logger6.fail("humanPress", error);
|
|
3609
3535
|
throw error;
|
|
3610
3536
|
}
|
|
3611
3537
|
},
|
|
@@ -3615,22 +3541,22 @@ var Humanize = {
|
|
|
3615
3541
|
* @param {string} selector - 输入框选择器
|
|
3616
3542
|
*/
|
|
3617
3543
|
async humanClear(page, selector) {
|
|
3618
|
-
|
|
3544
|
+
logger6.start("humanClear", `selector=${selector}`);
|
|
3619
3545
|
try {
|
|
3620
3546
|
const locator = page.locator(selector);
|
|
3621
3547
|
await locator.click();
|
|
3622
3548
|
await delay2(this.jitterMs(200, 0.4));
|
|
3623
3549
|
const currentValue = await locator.inputValue();
|
|
3624
3550
|
if (!currentValue || currentValue.length === 0) {
|
|
3625
|
-
|
|
3551
|
+
logger6.success("humanClear", "already empty");
|
|
3626
3552
|
return;
|
|
3627
3553
|
}
|
|
3628
3554
|
await page.keyboard.press("Meta+A");
|
|
3629
3555
|
await delay2(this.jitterMs(100, 0.4));
|
|
3630
3556
|
await page.keyboard.press("Backspace");
|
|
3631
|
-
|
|
3557
|
+
logger6.success("humanClear");
|
|
3632
3558
|
} catch (error) {
|
|
3633
|
-
|
|
3559
|
+
logger6.fail("humanClear", error);
|
|
3634
3560
|
throw error;
|
|
3635
3561
|
}
|
|
3636
3562
|
},
|
|
@@ -3642,7 +3568,7 @@ var Humanize = {
|
|
|
3642
3568
|
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
3643
3569
|
const cursor = $GetCursor(page);
|
|
3644
3570
|
const durationMs = this.jitterMs(baseDuration, 0.4);
|
|
3645
|
-
|
|
3571
|
+
logger6.start("warmUpBrowsing", `duration=${durationMs}ms`);
|
|
3646
3572
|
const startTime = Date.now();
|
|
3647
3573
|
const viewportSize = page.viewportSize() || { width: 1920, height: 1080 };
|
|
3648
3574
|
try {
|
|
@@ -3661,9 +3587,9 @@ var Humanize = {
|
|
|
3661
3587
|
await delay2(this.jitterMs(800, 0.5));
|
|
3662
3588
|
}
|
|
3663
3589
|
}
|
|
3664
|
-
|
|
3590
|
+
logger6.success("warmUpBrowsing");
|
|
3665
3591
|
} catch (error) {
|
|
3666
|
-
|
|
3592
|
+
logger6.fail("warmUpBrowsing", error);
|
|
3667
3593
|
throw error;
|
|
3668
3594
|
}
|
|
3669
3595
|
},
|
|
@@ -3677,7 +3603,7 @@ var Humanize = {
|
|
|
3677
3603
|
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
3678
3604
|
const steps = Math.max(3, baseSteps + Math.floor(Math.random() * 3) - 1);
|
|
3679
3605
|
const actualDistance = this.jitterMs(distance, 0.15);
|
|
3680
|
-
|
|
3606
|
+
logger6.start("naturalScroll", `dir=${direction}, dist=${actualDistance}, steps=${steps}`);
|
|
3681
3607
|
const sign = direction === "down" ? 1 : -1;
|
|
3682
3608
|
const stepDistance = actualDistance / steps;
|
|
3683
3609
|
try {
|
|
@@ -3689,9 +3615,9 @@ var Humanize = {
|
|
|
3689
3615
|
const baseDelay = 60 + i * 25;
|
|
3690
3616
|
await delay2(this.jitterMs(baseDelay, 0.3));
|
|
3691
3617
|
}
|
|
3692
|
-
|
|
3618
|
+
logger6.success("naturalScroll");
|
|
3693
3619
|
} catch (error) {
|
|
3694
|
-
|
|
3620
|
+
logger6.fail("naturalScroll", error);
|
|
3695
3621
|
throw error;
|
|
3696
3622
|
}
|
|
3697
3623
|
}
|
|
@@ -3720,7 +3646,7 @@ var resolveElement = async (page, target, { throwOnMissing = true } = {}) => {
|
|
|
3720
3646
|
var waitJitter = (base, jitterPercent = 0.3) => delay3(jitterMs(base, jitterPercent));
|
|
3721
3647
|
|
|
3722
3648
|
// src/internals/humanize/mobile.js
|
|
3723
|
-
var
|
|
3649
|
+
var logger7 = createInternalLogger("Humanize.Mobile");
|
|
3724
3650
|
var initializedPages = /* @__PURE__ */ new WeakSet();
|
|
3725
3651
|
var DEFAULT_TAP_TIMEOUT_MS = 2500;
|
|
3726
3652
|
var DEFAULT_MOUSE_TAP_FALLBACK_TIMEOUT_MS = 1200;
|
|
@@ -4090,7 +4016,7 @@ var restoreWindowFromSnapshot = async (page, before, after) => {
|
|
|
4090
4016
|
return;
|
|
4091
4017
|
}
|
|
4092
4018
|
await page.evaluate(
|
|
4093
|
-
(
|
|
4019
|
+
(state) => window.scrollTo(state.x, state.y),
|
|
4094
4020
|
{ x: Number(before.scrollX || 0), y: Number(before.scrollY || 0) }
|
|
4095
4021
|
).catch(() => {
|
|
4096
4022
|
});
|
|
@@ -4177,7 +4103,7 @@ var dispatchTouchSwipe = async (page, deltaY, options = {}) => {
|
|
|
4177
4103
|
}
|
|
4178
4104
|
return true;
|
|
4179
4105
|
} catch (error) {
|
|
4180
|
-
|
|
4106
|
+
logger7.debug(`touch swipe fallback: ${error?.message || error}`);
|
|
4181
4107
|
try {
|
|
4182
4108
|
await page.evaluate((amount) => window.scrollBy(0, amount), deltaY);
|
|
4183
4109
|
await waitJitter(120, 0.35);
|
|
@@ -4211,7 +4137,7 @@ var tapPoint = async (page, point, options = {}) => {
|
|
|
4211
4137
|
);
|
|
4212
4138
|
return { method: "touchscreen" };
|
|
4213
4139
|
} catch (error) {
|
|
4214
|
-
|
|
4140
|
+
logger7.warn(`tapPoint | touchscreen.tap \u5931\u8D25\u6216\u8D85\u65F6\uFF0C\u5C1D\u8BD5\u9F20\u6807\u515C\u5E95: ${error?.message || error}`);
|
|
4215
4141
|
if (!allowMouseFallback) throw error;
|
|
4216
4142
|
}
|
|
4217
4143
|
}
|
|
@@ -4227,10 +4153,10 @@ var MobileHumanize = {
|
|
|
4227
4153
|
async initializeCursor(page) {
|
|
4228
4154
|
if (initializedPages.has(page)) return;
|
|
4229
4155
|
initializedPages.add(page);
|
|
4230
|
-
|
|
4156
|
+
logger7.debug("initializeCursor: mobile mode uses touch gestures, cursor init skipped");
|
|
4231
4157
|
},
|
|
4232
4158
|
async humanMove(page, target) {
|
|
4233
|
-
|
|
4159
|
+
logger7.debug(`humanMove: mobile no-op target=${typeof target === "string" ? target : "element/coords"}`);
|
|
4234
4160
|
if (typeof target === "string" || target && typeof target.boundingBox === "function") {
|
|
4235
4161
|
const element = await resolveElement(page, target, { throwOnMissing: false });
|
|
4236
4162
|
if (!element) {
|
|
@@ -4249,10 +4175,10 @@ var MobileHumanize = {
|
|
|
4249
4175
|
throwOnMissing = false
|
|
4250
4176
|
} = options;
|
|
4251
4177
|
const targetDesc = describeTarget(target);
|
|
4252
|
-
|
|
4178
|
+
logger7.start("humanScroll", `target=${targetDesc}`);
|
|
4253
4179
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4254
4180
|
if (!element) {
|
|
4255
|
-
|
|
4181
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u672A\u627E\u5230: ${targetDesc}`);
|
|
4256
4182
|
return { element: null, didScroll: false, restore: null };
|
|
4257
4183
|
}
|
|
4258
4184
|
const startTime = Date.now();
|
|
@@ -4261,42 +4187,42 @@ var MobileHumanize = {
|
|
|
4261
4187
|
const status = await checkElementVisibility(element);
|
|
4262
4188
|
if (status.code === "VISIBLE") {
|
|
4263
4189
|
if (status.isFixed) {
|
|
4264
|
-
|
|
4190
|
+
logger7.info("humanScroll | fixed/sticky \u5BB9\u5668\u5185\uFF0C\u8DF3\u8FC7\u6EDA\u52A8");
|
|
4265
4191
|
} else {
|
|
4266
|
-
|
|
4192
|
+
logger7.debug("humanScroll | \u5143\u7D20\u53EF\u89C1\u4E14\u65E0\u906E\u6321");
|
|
4267
4193
|
}
|
|
4268
|
-
|
|
4194
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4269
4195
|
return { element, didScroll, restore: null };
|
|
4270
4196
|
}
|
|
4271
4197
|
if (status.code === "ZERO_DIMENSIONS" || status.code === "NOT_INTERACTABLE") {
|
|
4272
|
-
|
|
4198
|
+
logger7.warn(`humanScroll | \u5143\u7D20\u4E0D\u53EF\u6EDA\u52A8\u81F3\u53EF\u70B9\u51FB\u72B6\u6001: ${status.reason || status.code}`);
|
|
4273
4199
|
return { element, didScroll, restore: null };
|
|
4274
4200
|
}
|
|
4275
4201
|
const scrollRect = await getScrollableRect(element);
|
|
4276
4202
|
if (!scrollRect && status.isFixed && status.code === "OUT_OF_VIEWPORT") {
|
|
4277
|
-
|
|
4203
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u4E0D\u5728\u89C6\u53E3\u5185\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (direction=${status.direction || "unknown"})`);
|
|
4278
4204
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4279
4205
|
}
|
|
4280
4206
|
if (!scrollRect && status.isFixed && status.code === "OBSTRUCTED") {
|
|
4281
|
-
|
|
4207
|
+
logger7.warn(`humanScroll | fixed/sticky \u76EE\u6807\u88AB\u906E\u6321\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u89E3\u9664 (${status.obstruction?.tag || "unknown"})`);
|
|
4282
4208
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4283
4209
|
}
|
|
4284
4210
|
if (scrollRect && status.code === "OBSTRUCTED" && status.obstruction?.isFixed) {
|
|
4285
4211
|
const moved = await scrollAwayFromObstruction(element, status);
|
|
4286
4212
|
if (moved.moved) {
|
|
4287
|
-
|
|
4213
|
+
logger7.debug(`humanScroll | sticky/fixed \u906E\u6321\u8865\u507F\u6EDA\u52A8 top=${Math.round(moved.scrollTop || 0)}`);
|
|
4288
4214
|
await waitJitter(90, 0.3);
|
|
4289
4215
|
didScroll = true;
|
|
4290
4216
|
continue;
|
|
4291
4217
|
}
|
|
4292
4218
|
}
|
|
4293
4219
|
if (Date.now() - startTime > maxDurationMs) {
|
|
4294
|
-
|
|
4220
|
+
logger7.warn(`humanScroll | mobile timeout (${maxDurationMs}ms, status=${status.code}, direction=${status.direction || "unknown"}, fixed=${Boolean(status.isFixed)})`);
|
|
4295
4221
|
return { element, didScroll, restore: null };
|
|
4296
4222
|
}
|
|
4297
4223
|
const stepMin = scrollRect ? Math.min(minStep, Math.max(60, scrollRect.height * 0.4)) : minStep;
|
|
4298
4224
|
const stepMax = scrollRect ? Math.min(maxStep, Math.max(stepMin + 40, scrollRect.height * 0.8)) : maxStep;
|
|
4299
|
-
|
|
4225
|
+
logger7.debug(`humanScroll | \u6B65\u9AA4 ${i + 1}/${maxSteps}: ${status.reason || status.code} ${status.direction ? `(${status.direction})` : ""}`);
|
|
4300
4226
|
const distance = stepMin + Math.random() * Math.max(1, stepMax - stepMin);
|
|
4301
4227
|
let deltaY = status.direction === "up" ? -distance : distance;
|
|
4302
4228
|
if (status.code === "OBSTRUCTED") {
|
|
@@ -4336,8 +4262,8 @@ var MobileHumanize = {
|
|
|
4336
4262
|
if (scrollRect && beforeWindowState) {
|
|
4337
4263
|
const afterWindowState = await page.evaluate(() => ({ x: window.scrollX, y: window.scrollY }));
|
|
4338
4264
|
if (Math.abs(afterWindowState.x - beforeWindowState.x) > 2 || Math.abs(afterWindowState.y - beforeWindowState.y) > 2) {
|
|
4339
|
-
await page.evaluate((
|
|
4340
|
-
|
|
4265
|
+
await page.evaluate((state) => window.scrollTo(state.x, state.y), beforeWindowState);
|
|
4266
|
+
logger7.debug(`humanScroll | \u7A97\u53E3\u6EDA\u52A8\u56DE\u6536 from=${Math.round(afterWindowState.y)} to=${Math.round(beforeWindowState.y)}`);
|
|
4341
4267
|
}
|
|
4342
4268
|
}
|
|
4343
4269
|
let afterElementSnapshot = null;
|
|
@@ -4351,7 +4277,7 @@ var MobileHumanize = {
|
|
|
4351
4277
|
const afterSnapshot = await readAfterElementSnapshot();
|
|
4352
4278
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4353
4279
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4354
|
-
|
|
4280
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u9875\u9762\u6EDA\u52A8\u79FB\u52A8\uFF0C\u9875\u9762\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4355
4281
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4356
4282
|
}
|
|
4357
4283
|
}
|
|
@@ -4383,12 +4309,12 @@ var MobileHumanize = {
|
|
|
4383
4309
|
const moved = beforeState.kind !== afterState.kind || Math.abs(topDelta) > 2 || Math.abs(leftDelta) > 2;
|
|
4384
4310
|
if (!moved) {
|
|
4385
4311
|
const fallback = await scrollScrollableAncestor(element, deltaY);
|
|
4386
|
-
|
|
4312
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u65E0\u6548\uFF0C\u76F4\u63A5\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4387
4313
|
} else if (beforeState.kind === afterState.kind && Math.abs(expectedDelta) > 24 && Math.sign(topDelta || expectedDelta) === Math.sign(expectedDelta) && Math.abs(topDelta) < Math.min(Math.abs(expectedDelta) * 0.45, 96)) {
|
|
4388
4314
|
const residualDelta = expectedDelta - topDelta;
|
|
4389
4315
|
if (Math.sign(residualDelta) === Math.sign(expectedDelta) && Math.abs(residualDelta) > 24) {
|
|
4390
4316
|
const fallback = await scrollScrollableAncestor(element, residualDelta);
|
|
4391
|
-
|
|
4317
|
+
logger7.debug(`humanScroll | \u5BB9\u5668\u89E6\u6478\u8DDD\u79BB\u4E0D\u8DB3\uFF0C\u8865\u507F\u6EDA\u52A8 fallback=${fallback.scroller ? "ancestor" : "window"} top=${Math.round(fallback.scrollTop || 0)}`);
|
|
4392
4318
|
}
|
|
4393
4319
|
}
|
|
4394
4320
|
}
|
|
@@ -4396,7 +4322,7 @@ var MobileHumanize = {
|
|
|
4396
4322
|
const afterSnapshot = await getElementViewportSnapshot(element).catch(() => null);
|
|
4397
4323
|
if (isTargetImmobileAfterScroll(beforeElementSnapshot, afterSnapshot)) {
|
|
4398
4324
|
await restoreWindowFromSnapshot(page, beforeElementSnapshot, afterSnapshot);
|
|
4399
|
-
|
|
4325
|
+
logger7.warn(`humanScroll | \u76EE\u6807\u4E0D\u968F\u6EDA\u52A8\u5BB9\u5668\u79FB\u52A8\uFF0C\u6EDA\u52A8\u65E0\u6CD5\u6539\u53D8\u5176\u4F4D\u7F6E (status=${status.code}, direction=${status.direction || "unknown"})`);
|
|
4400
4326
|
return { element, didScroll, restore: null, unscrollable: true };
|
|
4401
4327
|
}
|
|
4402
4328
|
}
|
|
@@ -4407,14 +4333,14 @@ var MobileHumanize = {
|
|
|
4407
4333
|
await waitJitter(80, 0.3);
|
|
4408
4334
|
const finalStatus = await checkElementVisibility(element);
|
|
4409
4335
|
if (finalStatus.code === "VISIBLE") {
|
|
4410
|
-
|
|
4411
|
-
|
|
4336
|
+
logger7.info("humanScroll | \u539F\u751F scrollIntoViewIfNeeded \u515C\u5E95\u6210\u529F");
|
|
4337
|
+
logger7.success("humanScroll", didScroll ? "\u5DF2\u6EDA\u52A8" : "\u65E0\u9700\u6EDA\u52A8");
|
|
4412
4338
|
return { element, didScroll: true, restore: null };
|
|
4413
4339
|
}
|
|
4414
4340
|
} catch (fallbackError) {
|
|
4415
|
-
|
|
4341
|
+
logger7.debug(`humanScroll | native fallback failed: ${fallbackError?.message || fallbackError}`);
|
|
4416
4342
|
}
|
|
4417
|
-
|
|
4343
|
+
logger7.warn(`humanScroll | \u5728 ${maxSteps} \u6B65\u540E\u65E0\u6CD5\u786E\u4FDD\u53EF\u89C1\u6027`);
|
|
4418
4344
|
return { element, didScroll, restore: null };
|
|
4419
4345
|
},
|
|
4420
4346
|
async humanClick(page, target, options = {}) {
|
|
@@ -4429,7 +4355,7 @@ var MobileHumanize = {
|
|
|
4429
4355
|
fallbackDomClickOnTapError = true
|
|
4430
4356
|
} = options;
|
|
4431
4357
|
const targetDesc = describeTarget(target);
|
|
4432
|
-
|
|
4358
|
+
logger7.start("humanClick", `target=${targetDesc}`);
|
|
4433
4359
|
try {
|
|
4434
4360
|
if (target == null) {
|
|
4435
4361
|
const viewport = resolveViewport(page);
|
|
@@ -4441,12 +4367,12 @@ var MobileHumanize = {
|
|
|
4441
4367
|
timeoutMs: tapTimeoutMs,
|
|
4442
4368
|
mouseFallbackTimeoutMs
|
|
4443
4369
|
});
|
|
4444
|
-
|
|
4370
|
+
logger7.success("humanClick", "Tapped current position");
|
|
4445
4371
|
return true;
|
|
4446
4372
|
}
|
|
4447
4373
|
const element = await resolveElement(page, target, { throwOnMissing });
|
|
4448
4374
|
if (!element) {
|
|
4449
|
-
|
|
4375
|
+
logger7.warn(`humanClick: \u5143\u7D20\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u70B9\u51FB ${targetDesc}`);
|
|
4450
4376
|
return false;
|
|
4451
4377
|
}
|
|
4452
4378
|
const scrollResult = scrollIfNeeded ? await MobileHumanize.humanScroll(page, element, { throwOnMissing }) : null;
|
|
@@ -4470,19 +4396,19 @@ var MobileHumanize = {
|
|
|
4470
4396
|
).catch(() => null);
|
|
4471
4397
|
}
|
|
4472
4398
|
if (fallback?.activated) {
|
|
4473
|
-
|
|
4399
|
+
logger7.warn(`humanClick: \u4E0D\u53EF\u6EDA\u52A8\u76EE\u6807\u4E0D\u53EF\u7269\u7406\u70B9\u51FB\uFF0C\u5DF2\u7528 ${fallback.method} \u6FC0\u6D3B`);
|
|
4474
4400
|
return true;
|
|
4475
4401
|
}
|
|
4476
4402
|
}
|
|
4477
4403
|
const message = `\u5143\u7D20\u4E0D\u53EF\u70B9\u51FB: ${status.reason || status.code}`;
|
|
4478
4404
|
if (throwOnMissing) throw new Error(message);
|
|
4479
|
-
|
|
4405
|
+
logger7.warn(`humanClick: ${message}\uFF0C\u8DF3\u8FC7\u70B9\u51FB`);
|
|
4480
4406
|
return false;
|
|
4481
4407
|
}
|
|
4482
4408
|
const box = await element.boundingBox();
|
|
4483
4409
|
if (!box) {
|
|
4484
4410
|
if (throwOnMissing) throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5143\u7D20\u4F4D\u7F6E");
|
|
4485
|
-
|
|
4411
|
+
logger7.warn("humanClick: \u65E0\u6CD5\u83B7\u53D6\u4F4D\u7F6E\uFF0C\u8DF3\u8FC7\u70B9\u51FB");
|
|
4486
4412
|
return false;
|
|
4487
4413
|
}
|
|
4488
4414
|
await waitJitter(reactionDelay, 0.45);
|
|
@@ -4503,13 +4429,13 @@ var MobileHumanize = {
|
|
|
4503
4429
|
"activation fallback"
|
|
4504
4430
|
).catch(() => null);
|
|
4505
4431
|
if (!fallback?.activated) throw tapError;
|
|
4506
|
-
|
|
4432
|
+
logger7.warn(`humanClick: tap \u5931\u8D25\u540E\u5DF2\u7528 ${fallback.method} \u515C\u5E95: ${tapError?.message || tapError}`);
|
|
4507
4433
|
}
|
|
4508
4434
|
await waitJitter(120, 0.35);
|
|
4509
|
-
|
|
4435
|
+
logger7.success("humanClick");
|
|
4510
4436
|
return true;
|
|
4511
4437
|
} catch (error) {
|
|
4512
|
-
|
|
4438
|
+
logger7.fail("humanClick", error);
|
|
4513
4439
|
throw error;
|
|
4514
4440
|
}
|
|
4515
4441
|
},
|
|
@@ -4562,7 +4488,7 @@ var MobileHumanize = {
|
|
|
4562
4488
|
keyboardOptions = {}
|
|
4563
4489
|
} = pressOptions || {};
|
|
4564
4490
|
const targetDesc = hasTarget ? describeTarget(targetOrKey) : "current focus";
|
|
4565
|
-
|
|
4491
|
+
logger7.start("humanPress", `key=${key}, target=${targetDesc}`);
|
|
4566
4492
|
try {
|
|
4567
4493
|
if (hasTarget) {
|
|
4568
4494
|
await MobileHumanize.humanClick(page, targetOrKey, {
|
|
@@ -4576,10 +4502,10 @@ var MobileHumanize = {
|
|
|
4576
4502
|
...keyboardOptions,
|
|
4577
4503
|
delay: jitterMs(holdDelay, 0.5)
|
|
4578
4504
|
});
|
|
4579
|
-
|
|
4505
|
+
logger7.success("humanPress");
|
|
4580
4506
|
return true;
|
|
4581
4507
|
} catch (error) {
|
|
4582
|
-
|
|
4508
|
+
logger7.fail("humanPress", error);
|
|
4583
4509
|
throw error;
|
|
4584
4510
|
}
|
|
4585
4511
|
},
|
|
@@ -4646,7 +4572,7 @@ var MobileHumanize = {
|
|
|
4646
4572
|
}
|
|
4647
4573
|
};
|
|
4648
4574
|
|
|
4649
|
-
// src/
|
|
4575
|
+
// src/humanize.js
|
|
4650
4576
|
var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4651
4577
|
var resolveDelegate = (page) => {
|
|
4652
4578
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
@@ -4655,7 +4581,7 @@ var callDelegate = (method, page, args) => {
|
|
|
4655
4581
|
const delegate = resolveDelegate(page);
|
|
4656
4582
|
return delegate[method](page, ...args);
|
|
4657
4583
|
};
|
|
4658
|
-
var
|
|
4584
|
+
var Humanize2 = {
|
|
4659
4585
|
jitterMs(base, jitterPercent = 0.3) {
|
|
4660
4586
|
return Humanize.jitterMs(base, jitterPercent);
|
|
4661
4587
|
},
|
|
@@ -4701,169 +4627,7 @@ var DefaultHumanize = {
|
|
|
4701
4627
|
}
|
|
4702
4628
|
};
|
|
4703
4629
|
|
|
4704
|
-
// src/
|
|
4705
|
-
import delay4 from "delay";
|
|
4706
|
-
var resolveDeviceFromPage3 = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
4707
|
-
var isMobilePage = (page) => resolveDeviceFromPage3(page) === Device.Mobile;
|
|
4708
|
-
var isPageLike2 = (value) => value && typeof value === "object" && typeof value.evaluate === "function";
|
|
4709
|
-
var isPoint2 = (value) => value && typeof value === "object" && Number.isFinite(Number(value.x)) && Number.isFinite(Number(value.y));
|
|
4710
|
-
var resolveTarget = (page, target) => typeof target === "string" ? page.locator(target).first() : target;
|
|
4711
|
-
var sleep = (base, jitter = 0.3) => delay4(jitterMs(base, jitter));
|
|
4712
|
-
var FORCE_OPTIONS = Object.freeze({ force: true });
|
|
4713
|
-
var DesktopCloakHumanize = {
|
|
4714
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4715
|
-
return jitterMs(base, jitterPercent);
|
|
4716
|
-
},
|
|
4717
|
-
async initializeCursor(page) {
|
|
4718
|
-
return Boolean(page);
|
|
4719
|
-
},
|
|
4720
|
-
async humanMove(page, target) {
|
|
4721
|
-
if (target == null) return false;
|
|
4722
|
-
if (isPoint2(target)) {
|
|
4723
|
-
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4724
|
-
return true;
|
|
4725
|
-
}
|
|
4726
|
-
await resolveTarget(page, target).hover(FORCE_OPTIONS);
|
|
4727
|
-
return true;
|
|
4728
|
-
},
|
|
4729
|
-
async humanScroll(page, target) {
|
|
4730
|
-
const element = resolveTarget(page, target);
|
|
4731
|
-
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4732
|
-
await element.scrollIntoViewIfNeeded?.();
|
|
4733
|
-
return { element, didScroll: true, restore: null };
|
|
4734
|
-
},
|
|
4735
|
-
async humanClick(page, target) {
|
|
4736
|
-
if (target == null) {
|
|
4737
|
-
await page.mouse.click(0, 0);
|
|
4738
|
-
return true;
|
|
4739
|
-
}
|
|
4740
|
-
if (isPoint2(target)) {
|
|
4741
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4742
|
-
return true;
|
|
4743
|
-
}
|
|
4744
|
-
if (typeof target === "string") {
|
|
4745
|
-
await page.click(target, FORCE_OPTIONS);
|
|
4746
|
-
return true;
|
|
4747
|
-
}
|
|
4748
|
-
await target.click(FORCE_OPTIONS);
|
|
4749
|
-
return true;
|
|
4750
|
-
},
|
|
4751
|
-
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4752
|
-
await sleep(baseMs, jitterPercent);
|
|
4753
|
-
},
|
|
4754
|
-
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4755
|
-
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4756
|
-
const startedAt = Date.now();
|
|
4757
|
-
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4758
|
-
while (Date.now() - startedAt < durationMs) {
|
|
4759
|
-
await page.mouse.move(
|
|
4760
|
-
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4761
|
-
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4762
|
-
);
|
|
4763
|
-
await sleep(300, 0.5);
|
|
4764
|
-
}
|
|
4765
|
-
},
|
|
4766
|
-
async humanType(page, selector, text) {
|
|
4767
|
-
const target = resolveTarget(page, selector);
|
|
4768
|
-
await target.click(FORCE_OPTIONS);
|
|
4769
|
-
await page.keyboard.type(text);
|
|
4770
|
-
},
|
|
4771
|
-
async humanPress(page, targetOrKey, maybeKey) {
|
|
4772
|
-
if (typeof maybeKey !== "string") {
|
|
4773
|
-
await page.keyboard.press(targetOrKey);
|
|
4774
|
-
return true;
|
|
4775
|
-
}
|
|
4776
|
-
await resolveTarget(page, targetOrKey).click(FORCE_OPTIONS);
|
|
4777
|
-
await page.keyboard.press(maybeKey);
|
|
4778
|
-
return true;
|
|
4779
|
-
},
|
|
4780
|
-
async humanClear(page, selector) {
|
|
4781
|
-
if (typeof selector === "string") {
|
|
4782
|
-
await page.fill(selector, "", FORCE_OPTIONS);
|
|
4783
|
-
return;
|
|
4784
|
-
}
|
|
4785
|
-
await selector.fill("", FORCE_OPTIONS);
|
|
4786
|
-
},
|
|
4787
|
-
async warmUpBrowsing(page, baseDuration = 3500) {
|
|
4788
|
-
await this.simulateGaze(page, Math.min(baseDuration, 900));
|
|
4789
|
-
},
|
|
4790
|
-
async naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4791
|
-
const steps = Math.max(1, Number(baseSteps) || 1);
|
|
4792
|
-
const delta = (Number(distance) || 0) / steps * (direction === "down" ? 1 : -1);
|
|
4793
|
-
for (let index = 0; index < steps; index += 1) {
|
|
4794
|
-
await page.mouse.wheel(0, delta);
|
|
4795
|
-
await sleep(60 + index * 20, 0.3);
|
|
4796
|
-
}
|
|
4797
|
-
}
|
|
4798
|
-
};
|
|
4799
|
-
var resolveDelegate2 = (page) => isMobilePage(page) ? MobileHumanize : DesktopCloakHumanize;
|
|
4800
|
-
var callDelegate2 = (method, page, args) => resolveDelegate2(page)[method](page, ...args);
|
|
4801
|
-
var CloakBrowserHumanize = {
|
|
4802
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4803
|
-
return jitterMs(base, jitterPercent);
|
|
4804
|
-
},
|
|
4805
|
-
initializeCursor(page) {
|
|
4806
|
-
return callDelegate2("initializeCursor", page, []);
|
|
4807
|
-
},
|
|
4808
|
-
humanMove(page, target) {
|
|
4809
|
-
return callDelegate2("humanMove", page, [target]);
|
|
4810
|
-
},
|
|
4811
|
-
humanScroll(page, target, options = {}) {
|
|
4812
|
-
return callDelegate2("humanScroll", page, [target, options]);
|
|
4813
|
-
},
|
|
4814
|
-
humanClick(page, target, options = {}) {
|
|
4815
|
-
return callDelegate2("humanClick", page, [target, options]);
|
|
4816
|
-
},
|
|
4817
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4818
|
-
if (isPageLike2(pageOrBaseMs)) {
|
|
4819
|
-
return resolveDelegate2(pageOrBaseMs).randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4820
|
-
}
|
|
4821
|
-
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4822
|
-
},
|
|
4823
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4824
|
-
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
4825
|
-
},
|
|
4826
|
-
humanType(page, selector, text, options = {}) {
|
|
4827
|
-
return callDelegate2("humanType", page, [selector, text, options]);
|
|
4828
|
-
},
|
|
4829
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4830
|
-
if (typeof maybeKey === "string") {
|
|
4831
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4832
|
-
}
|
|
4833
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4834
|
-
},
|
|
4835
|
-
humanClear(page, selector) {
|
|
4836
|
-
return callDelegate2("humanClear", page, [selector]);
|
|
4837
|
-
},
|
|
4838
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4839
|
-
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
4840
|
-
},
|
|
4841
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4842
|
-
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4843
|
-
}
|
|
4844
|
-
};
|
|
4845
|
-
|
|
4846
|
-
// src/humanize.js
|
|
4847
|
-
var humanizeStrategies = {
|
|
4848
|
-
[Mode.Default]: DefaultHumanize,
|
|
4849
|
-
[Mode.CloakBrowser]: CloakBrowserHumanize
|
|
4850
|
-
};
|
|
4851
|
-
var Humanize2 = createDelegatedFacade("Humanize", humanizeStrategies, [
|
|
4852
|
-
"jitterMs",
|
|
4853
|
-
"initializeCursor",
|
|
4854
|
-
"humanMove",
|
|
4855
|
-
"humanScroll",
|
|
4856
|
-
"humanClick",
|
|
4857
|
-
"randomSleep",
|
|
4858
|
-
"simulateGaze",
|
|
4859
|
-
"humanType",
|
|
4860
|
-
"humanPress",
|
|
4861
|
-
"humanClear",
|
|
4862
|
-
"warmUpBrowsing",
|
|
4863
|
-
"naturalScroll"
|
|
4864
|
-
]);
|
|
4865
|
-
|
|
4866
|
-
// src/internals/launch/default.js
|
|
4630
|
+
// src/launch.js
|
|
4867
4631
|
import { execFileSync } from "node:child_process";
|
|
4868
4632
|
import { FingerprintGenerator } from "fingerprint-generator";
|
|
4869
4633
|
import { FingerprintInjector } from "fingerprint-injector";
|
|
@@ -4948,8 +4712,8 @@ var ByPass = {
|
|
|
4948
4712
|
resolveRouteByProxy
|
|
4949
4713
|
};
|
|
4950
4714
|
|
|
4951
|
-
// src/
|
|
4952
|
-
var
|
|
4715
|
+
// src/launch.js
|
|
4716
|
+
var logger8 = createInternalLogger("Launch");
|
|
4953
4717
|
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
4954
4718
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4955
4719
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
@@ -5001,7 +4765,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
5001
4765
|
});
|
|
5002
4766
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
5003
4767
|
} catch (error) {
|
|
5004
|
-
|
|
4768
|
+
logger8.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
5005
4769
|
}
|
|
5006
4770
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
5007
4771
|
return detectedVersion;
|
|
@@ -5015,7 +4779,7 @@ var resolveCoreDevice = (core = {}) => {
|
|
|
5015
4779
|
};
|
|
5016
4780
|
var buildFingerprintGenerator = ({ locale, browserMajorVersion, device }) => {
|
|
5017
4781
|
return new FingerprintGenerator(
|
|
5018
|
-
|
|
4782
|
+
AntiCheat.getFingerprintGeneratorOptions({
|
|
5019
4783
|
locale,
|
|
5020
4784
|
browserMajorVersion,
|
|
5021
4785
|
device
|
|
@@ -5038,7 +4802,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
5038
4802
|
if (requestedBrowserMajorVersion <= 0) {
|
|
5039
4803
|
throw error;
|
|
5040
4804
|
}
|
|
5041
|
-
|
|
4805
|
+
logger8.warn(
|
|
5042
4806
|
`\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}`
|
|
5043
4807
|
);
|
|
5044
4808
|
}
|
|
@@ -5059,7 +4823,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5059
4823
|
}
|
|
5060
4824
|
let nextState = RuntimeEnv.rememberState(runtimeState);
|
|
5061
4825
|
let browserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
|
|
5062
|
-
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() ||
|
|
4826
|
+
const timezoneId = String(browserProfileCore?.timezone_id || "").trim() || AntiCheat.getBaseConfig().timezoneId;
|
|
5063
4827
|
const locale = DEFAULT_LOCALE;
|
|
5064
4828
|
const currentBrowserMajorVersion = detectBrowserMajorVersion(launcher);
|
|
5065
4829
|
const storedBrowserMajorVersion = Number(browserProfileCore?.browser_major_version || 0);
|
|
@@ -5083,7 +4847,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5083
4847
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5084
4848
|
};
|
|
5085
4849
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5086
|
-
|
|
4850
|
+
logger8.info(
|
|
5087
4851
|
`\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}`
|
|
5088
4852
|
);
|
|
5089
4853
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5138,7 +4902,7 @@ var applyFingerprintPageOptions = (pageOptions = {}, { fingerprintWithHeaders =
|
|
|
5138
4902
|
pageOptions.timezoneId = timezoneId;
|
|
5139
4903
|
}
|
|
5140
4904
|
};
|
|
5141
|
-
var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
4905
|
+
var buildReplayBrowserPoolOptions = (browserProfileCore, modifyPageOptions = null) => {
|
|
5142
4906
|
const fingerprintWithHeaders = browserProfileCore?.fingerprint;
|
|
5143
4907
|
const fingerprint = fingerprintWithHeaders?.fingerprint;
|
|
5144
4908
|
if (!fingerprintWithHeaders || !fingerprint) {
|
|
@@ -5147,13 +4911,16 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5147
4911
|
return {
|
|
5148
4912
|
useFingerprints: false,
|
|
5149
4913
|
prePageCreateHooks: [
|
|
5150
|
-
(
|
|
4914
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5151
4915
|
if (!pageOptions || typeof pageOptions !== "object") return;
|
|
5152
4916
|
applyFingerprintPageOptions(pageOptions, {
|
|
5153
4917
|
fingerprintWithHeaders,
|
|
5154
4918
|
locale: browserProfileCore.locale,
|
|
5155
4919
|
timezoneId: browserProfileCore.timezone_id
|
|
5156
4920
|
});
|
|
4921
|
+
if (modifyPageOptions) {
|
|
4922
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
4923
|
+
}
|
|
5157
4924
|
}
|
|
5158
4925
|
],
|
|
5159
4926
|
postPageCreateHooks: [
|
|
@@ -5168,7 +4935,7 @@ var buildReplayBrowserPoolOptions = (browserProfileCore) => {
|
|
|
5168
4935
|
]
|
|
5169
4936
|
};
|
|
5170
4937
|
};
|
|
5171
|
-
var
|
|
4938
|
+
var Launch = {
|
|
5172
4939
|
getPlaywrightCrawlerOptions(options = {}) {
|
|
5173
4940
|
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
5174
4941
|
const {
|
|
@@ -5179,11 +4946,13 @@ var DefaultLaunch = {
|
|
|
5179
4946
|
debugMode = false,
|
|
5180
4947
|
isRunningOnApify = false,
|
|
5181
4948
|
launcher = null,
|
|
4949
|
+
hooks = {},
|
|
5182
4950
|
preNavigationHooks = [],
|
|
5183
4951
|
postNavigationHooks = [],
|
|
5184
4952
|
runtimeState = null
|
|
5185
4953
|
} = normalizedOptions;
|
|
5186
4954
|
const device = resolveRuntimeDevice(runtimeState);
|
|
4955
|
+
const modifyPageOptions = typeof hooks?.modifyPageOptions === "function" ? hooks.modifyPageOptions : null;
|
|
5187
4956
|
const { byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
5188
4957
|
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
5189
4958
|
const proxyMeter = enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
@@ -5192,11 +4961,11 @@ var DefaultLaunch = {
|
|
|
5192
4961
|
launchProxy.bypass = byPassDomains.join(",");
|
|
5193
4962
|
}
|
|
5194
4963
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5195
|
-
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
4964
|
+
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore, modifyPageOptions);
|
|
5196
4965
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5197
4966
|
const launchOptions = {
|
|
5198
4967
|
args: [
|
|
5199
|
-
...
|
|
4968
|
+
...AntiCheat.getLaunchArgs({ locale: launchLocale }),
|
|
5200
4969
|
...customArgs
|
|
5201
4970
|
],
|
|
5202
4971
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
@@ -5212,18 +4981,18 @@ var DefaultLaunch = {
|
|
|
5212
4981
|
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5213
4982
|
} catch {
|
|
5214
4983
|
}
|
|
5215
|
-
|
|
4984
|
+
logger8.info(
|
|
5216
4985
|
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5217
4986
|
);
|
|
5218
|
-
|
|
4987
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5219
4988
|
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5220
|
-
|
|
5221
|
-
|
|
4989
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4990
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5222
4991
|
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5223
|
-
|
|
5224
|
-
|
|
4992
|
+
logger8.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4993
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5225
4994
|
} else if (enableByPassLogger) {
|
|
5226
|
-
|
|
4995
|
+
logger8.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5227
4996
|
}
|
|
5228
4997
|
const onPageCreated = (page) => {
|
|
5229
4998
|
const recommendedGotoOptions = {
|
|
@@ -5245,7 +5014,7 @@ var DefaultLaunch = {
|
|
|
5245
5014
|
}
|
|
5246
5015
|
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5247
5016
|
if (!matched || !matched.rule) return;
|
|
5248
|
-
|
|
5017
|
+
logger8.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
5249
5018
|
};
|
|
5250
5019
|
page.on("request", requestHandler);
|
|
5251
5020
|
return recommendedGotoOptions;
|
|
@@ -5264,20 +5033,23 @@ var DefaultLaunch = {
|
|
|
5264
5033
|
browserPoolOptions: replayBrowserPoolOptions || {
|
|
5265
5034
|
useFingerprints: true,
|
|
5266
5035
|
fingerprintOptions: {
|
|
5267
|
-
fingerprintGeneratorOptions:
|
|
5036
|
+
fingerprintGeneratorOptions: AntiCheat.getFingerprintGeneratorOptions({
|
|
5268
5037
|
locale: launchLocale,
|
|
5269
5038
|
device
|
|
5270
5039
|
})
|
|
5271
5040
|
},
|
|
5272
5041
|
prePageCreateHooks: [
|
|
5273
|
-
(
|
|
5042
|
+
async (pageId, browserController, pageOptions = {}) => {
|
|
5274
5043
|
const fingerprintWithHeaders = browserController?.launchContext?.fingerprint;
|
|
5275
|
-
const timezoneId =
|
|
5044
|
+
const timezoneId = AntiCheat.getBaseConfig().timezoneId;
|
|
5276
5045
|
applyFingerprintPageOptions(pageOptions, {
|
|
5277
5046
|
fingerprintWithHeaders,
|
|
5278
5047
|
locale: launchLocale,
|
|
5279
5048
|
timezoneId
|
|
5280
5049
|
});
|
|
5050
|
+
if (modifyPageOptions) {
|
|
5051
|
+
await modifyPageOptions(pageOptions, { pageId, browserController });
|
|
5052
|
+
}
|
|
5281
5053
|
}
|
|
5282
5054
|
]
|
|
5283
5055
|
},
|
|
@@ -5299,262 +5071,6 @@ var DefaultLaunch = {
|
|
|
5299
5071
|
}
|
|
5300
5072
|
};
|
|
5301
5073
|
|
|
5302
|
-
// src/internals/launch/cloakbrowser.js
|
|
5303
|
-
import { execFile } from "node:child_process";
|
|
5304
|
-
import { promisify } from "node:util";
|
|
5305
|
-
var logger8 = createInternalLogger("CloakBrowser");
|
|
5306
|
-
var execFileAsync = promisify(execFile);
|
|
5307
|
-
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5308
|
-
maxConcurrency: 1,
|
|
5309
|
-
maxRequestRetries: 0,
|
|
5310
|
-
requestHandlerTimeoutSecs: 240,
|
|
5311
|
-
navigationTimeoutSecs: 120
|
|
5312
|
-
});
|
|
5313
|
-
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5314
|
-
humanize: true
|
|
5315
|
-
});
|
|
5316
|
-
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5317
|
-
waitUntil: "commit"
|
|
5318
|
-
});
|
|
5319
|
-
var cachedCloakBrowserModulePromise = null;
|
|
5320
|
-
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5321
|
-
var loadCloakBrowserModule = async () => {
|
|
5322
|
-
if (!cachedCloakBrowserModulePromise) {
|
|
5323
|
-
cachedCloakBrowserModulePromise = import("cloakbrowser").catch((error) => {
|
|
5324
|
-
cachedCloakBrowserModulePromise = null;
|
|
5325
|
-
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", {
|
|
5326
|
-
cause: error
|
|
5327
|
-
});
|
|
5328
|
-
});
|
|
5329
|
-
}
|
|
5330
|
-
return cachedCloakBrowserModulePromise;
|
|
5331
|
-
};
|
|
5332
|
-
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5333
|
-
const { buildLaunchOptions } = await loadCloakBrowserModule();
|
|
5334
|
-
return await buildLaunchOptions(normalizeObject(options));
|
|
5335
|
-
};
|
|
5336
|
-
var normalizeObject = (value) => {
|
|
5337
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5338
|
-
return {};
|
|
5339
|
-
}
|
|
5340
|
-
return value;
|
|
5341
|
-
};
|
|
5342
|
-
var normalizeStringArray = (value) => {
|
|
5343
|
-
if (!Array.isArray(value)) {
|
|
5344
|
-
return [];
|
|
5345
|
-
}
|
|
5346
|
-
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5347
|
-
};
|
|
5348
|
-
var resolveCloakBrowserProxy = (proxyConfiguration = {}) => {
|
|
5349
|
-
const config = normalizeObject(proxyConfiguration);
|
|
5350
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5351
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5352
|
-
if (!enableProxy || !proxyUrl) {
|
|
5353
|
-
return null;
|
|
5354
|
-
}
|
|
5355
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5356
|
-
if (byPassDomains.length === 0) {
|
|
5357
|
-
return proxyUrl;
|
|
5358
|
-
}
|
|
5359
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5360
|
-
return {
|
|
5361
|
-
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5362
|
-
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5363
|
-
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5364
|
-
bypass: byPassDomains.join(",")
|
|
5365
|
-
};
|
|
5366
|
-
};
|
|
5367
|
-
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5368
|
-
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5369
|
-
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5370
|
-
};
|
|
5371
|
-
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5372
|
-
const normalizedRecommendedGotoOptions = normalizeObject(recommendedGotoOptions);
|
|
5373
|
-
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5374
|
-
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5375
|
-
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5376
|
-
if (gotoOptions[key] == null) {
|
|
5377
|
-
gotoOptions[key] = value;
|
|
5378
|
-
}
|
|
5379
|
-
}
|
|
5380
|
-
};
|
|
5381
|
-
};
|
|
5382
|
-
var attachCloakBrowserHumanizeHook = ({
|
|
5383
|
-
browserPoolOptions = {},
|
|
5384
|
-
activeBrowsers,
|
|
5385
|
-
patchedBrowsers,
|
|
5386
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5387
|
-
} = {}) => {
|
|
5388
|
-
const normalizedBrowserPoolOptions = normalizeObject(browserPoolOptions);
|
|
5389
|
-
const shouldHumanize = humanizeOptions !== false;
|
|
5390
|
-
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5391
|
-
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5392
|
-
...normalizeObject(humanizeOptions)
|
|
5393
|
-
} : null;
|
|
5394
|
-
return {
|
|
5395
|
-
...normalizedBrowserPoolOptions,
|
|
5396
|
-
useFingerprints: false,
|
|
5397
|
-
postLaunchHooks: [
|
|
5398
|
-
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5399
|
-
async (_pageId, browserController) => {
|
|
5400
|
-
const browser = browserController?.browser;
|
|
5401
|
-
if (!browser || typeof browser.contexts !== "function") {
|
|
5402
|
-
return;
|
|
5403
|
-
}
|
|
5404
|
-
activeBrowsers.add(browser);
|
|
5405
|
-
if (typeof browser.once === "function") {
|
|
5406
|
-
browser.once("disconnected", () => {
|
|
5407
|
-
activeBrowsers.delete(browser);
|
|
5408
|
-
});
|
|
5409
|
-
}
|
|
5410
|
-
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5411
|
-
return;
|
|
5412
|
-
}
|
|
5413
|
-
const { humanizeBrowser } = await loadCloakBrowserModule();
|
|
5414
|
-
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5415
|
-
patchedBrowsers.add(browser);
|
|
5416
|
-
}
|
|
5417
|
-
]
|
|
5418
|
-
};
|
|
5419
|
-
};
|
|
5420
|
-
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5421
|
-
const browsers = Array.from(activeBrowsers || []);
|
|
5422
|
-
activeBrowsers?.clear?.();
|
|
5423
|
-
await Promise.allSettled(
|
|
5424
|
-
browsers.map(async (browser) => {
|
|
5425
|
-
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5426
|
-
return;
|
|
5427
|
-
}
|
|
5428
|
-
await browser.close().catch(() => {
|
|
5429
|
-
});
|
|
5430
|
-
})
|
|
5431
|
-
);
|
|
5432
|
-
};
|
|
5433
|
-
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5434
|
-
if (!fingerprintArg) {
|
|
5435
|
-
return;
|
|
5436
|
-
}
|
|
5437
|
-
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5438
|
-
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5439
|
-
return;
|
|
5440
|
-
}
|
|
5441
|
-
logger8.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5442
|
-
});
|
|
5443
|
-
};
|
|
5444
|
-
var CloakBrowserLaunch = {
|
|
5445
|
-
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5446
|
-
return resolveCloakBrowserProxy(proxyConfiguration);
|
|
5447
|
-
},
|
|
5448
|
-
extractFingerprintArg(launchOptions = {}) {
|
|
5449
|
-
return extractFingerprintArg(launchOptions);
|
|
5450
|
-
},
|
|
5451
|
-
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5452
|
-
return createStableGotoHook(recommendedGotoOptions);
|
|
5453
|
-
},
|
|
5454
|
-
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5455
|
-
const runtime2 = await CloakBrowserLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5456
|
-
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5457
|
-
cleanup: {
|
|
5458
|
-
enumerable: false,
|
|
5459
|
-
value: runtime2.cleanup
|
|
5460
|
-
},
|
|
5461
|
-
closeActiveBrowsers: {
|
|
5462
|
-
enumerable: false,
|
|
5463
|
-
value: runtime2.closeActiveBrowsers
|
|
5464
|
-
},
|
|
5465
|
-
forceTerminateActiveProcesses: {
|
|
5466
|
-
enumerable: false,
|
|
5467
|
-
value: runtime2.forceTerminateActiveProcesses
|
|
5468
|
-
}
|
|
5469
|
-
});
|
|
5470
|
-
},
|
|
5471
|
-
async buildLaunchOptions(options = {}) {
|
|
5472
|
-
return await buildCloakLaunchOptions(options);
|
|
5473
|
-
},
|
|
5474
|
-
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5475
|
-
const normalizedOptions = normalizeObject(options);
|
|
5476
|
-
const {
|
|
5477
|
-
proxyConfiguration = {},
|
|
5478
|
-
runInHeadfulMode = false,
|
|
5479
|
-
isRunningOnApify = false,
|
|
5480
|
-
launcher = null,
|
|
5481
|
-
cloakOptions = {},
|
|
5482
|
-
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5483
|
-
crawlerBaseOptions = {},
|
|
5484
|
-
browserPoolOptions = {},
|
|
5485
|
-
launchContext = {},
|
|
5486
|
-
preNavigationHooks = [],
|
|
5487
|
-
postNavigationHooks = [],
|
|
5488
|
-
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5489
|
-
} = normalizedOptions;
|
|
5490
|
-
const normalizedCloakOptions = normalizeObject(cloakOptions);
|
|
5491
|
-
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5492
|
-
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5493
|
-
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5494
|
-
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5495
|
-
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakBrowserProxy(proxyConfiguration);
|
|
5496
|
-
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5497
|
-
const mergedCloakOptions = {
|
|
5498
|
-
...normalizedCloakOptions,
|
|
5499
|
-
headless,
|
|
5500
|
-
proxy,
|
|
5501
|
-
args: [...defaultArgs, ...extraArgs]
|
|
5502
|
-
};
|
|
5503
|
-
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5504
|
-
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5505
|
-
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5506
|
-
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5507
|
-
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5508
|
-
const crawlerOptions = {
|
|
5509
|
-
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5510
|
-
...normalizeObject(crawlerBaseOptions),
|
|
5511
|
-
headless,
|
|
5512
|
-
launchContext: {
|
|
5513
|
-
useIncognitoPages: true,
|
|
5514
|
-
...normalizeObject(launchContext),
|
|
5515
|
-
...launcher ? { launcher } : {},
|
|
5516
|
-
launchOptions
|
|
5517
|
-
},
|
|
5518
|
-
browserPoolOptions: attachCloakBrowserHumanizeHook({
|
|
5519
|
-
browserPoolOptions,
|
|
5520
|
-
activeBrowsers,
|
|
5521
|
-
patchedBrowsers,
|
|
5522
|
-
humanizeOptions
|
|
5523
|
-
}),
|
|
5524
|
-
preNavigationHooks: [internalPreNavigationHook, ...normalizedPreNavigationHooks],
|
|
5525
|
-
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5526
|
-
};
|
|
5527
|
-
const closeActiveBrowsers = async () => {
|
|
5528
|
-
await closeTrackedBrowsers(activeBrowsers);
|
|
5529
|
-
};
|
|
5530
|
-
const forceTerminateActiveProcesses = async () => {
|
|
5531
|
-
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5532
|
-
};
|
|
5533
|
-
const cleanup = async () => {
|
|
5534
|
-
await closeActiveBrowsers();
|
|
5535
|
-
await forceTerminateActiveProcesses();
|
|
5536
|
-
};
|
|
5537
|
-
return {
|
|
5538
|
-
headless,
|
|
5539
|
-
launchOptions,
|
|
5540
|
-
fingerprintArg,
|
|
5541
|
-
crawlerOptions,
|
|
5542
|
-
closeActiveBrowsers,
|
|
5543
|
-
forceTerminateActiveProcesses,
|
|
5544
|
-
cleanup
|
|
5545
|
-
};
|
|
5546
|
-
}
|
|
5547
|
-
};
|
|
5548
|
-
|
|
5549
|
-
// src/launch.js
|
|
5550
|
-
var launchStrategies = {
|
|
5551
|
-
[Mode.Default]: DefaultLaunch,
|
|
5552
|
-
[Mode.CloakBrowser]: CloakBrowserLaunch
|
|
5553
|
-
};
|
|
5554
|
-
var Launch = createDelegatedFacade("Launch", launchStrategies, [
|
|
5555
|
-
"getPlaywrightCrawlerOptions"
|
|
5556
|
-
]);
|
|
5557
|
-
|
|
5558
5074
|
// src/live-view.js
|
|
5559
5075
|
import express from "express";
|
|
5560
5076
|
import { Actor } from "apify";
|
|
@@ -6642,7 +6158,7 @@ var Mutation = {
|
|
|
6642
6158
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6643
6159
|
const onMutation = options.onMutation;
|
|
6644
6160
|
const pollInterval = 500;
|
|
6645
|
-
const
|
|
6161
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6646
6162
|
setTimeout(resolve, ms);
|
|
6647
6163
|
});
|
|
6648
6164
|
const truncate = (value, max = 800) => {
|
|
@@ -6803,8 +6319,8 @@ var Mutation = {
|
|
|
6803
6319
|
throw e;
|
|
6804
6320
|
}
|
|
6805
6321
|
}
|
|
6806
|
-
let
|
|
6807
|
-
if (!
|
|
6322
|
+
let state = await buildState();
|
|
6323
|
+
if (!state?.hasMatched) {
|
|
6808
6324
|
logger12.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6809
6325
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6810
6326
|
}
|
|
@@ -6812,7 +6328,7 @@ var Mutation = {
|
|
|
6812
6328
|
let stableSince = 0;
|
|
6813
6329
|
let isPaused = false;
|
|
6814
6330
|
let wasPaused = false;
|
|
6815
|
-
let lastSnapshotKey =
|
|
6331
|
+
let lastSnapshotKey = state.snapshotKey;
|
|
6816
6332
|
const applyPauseSignal = (signal) => {
|
|
6817
6333
|
const nextPaused = signal === "__PAUSE__";
|
|
6818
6334
|
if (nextPaused) {
|
|
@@ -6826,15 +6342,15 @@ var Mutation = {
|
|
|
6826
6342
|
};
|
|
6827
6343
|
const initialSignal = await invokeMutationCallback({
|
|
6828
6344
|
mutationCount: 0,
|
|
6829
|
-
html:
|
|
6830
|
-
text:
|
|
6831
|
-
mutationNodes:
|
|
6345
|
+
html: state.html || "",
|
|
6346
|
+
text: state.text || "",
|
|
6347
|
+
mutationNodes: state.mutationNodes || []
|
|
6832
6348
|
});
|
|
6833
6349
|
applyPauseSignal(initialSignal);
|
|
6834
6350
|
const deadline = Date.now() + overallTimeout;
|
|
6835
|
-
let lastState =
|
|
6351
|
+
let lastState = state;
|
|
6836
6352
|
while (Date.now() < deadline) {
|
|
6837
|
-
await
|
|
6353
|
+
await sleep(pollInterval);
|
|
6838
6354
|
lastState = await buildState();
|
|
6839
6355
|
if (!lastState?.hasMatched) {
|
|
6840
6356
|
continue;
|
|
@@ -7922,7 +7438,7 @@ var Logger = {
|
|
|
7922
7438
|
};
|
|
7923
7439
|
|
|
7924
7440
|
// src/share.js
|
|
7925
|
-
import
|
|
7441
|
+
import delay4 from "delay";
|
|
7926
7442
|
|
|
7927
7443
|
// src/internals/watermarkify.js
|
|
7928
7444
|
var DEFAULT_TIMEZONE_OFFSET = 8;
|
|
@@ -8418,10 +7934,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8418
7934
|
</html>
|
|
8419
7935
|
`;
|
|
8420
7936
|
};
|
|
8421
|
-
var
|
|
8422
|
-
return String(value || "default").trim().toLowerCase() === "cloakbrowser" ? "cloakbrowser" : "default";
|
|
8423
|
-
};
|
|
8424
|
-
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
7937
|
+
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
8425
7938
|
if (!page || typeof page.context !== "function") {
|
|
8426
7939
|
logger13.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8427
7940
|
return buffer;
|
|
@@ -8445,35 +7958,15 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8445
7958
|
height: viewportHeight
|
|
8446
7959
|
}).catch(() => {
|
|
8447
7960
|
});
|
|
8448
|
-
|
|
8449
|
-
|
|
8450
|
-
|
|
8451
|
-
|
|
8452
|
-
|
|
8453
|
-
|
|
8454
|
-
|
|
8455
|
-
|
|
8456
|
-
|
|
8457
|
-
await renderPage.goto("about:blank", {
|
|
8458
|
-
waitUntil: "commit"
|
|
8459
|
-
}).catch(() => {
|
|
8460
|
-
});
|
|
8461
|
-
await renderPage.evaluate((html) => {
|
|
8462
|
-
document.open();
|
|
8463
|
-
document.write(html);
|
|
8464
|
-
document.close();
|
|
8465
|
-
}, renderHtml);
|
|
8466
|
-
} else {
|
|
8467
|
-
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
8468
|
-
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8469
|
-
overlaySvg,
|
|
8470
|
-
width: safeWidth,
|
|
8471
|
-
height: safeHeight,
|
|
8472
|
-
imageHeight: safeImageHeight
|
|
8473
|
-
}), {
|
|
8474
|
-
waitUntil: "load"
|
|
8475
|
-
});
|
|
8476
|
-
}
|
|
7961
|
+
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
7962
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
7963
|
+
overlaySvg,
|
|
7964
|
+
width: safeWidth,
|
|
7965
|
+
height: safeHeight,
|
|
7966
|
+
imageHeight: safeImageHeight
|
|
7967
|
+
}), {
|
|
7968
|
+
waitUntil: "load"
|
|
7969
|
+
});
|
|
8477
7970
|
await renderPage.waitForFunction(() => {
|
|
8478
7971
|
const image = document.getElementById("pk-base-image");
|
|
8479
7972
|
return image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0 && image.naturalHeight > 0;
|
|
@@ -9408,7 +8901,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
9408
8901
|
</svg>
|
|
9409
8902
|
`;
|
|
9410
8903
|
};
|
|
9411
|
-
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null
|
|
8904
|
+
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
9412
8905
|
const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
|
|
9413
8906
|
const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
|
|
9414
8907
|
if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
|
|
@@ -9429,7 +8922,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9429
8922
|
if (!overlaySvg) {
|
|
9430
8923
|
return buffer;
|
|
9431
8924
|
}
|
|
9432
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo
|
|
8925
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
9433
8926
|
};
|
|
9434
8927
|
|
|
9435
8928
|
// src/internals/compression.js
|
|
@@ -9993,7 +9486,7 @@ var Share = {
|
|
|
9993
9486
|
);
|
|
9994
9487
|
nextProgressLogTs = now + 5e3;
|
|
9995
9488
|
}
|
|
9996
|
-
await
|
|
9489
|
+
await delay4(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9997
9490
|
}
|
|
9998
9491
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9999
9492
|
logger15.warning(
|
|
@@ -10027,7 +9520,6 @@ var Share = {
|
|
|
10027
9520
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10028
9521
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10029
9522
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10030
|
-
* @param {'default'|'cloakbrowser'} [options.mode] 截图水印合成模式,默认 default
|
|
10031
9523
|
* @returns {Promise<string>} base64 image
|
|
10032
9524
|
*/
|
|
10033
9525
|
async captureScreen(page, options = {}) {
|
|
@@ -10048,9 +9540,7 @@ var Share = {
|
|
|
10048
9540
|
...screenshotWatermarkify,
|
|
10049
9541
|
capturedAt
|
|
10050
9542
|
});
|
|
10051
|
-
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page
|
|
10052
|
-
mode: options.mode === "cloakbrowser" ? "cloakbrowser" : "default"
|
|
10053
|
-
});
|
|
9543
|
+
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page);
|
|
10054
9544
|
}
|
|
10055
9545
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
10056
9546
|
}
|
|
@@ -10058,9 +9548,8 @@ var Share = {
|
|
|
10058
9548
|
|
|
10059
9549
|
// entrys/node.js
|
|
10060
9550
|
Logger.setLogger(crawleeLog);
|
|
10061
|
-
var usePlaywrightToolKit = (
|
|
10062
|
-
|
|
10063
|
-
const toolkit = {
|
|
9551
|
+
var usePlaywrightToolKit = () => {
|
|
9552
|
+
return {
|
|
10064
9553
|
ApifyKit,
|
|
10065
9554
|
AntiCheat,
|
|
10066
9555
|
DeviceInput,
|
|
@@ -10080,7 +9569,6 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10080
9569
|
ByPass,
|
|
10081
9570
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
10082
9571
|
};
|
|
10083
|
-
return toolkit;
|
|
10084
9572
|
};
|
|
10085
9573
|
export {
|
|
10086
9574
|
usePlaywrightToolKit
|