@skrillex1224/playwright-toolkit 3.0.1 → 3.0.3
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/index.cjs +276 -197
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +276 -197
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -360,18 +360,18 @@ var fallbackLog = {
|
|
|
360
360
|
error: (...args) => console.error(...args),
|
|
361
361
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
362
362
|
};
|
|
363
|
-
var resolveLogMethod = (
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
363
|
+
var resolveLogMethod = (logger17, name) => {
|
|
364
|
+
if (logger17 && typeof logger17[name] === "function") {
|
|
365
|
+
return logger17[name].bind(logger17);
|
|
366
366
|
}
|
|
367
|
-
if (name === "warning" &&
|
|
368
|
-
return
|
|
367
|
+
if (name === "warning" && logger17 && typeof logger17.warn === "function") {
|
|
368
|
+
return logger17.warn.bind(logger17);
|
|
369
369
|
}
|
|
370
370
|
return fallbackLog[name];
|
|
371
371
|
};
|
|
372
372
|
var defaultLogger = null;
|
|
373
|
-
var setDefaultLogger = (
|
|
374
|
-
defaultLogger =
|
|
373
|
+
var setDefaultLogger = (logger17) => {
|
|
374
|
+
defaultLogger = logger17;
|
|
375
375
|
};
|
|
376
376
|
var resolveLogger = (explicitLogger) => {
|
|
377
377
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -398,8 +398,8 @@ var colorize = (text, color) => {
|
|
|
398
398
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
399
399
|
const name = prefix ? String(prefix) : "";
|
|
400
400
|
const dispatch = (methodName, icon, message, color) => {
|
|
401
|
-
const
|
|
402
|
-
const logFn = resolveLogMethod(
|
|
401
|
+
const logger17 = resolveLogger(explicitLogger);
|
|
402
|
+
const logFn = resolveLogMethod(logger17, methodName);
|
|
403
403
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
404
404
|
const line = formatLine(name, icon, message);
|
|
405
405
|
const coloredLine = colorize(line, color);
|
|
@@ -4837,9 +4837,107 @@ var ByPass = {
|
|
|
4837
4837
|
resolveRouteByProxy
|
|
4838
4838
|
};
|
|
4839
4839
|
|
|
4840
|
-
// src/internals/launch/
|
|
4840
|
+
// src/internals/launch/traffic.js
|
|
4841
4841
|
var logger7 = createInternalLogger("Launch");
|
|
4842
|
-
var
|
|
4842
|
+
var normalizeObject = (value) => {
|
|
4843
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4844
|
+
return {};
|
|
4845
|
+
}
|
|
4846
|
+
return value;
|
|
4847
|
+
};
|
|
4848
|
+
var parseProxyConfiguration = (proxyConfiguration = {}) => {
|
|
4849
|
+
const config = normalizeObject(proxyConfiguration);
|
|
4850
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4851
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4852
|
+
const byPassDomains = enableProxy && proxyUrl ? ByPass.normalizeByPassDomains(config.by_pass_domains) : [];
|
|
4853
|
+
return {
|
|
4854
|
+
byPassDomains,
|
|
4855
|
+
enableProxy,
|
|
4856
|
+
proxyUrl
|
|
4857
|
+
};
|
|
4858
|
+
};
|
|
4859
|
+
var resolveLaunchTraffic = ({
|
|
4860
|
+
proxyConfiguration = {},
|
|
4861
|
+
debugMode = false,
|
|
4862
|
+
useMeter = true
|
|
4863
|
+
} = {}) => {
|
|
4864
|
+
const { byPassDomains, enableProxy, proxyUrl } = parseProxyConfiguration(proxyConfiguration);
|
|
4865
|
+
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4866
|
+
const proxyMeter = useMeter && enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4867
|
+
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4868
|
+
if (launchProxy && byPassDomains.length > 0) {
|
|
4869
|
+
launchProxy.bypass = byPassDomains.join(",");
|
|
4870
|
+
}
|
|
4871
|
+
return {
|
|
4872
|
+
byPassDomains,
|
|
4873
|
+
byPassRules,
|
|
4874
|
+
enableProxy,
|
|
4875
|
+
proxyUrl,
|
|
4876
|
+
launchProxy
|
|
4877
|
+
};
|
|
4878
|
+
};
|
|
4879
|
+
var logLaunchTraffic = ({
|
|
4880
|
+
byPassDomains = [],
|
|
4881
|
+
debugMode = false,
|
|
4882
|
+
enabled = false,
|
|
4883
|
+
enableProxy = false,
|
|
4884
|
+
explicitProxy = false,
|
|
4885
|
+
launchProxy = null,
|
|
4886
|
+
proxyUrl = ""
|
|
4887
|
+
} = {}) => {
|
|
4888
|
+
if (!enabled) return;
|
|
4889
|
+
if (explicitProxy) {
|
|
4890
|
+
logger7.info("[\u4EE3\u7406\u5DF2\u542F\u7528] \u4F7F\u7528\u663E\u5F0F proxy \u914D\u7F6E\uFF0C\u8DF3\u8FC7 toolkit \u672C\u5730\u6D41\u91CF\u89C2\u6D4B");
|
|
4891
|
+
return;
|
|
4892
|
+
}
|
|
4893
|
+
if (launchProxy) {
|
|
4894
|
+
let upstreamLabel = "";
|
|
4895
|
+
try {
|
|
4896
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
4897
|
+
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
4898
|
+
} catch {
|
|
4899
|
+
}
|
|
4900
|
+
logger7.info(
|
|
4901
|
+
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
4902
|
+
);
|
|
4903
|
+
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
4904
|
+
return;
|
|
4905
|
+
}
|
|
4906
|
+
if (enableProxy) {
|
|
4907
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4908
|
+
} else if (proxyUrl) {
|
|
4909
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4910
|
+
}
|
|
4911
|
+
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
4912
|
+
};
|
|
4913
|
+
var createLaunchTrafficHook = ({
|
|
4914
|
+
byPassDomains = [],
|
|
4915
|
+
byPassRules = [],
|
|
4916
|
+
enabled = false,
|
|
4917
|
+
launchProxy = null
|
|
4918
|
+
} = {}) => {
|
|
4919
|
+
const patchedPages = /* @__PURE__ */ new WeakSet();
|
|
4920
|
+
return (page) => {
|
|
4921
|
+
if (!page || typeof page.on !== "function" || patchedPages.has(page)) {
|
|
4922
|
+
return;
|
|
4923
|
+
}
|
|
4924
|
+
patchedPages.add(page);
|
|
4925
|
+
page.on("request", (req) => {
|
|
4926
|
+
const requestUrl = req.url();
|
|
4927
|
+
const resourceType = req.resourceType();
|
|
4928
|
+
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
4929
|
+
if (launchProxy) {
|
|
4930
|
+
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
4931
|
+
}
|
|
4932
|
+
if (!enabled || byPassDomains.length === 0) return;
|
|
4933
|
+
if (!matched || !matched.rule) return;
|
|
4934
|
+
logger7.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
4935
|
+
});
|
|
4936
|
+
};
|
|
4937
|
+
};
|
|
4938
|
+
|
|
4939
|
+
// src/internals/launch/default.js
|
|
4940
|
+
var logger8 = createInternalLogger("Launch");
|
|
4843
4941
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4844
4942
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
4845
4943
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -4851,16 +4949,6 @@ var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
|
4851
4949
|
navigationTimeoutSecs: 120
|
|
4852
4950
|
});
|
|
4853
4951
|
var fingerprintInjector = new FingerprintInjector();
|
|
4854
|
-
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
4855
|
-
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
4856
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4857
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4858
|
-
if (!enableProxy || !proxyUrl) {
|
|
4859
|
-
return { byPassDomains: [], enableProxy, proxyUrl };
|
|
4860
|
-
}
|
|
4861
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
4862
|
-
return { byPassDomains, enableProxy, proxyUrl };
|
|
4863
|
-
};
|
|
4864
4952
|
var parseChromeMajorVersion = (rawValue = "") => {
|
|
4865
4953
|
const match = String(rawValue || "").match(/(?:Chrome|Chromium)(?:\/|\s+(?:for Testing\s+)?)(\d+)/i);
|
|
4866
4954
|
return match ? Number(match[1] || 0) : 0;
|
|
@@ -4890,7 +4978,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
4890
4978
|
});
|
|
4891
4979
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
4892
4980
|
} catch (error) {
|
|
4893
|
-
|
|
4981
|
+
logger8.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
4894
4982
|
}
|
|
4895
4983
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
4896
4984
|
return detectedVersion;
|
|
@@ -4927,7 +5015,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
4927
5015
|
if (requestedBrowserMajorVersion <= 0) {
|
|
4928
5016
|
throw error;
|
|
4929
5017
|
}
|
|
4930
|
-
|
|
5018
|
+
logger8.warn(
|
|
4931
5019
|
`\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}`
|
|
4932
5020
|
);
|
|
4933
5021
|
}
|
|
@@ -4972,7 +5060,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
4972
5060
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
4973
5061
|
};
|
|
4974
5062
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
4975
|
-
|
|
5063
|
+
logger8.info(
|
|
4976
5064
|
`\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}`
|
|
4977
5065
|
);
|
|
4978
5066
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5073,13 +5161,12 @@ var DefaultLaunch = {
|
|
|
5073
5161
|
runtimeState = null
|
|
5074
5162
|
} = normalizedOptions;
|
|
5075
5163
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5076
|
-
const
|
|
5077
|
-
const
|
|
5078
|
-
const
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
}
|
|
5164
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5165
|
+
const traffic = resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5166
|
+
const trafficHook = createLaunchTrafficHook({
|
|
5167
|
+
...traffic,
|
|
5168
|
+
enabled: enableByPassLogger
|
|
5169
|
+
});
|
|
5083
5170
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5084
5171
|
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
5085
5172
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
@@ -5090,30 +5177,14 @@ var DefaultLaunch = {
|
|
|
5090
5177
|
],
|
|
5091
5178
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
5092
5179
|
};
|
|
5093
|
-
if (launchProxy) {
|
|
5094
|
-
launchOptions.proxy = launchProxy;
|
|
5095
|
-
}
|
|
5096
|
-
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5097
|
-
if (enableByPassLogger && launchProxy) {
|
|
5098
|
-
let upstreamLabel = "";
|
|
5099
|
-
try {
|
|
5100
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5101
|
-
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5102
|
-
} catch {
|
|
5103
|
-
}
|
|
5104
|
-
logger7.info(
|
|
5105
|
-
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5106
|
-
);
|
|
5107
|
-
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5108
|
-
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5109
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5110
|
-
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5111
|
-
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5112
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5113
|
-
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5114
|
-
} else if (enableByPassLogger) {
|
|
5115
|
-
logger7.info(`[\u6D41\u91CF\u89C2\u6D4B] \u9010\u8BF7\u6C42\u8C03\u8BD5=${Boolean(debugMode) ? "\u5F00\u542F" : "\u5173\u95ED"}\uFF08\u6C47\u603B\u59CB\u7EC8\u5F00\u542F\uFF09`);
|
|
5180
|
+
if (traffic.launchProxy) {
|
|
5181
|
+
launchOptions.proxy = traffic.launchProxy;
|
|
5116
5182
|
}
|
|
5183
|
+
logLaunchTraffic({
|
|
5184
|
+
...traffic,
|
|
5185
|
+
debugMode,
|
|
5186
|
+
enabled: enableByPassLogger
|
|
5187
|
+
});
|
|
5117
5188
|
const onPageCreated = (page) => {
|
|
5118
5189
|
const recommendedGotoOptions = {
|
|
5119
5190
|
waitUntil: "commit"
|
|
@@ -5121,22 +5192,7 @@ var DefaultLaunch = {
|
|
|
5121
5192
|
if (!page || typeof page.on !== "function") {
|
|
5122
5193
|
return recommendedGotoOptions;
|
|
5123
5194
|
}
|
|
5124
|
-
|
|
5125
|
-
return recommendedGotoOptions;
|
|
5126
|
-
}
|
|
5127
|
-
page[REQUEST_HOOK_FLAG] = true;
|
|
5128
|
-
const requestHandler = (req) => {
|
|
5129
|
-
const requestUrl = req.url();
|
|
5130
|
-
const resourceType = req.resourceType();
|
|
5131
|
-
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
5132
|
-
if (launchProxy) {
|
|
5133
|
-
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
5134
|
-
}
|
|
5135
|
-
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5136
|
-
if (!matched || !matched.rule) return;
|
|
5137
|
-
logger7.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
5138
|
-
};
|
|
5139
|
-
page.on("request", requestHandler);
|
|
5195
|
+
trafficHook(page);
|
|
5140
5196
|
return recommendedGotoOptions;
|
|
5141
5197
|
};
|
|
5142
5198
|
const launchContext = {
|
|
@@ -5191,7 +5247,7 @@ var DefaultLaunch = {
|
|
|
5191
5247
|
// src/internals/launch/cloak.js
|
|
5192
5248
|
import { execFile } from "node:child_process";
|
|
5193
5249
|
import { promisify } from "node:util";
|
|
5194
|
-
var
|
|
5250
|
+
var logger9 = createInternalLogger("Launch");
|
|
5195
5251
|
var execFileAsync = promisify(execFile);
|
|
5196
5252
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5197
5253
|
maxConcurrency: 1,
|
|
@@ -5220,9 +5276,9 @@ var loadCloakModule = async () => {
|
|
|
5220
5276
|
};
|
|
5221
5277
|
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5222
5278
|
const { buildLaunchOptions } = await loadCloakModule();
|
|
5223
|
-
return await buildLaunchOptions(
|
|
5279
|
+
return await buildLaunchOptions(normalizeObject2(options));
|
|
5224
5280
|
};
|
|
5225
|
-
var
|
|
5281
|
+
var normalizeObject2 = (value) => {
|
|
5226
5282
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5227
5283
|
return {};
|
|
5228
5284
|
}
|
|
@@ -5235,7 +5291,7 @@ var normalizeStringArray = (value) => {
|
|
|
5235
5291
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5236
5292
|
};
|
|
5237
5293
|
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5238
|
-
const config =
|
|
5294
|
+
const config = normalizeObject2(proxyConfiguration);
|
|
5239
5295
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5240
5296
|
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5241
5297
|
if (!enableProxy || !proxyUrl) {
|
|
@@ -5258,7 +5314,7 @@ var extractFingerprintArg = (launchOptions = {}) => {
|
|
|
5258
5314
|
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5259
5315
|
};
|
|
5260
5316
|
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5261
|
-
const normalizedRecommendedGotoOptions =
|
|
5317
|
+
const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
|
|
5262
5318
|
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5263
5319
|
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5264
5320
|
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
@@ -5274,11 +5330,11 @@ var attachCloakHumanizeHook = ({
|
|
|
5274
5330
|
patchedBrowsers,
|
|
5275
5331
|
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5276
5332
|
} = {}) => {
|
|
5277
|
-
const normalizedBrowserPoolOptions =
|
|
5333
|
+
const normalizedBrowserPoolOptions = normalizeObject2(browserPoolOptions);
|
|
5278
5334
|
const shouldHumanize = humanizeOptions !== false;
|
|
5279
5335
|
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5280
5336
|
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5281
|
-
...
|
|
5337
|
+
...normalizeObject2(humanizeOptions)
|
|
5282
5338
|
} : null;
|
|
5283
5339
|
return {
|
|
5284
5340
|
...normalizedBrowserPoolOptions,
|
|
@@ -5327,7 +5383,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5327
5383
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5328
5384
|
return;
|
|
5329
5385
|
}
|
|
5330
|
-
|
|
5386
|
+
logger9.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5331
5387
|
});
|
|
5332
5388
|
};
|
|
5333
5389
|
var CloakLaunch = {
|
|
@@ -5361,9 +5417,11 @@ var CloakLaunch = {
|
|
|
5361
5417
|
return await buildCloakLaunchOptions(options);
|
|
5362
5418
|
},
|
|
5363
5419
|
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5364
|
-
const normalizedOptions =
|
|
5420
|
+
const normalizedOptions = normalizeObject2(options);
|
|
5365
5421
|
const {
|
|
5366
5422
|
proxyConfiguration = {},
|
|
5423
|
+
log: logOptions = null,
|
|
5424
|
+
debugMode = false,
|
|
5367
5425
|
runInHeadfulMode = false,
|
|
5368
5426
|
isRunningOnApify = false,
|
|
5369
5427
|
launcher = null,
|
|
@@ -5376,13 +5434,16 @@ var CloakLaunch = {
|
|
|
5376
5434
|
postNavigationHooks = [],
|
|
5377
5435
|
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5378
5436
|
} = normalizedOptions;
|
|
5379
|
-
const normalizedCloakOptions =
|
|
5437
|
+
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5380
5438
|
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5381
5439
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5382
5440
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5383
5441
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5384
|
-
const
|
|
5442
|
+
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5443
|
+
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5444
|
+
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
5385
5445
|
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5446
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5386
5447
|
const mergedCloakOptions = {
|
|
5387
5448
|
...normalizedCloakOptions,
|
|
5388
5449
|
headless,
|
|
@@ -5392,15 +5453,27 @@ var CloakLaunch = {
|
|
|
5392
5453
|
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5393
5454
|
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5394
5455
|
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5456
|
+
const trafficHook = createLaunchTrafficHook({
|
|
5457
|
+
byPassDomains: proxyLaunchState.byPassDomains,
|
|
5458
|
+
byPassRules: proxyLaunchState.byPassRules,
|
|
5459
|
+
enabled: enableByPassLogger,
|
|
5460
|
+
launchProxy: proxyLaunchState.launchProxy
|
|
5461
|
+
});
|
|
5395
5462
|
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5396
5463
|
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5464
|
+
logLaunchTraffic({
|
|
5465
|
+
...proxyLaunchState,
|
|
5466
|
+
debugMode,
|
|
5467
|
+
enabled: enableByPassLogger,
|
|
5468
|
+
explicitProxy: hasExplicitProxy
|
|
5469
|
+
});
|
|
5397
5470
|
const crawlerOptions = {
|
|
5398
5471
|
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5399
|
-
...
|
|
5472
|
+
...normalizeObject2(crawlerBaseOptions),
|
|
5400
5473
|
headless,
|
|
5401
5474
|
launchContext: {
|
|
5402
5475
|
useIncognitoPages: true,
|
|
5403
|
-
...
|
|
5476
|
+
...normalizeObject2(launchContext),
|
|
5404
5477
|
...launcher ? { launcher } : {},
|
|
5405
5478
|
launchOptions
|
|
5406
5479
|
},
|
|
@@ -5410,7 +5483,13 @@ var CloakLaunch = {
|
|
|
5410
5483
|
patchedBrowsers,
|
|
5411
5484
|
humanizeOptions
|
|
5412
5485
|
}),
|
|
5413
|
-
preNavigationHooks: [
|
|
5486
|
+
preNavigationHooks: [
|
|
5487
|
+
async (crawlingContext, gotoOptions = {}) => {
|
|
5488
|
+
trafficHook(crawlingContext?.page);
|
|
5489
|
+
await internalPreNavigationHook(crawlingContext, gotoOptions);
|
|
5490
|
+
},
|
|
5491
|
+
...normalizedPreNavigationHooks
|
|
5492
|
+
],
|
|
5414
5493
|
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5415
5494
|
};
|
|
5416
5495
|
const closeActiveBrowsers = async () => {
|
|
@@ -5445,7 +5524,7 @@ var Launch = withModeReflect("Launch", launchStrategies);
|
|
|
5445
5524
|
// src/live-view.js
|
|
5446
5525
|
import express from "express";
|
|
5447
5526
|
import { Actor } from "apify";
|
|
5448
|
-
var
|
|
5527
|
+
var logger10 = createInternalLogger("LiveView");
|
|
5449
5528
|
async function startLiveViewServer(liveViewKey) {
|
|
5450
5529
|
const app = express();
|
|
5451
5530
|
app.get("/", async (req, res) => {
|
|
@@ -5470,13 +5549,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5470
5549
|
</html>
|
|
5471
5550
|
`);
|
|
5472
5551
|
} catch (error) {
|
|
5473
|
-
|
|
5552
|
+
logger10.fail("Live View Server", error);
|
|
5474
5553
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5475
5554
|
}
|
|
5476
5555
|
});
|
|
5477
5556
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5478
5557
|
app.listen(port, () => {
|
|
5479
|
-
|
|
5558
|
+
logger10.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5480
5559
|
});
|
|
5481
5560
|
}
|
|
5482
5561
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5484,10 +5563,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5484
5563
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5485
5564
|
await Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5486
5565
|
if (logMessage) {
|
|
5487
|
-
|
|
5566
|
+
logger10.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5488
5567
|
}
|
|
5489
5568
|
} catch (e) {
|
|
5490
|
-
|
|
5569
|
+
logger10.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5491
5570
|
}
|
|
5492
5571
|
}
|
|
5493
5572
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5596,7 +5675,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5596
5675
|
};
|
|
5597
5676
|
|
|
5598
5677
|
// src/internals/captcha/bytedance.js
|
|
5599
|
-
var
|
|
5678
|
+
var logger11 = createInternalLogger("Captcha");
|
|
5600
5679
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5601
5680
|
apiType: "31234",
|
|
5602
5681
|
maxRetries: 3,
|
|
@@ -5728,7 +5807,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5728
5807
|
}
|
|
5729
5808
|
await writeFile(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5730
5809
|
}
|
|
5731
|
-
|
|
5810
|
+
logger11.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5732
5811
|
};
|
|
5733
5812
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5734
5813
|
if (!options.debugArtifacts) {
|
|
@@ -5765,14 +5844,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5765
5844
|
if (!isContainerVisible) {
|
|
5766
5845
|
return null;
|
|
5767
5846
|
}
|
|
5768
|
-
|
|
5847
|
+
logger11.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5769
5848
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5770
5849
|
let isIframeVisible = await waitForVisible(
|
|
5771
5850
|
iframeLocator,
|
|
5772
5851
|
options.iframeVisibleTimeoutMs
|
|
5773
5852
|
);
|
|
5774
5853
|
if (!isIframeVisible) {
|
|
5775
|
-
|
|
5854
|
+
logger11.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5776
5855
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5777
5856
|
isIframeVisible = await waitForVisible(
|
|
5778
5857
|
iframeLocator,
|
|
@@ -5782,7 +5861,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5782
5861
|
if (!isIframeVisible) {
|
|
5783
5862
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5784
5863
|
}
|
|
5785
|
-
|
|
5864
|
+
logger11.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5786
5865
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5787
5866
|
if (!frame) {
|
|
5788
5867
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -5898,11 +5977,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
5898
5977
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
5899
5978
|
...options,
|
|
5900
5979
|
page,
|
|
5901
|
-
logger:
|
|
5980
|
+
logger: logger11,
|
|
5902
5981
|
forceMouse: true
|
|
5903
5982
|
}).catch(() => false);
|
|
5904
5983
|
if (!clicked) {
|
|
5905
|
-
|
|
5984
|
+
logger11.warn("Refresh button not found.");
|
|
5906
5985
|
return false;
|
|
5907
5986
|
}
|
|
5908
5987
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -5933,24 +6012,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
5933
6012
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
5934
6013
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
5935
6014
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
5936
|
-
|
|
6015
|
+
logger11.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u64CD\u4F5C\u5F15\u5BFC\u5C42\uFF0C\u7B49\u5F85\u5176\u6D88\u5931\u540E\u518D\u5F00\u59CB\u8BC6\u522B\u3002");
|
|
5937
6016
|
hasLoggedGuideMask = true;
|
|
5938
6017
|
}
|
|
5939
6018
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
5940
|
-
|
|
6019
|
+
logger11.info(
|
|
5941
6020
|
hasSeenGuideMask ? "\u9A8C\u8BC1\u7801\u56FE\u7247\u548C\u62D6\u62FD\u533A\u57DF\u5DF2\u5C31\u7EEA\uFF0C\u5F15\u5BFC\u5C42\u5DF2\u6D88\u5931\u3002" : hasSeenLoading ? "\u9A8C\u8BC1\u7801\u56FE\u7247\u5DF2\u52A0\u8F7D\u5B8C\u6210\u3002" : "\u9A8C\u8BC1\u7801\u56FE\u7247\u5DF2\u5C31\u7EEA\u3002"
|
|
5942
6021
|
);
|
|
5943
6022
|
return;
|
|
5944
6023
|
}
|
|
5945
6024
|
if (hasErrorTextVisible) {
|
|
5946
|
-
|
|
6025
|
+
logger11.warn("\u9A8C\u8BC1\u7801\u9762\u677F\u51FA\u73B0\u7F51\u7EDC\u5F02\u5E38\u6587\u6848\uFF0C\u5C1D\u8BD5\u7ACB\u5373\u5237\u65B0\u9898\u76EE\u3002");
|
|
5947
6026
|
await refreshCaptcha(page, frame, options);
|
|
5948
6027
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5949
6028
|
hasSeenLoading = false;
|
|
5950
6029
|
continue;
|
|
5951
6030
|
}
|
|
5952
6031
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
5953
|
-
|
|
6032
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u9898\u76EE\u8D85\u8FC7 ${options.challengeReadyRefreshTimeoutMs}ms \u4ECD\u672A\u51C6\u5907\u597D\uFF0C\u5C1D\u8BD5\u5237\u65B0\u9898\u76EE\u3002`);
|
|
5954
6033
|
await refreshCaptcha(page, frame, options);
|
|
5955
6034
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5956
6035
|
hasSeenLoading = false;
|
|
@@ -5998,7 +6077,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
5998
6077
|
accepted
|
|
5999
6078
|
};
|
|
6000
6079
|
dragAttempts.push(attemptInfo);
|
|
6001
|
-
|
|
6080
|
+
logger11.info(
|
|
6002
6081
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6003
6082
|
);
|
|
6004
6083
|
if (accepted) {
|
|
@@ -6016,7 +6095,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6016
6095
|
dragAttempts,
|
|
6017
6096
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6018
6097
|
}).catch((error) => {
|
|
6019
|
-
|
|
6098
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6020
6099
|
});
|
|
6021
6100
|
return {
|
|
6022
6101
|
accepted: false,
|
|
@@ -6033,16 +6112,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6033
6112
|
...options
|
|
6034
6113
|
};
|
|
6035
6114
|
if (!config.token) {
|
|
6036
|
-
|
|
6115
|
+
logger11.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6037
6116
|
return false;
|
|
6038
6117
|
}
|
|
6039
|
-
|
|
6118
|
+
logger11.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6040
6119
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6041
|
-
|
|
6120
|
+
logger11.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6042
6121
|
try {
|
|
6043
6122
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6044
6123
|
if (!captchaContext) {
|
|
6045
|
-
|
|
6124
|
+
logger11.info("Captcha container is not visible anymore.");
|
|
6046
6125
|
return true;
|
|
6047
6126
|
}
|
|
6048
6127
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6055,7 +6134,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6055
6134
|
"ready",
|
|
6056
6135
|
config
|
|
6057
6136
|
).catch((error) => {
|
|
6058
|
-
|
|
6137
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6059
6138
|
});
|
|
6060
6139
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6061
6140
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6067,16 +6146,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6067
6146
|
});
|
|
6068
6147
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6069
6148
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6070
|
-
|
|
6149
|
+
logger11.warn(
|
|
6071
6150
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6072
6151
|
);
|
|
6073
6152
|
await refreshCaptcha(page, frame, config);
|
|
6074
6153
|
continue;
|
|
6075
6154
|
}
|
|
6076
|
-
|
|
6155
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6077
6156
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6078
6157
|
if (!dropTarget) {
|
|
6079
|
-
|
|
6158
|
+
logger11.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6080
6159
|
await refreshCaptcha(page, frame, config);
|
|
6081
6160
|
continue;
|
|
6082
6161
|
}
|
|
@@ -6087,7 +6166,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6087
6166
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6088
6167
|
);
|
|
6089
6168
|
}
|
|
6090
|
-
|
|
6169
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6091
6170
|
for (const imageIndex of normalizedIndexes) {
|
|
6092
6171
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6093
6172
|
throw new Error(
|
|
@@ -6119,52 +6198,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6119
6198
|
}
|
|
6120
6199
|
}
|
|
6121
6200
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6122
|
-
|
|
6201
|
+
logger11.info(
|
|
6123
6202
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6124
6203
|
);
|
|
6125
6204
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6126
6205
|
...config,
|
|
6127
6206
|
page,
|
|
6128
|
-
logger:
|
|
6207
|
+
logger: logger11,
|
|
6129
6208
|
forceMouse: true,
|
|
6130
6209
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6131
6210
|
}).catch(() => false);
|
|
6132
6211
|
if (!submitted) {
|
|
6133
|
-
|
|
6212
|
+
logger11.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6134
6213
|
}
|
|
6135
6214
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6136
6215
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6137
|
-
|
|
6216
|
+
logger11.info(
|
|
6138
6217
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6139
6218
|
);
|
|
6140
6219
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6141
6220
|
if (!stillVisible) {
|
|
6142
|
-
|
|
6221
|
+
logger11.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6143
6222
|
return true;
|
|
6144
6223
|
}
|
|
6145
6224
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6146
6225
|
beforeSubmitState,
|
|
6147
6226
|
afterSubmitState
|
|
6148
6227
|
}).catch((error) => {
|
|
6149
|
-
|
|
6228
|
+
logger11.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6150
6229
|
});
|
|
6151
|
-
|
|
6230
|
+
logger11.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6152
6231
|
await page.waitForTimeout(2e3);
|
|
6153
6232
|
await refreshCaptcha(page, frame, config);
|
|
6154
6233
|
} catch (error) {
|
|
6155
|
-
|
|
6234
|
+
logger11.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6156
6235
|
}
|
|
6157
6236
|
if (attempt < config.maxRetries) {
|
|
6158
6237
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6159
6238
|
}
|
|
6160
6239
|
}
|
|
6161
|
-
|
|
6240
|
+
logger11.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6162
6241
|
return false;
|
|
6163
6242
|
}
|
|
6164
6243
|
var sloveCaptcha = solveCaptcha;
|
|
6165
6244
|
|
|
6166
6245
|
// src/chaptcha.js
|
|
6167
|
-
var
|
|
6246
|
+
var logger12 = createInternalLogger("Captcha");
|
|
6168
6247
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6169
6248
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6170
6249
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6251,7 +6330,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6251
6330
|
};
|
|
6252
6331
|
})();
|
|
6253
6332
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6254
|
-
|
|
6333
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6255
6334
|
cleanupFns.push(async () => {
|
|
6256
6335
|
try {
|
|
6257
6336
|
await page.evaluate((name) => {
|
|
@@ -6275,14 +6354,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
6275
6354
|
}
|
|
6276
6355
|
};
|
|
6277
6356
|
page.on("framenavigated", frameHandler);
|
|
6278
|
-
|
|
6357
|
+
logger12.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6279
6358
|
cleanupFns.push(async () => {
|
|
6280
6359
|
page.off("framenavigated", frameHandler);
|
|
6281
6360
|
});
|
|
6282
6361
|
}
|
|
6283
6362
|
return {
|
|
6284
6363
|
stop: async () => {
|
|
6285
|
-
|
|
6364
|
+
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6286
6365
|
for (const fn of cleanupFns) {
|
|
6287
6366
|
await fn();
|
|
6288
6367
|
}
|
|
@@ -6321,7 +6400,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6321
6400
|
);
|
|
6322
6401
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6323
6402
|
callCaptchaRecognitionApi,
|
|
6324
|
-
logger:
|
|
6403
|
+
logger: logger12
|
|
6325
6404
|
});
|
|
6326
6405
|
}
|
|
6327
6406
|
var Captcha = {
|
|
@@ -6332,7 +6411,7 @@ var Captcha = {
|
|
|
6332
6411
|
// src/mutation.js
|
|
6333
6412
|
import { createHash } from "node:crypto";
|
|
6334
6413
|
import { v4 as uuidv42 } from "uuid";
|
|
6335
|
-
var
|
|
6414
|
+
var logger13 = createInternalLogger("Mutation");
|
|
6336
6415
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6337
6416
|
Added: "added",
|
|
6338
6417
|
Changed: "changed",
|
|
@@ -6365,14 +6444,14 @@ var Mutation = {
|
|
|
6365
6444
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6366
6445
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6367
6446
|
const onMutation = options.onMutation;
|
|
6368
|
-
|
|
6447
|
+
logger13.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6369
6448
|
if (initialTimeout > 0) {
|
|
6370
6449
|
const selectorQuery = selectorList.join(",");
|
|
6371
6450
|
try {
|
|
6372
6451
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6373
|
-
|
|
6452
|
+
logger13.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6374
6453
|
} catch (e) {
|
|
6375
|
-
|
|
6454
|
+
logger13.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6376
6455
|
throw e;
|
|
6377
6456
|
}
|
|
6378
6457
|
}
|
|
@@ -6388,7 +6467,7 @@ var Mutation = {
|
|
|
6388
6467
|
return "__CONTINUE__";
|
|
6389
6468
|
}
|
|
6390
6469
|
});
|
|
6391
|
-
|
|
6470
|
+
logger13.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6392
6471
|
} catch (e) {
|
|
6393
6472
|
}
|
|
6394
6473
|
}
|
|
@@ -6503,9 +6582,9 @@ var Mutation = {
|
|
|
6503
6582
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6504
6583
|
);
|
|
6505
6584
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6506
|
-
|
|
6585
|
+
logger13.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6507
6586
|
}
|
|
6508
|
-
|
|
6587
|
+
logger13.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6509
6588
|
return result;
|
|
6510
6589
|
},
|
|
6511
6590
|
/**
|
|
@@ -6677,22 +6756,22 @@ var Mutation = {
|
|
|
6677
6756
|
return "__CONTINUE__";
|
|
6678
6757
|
}
|
|
6679
6758
|
};
|
|
6680
|
-
|
|
6759
|
+
logger13.start(
|
|
6681
6760
|
"waitForStableAcrossRoots",
|
|
6682
6761
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6683
6762
|
);
|
|
6684
6763
|
if (initialTimeout > 0) {
|
|
6685
6764
|
try {
|
|
6686
6765
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6687
|
-
|
|
6766
|
+
logger13.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6688
6767
|
} catch (e) {
|
|
6689
|
-
|
|
6768
|
+
logger13.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6690
6769
|
throw e;
|
|
6691
6770
|
}
|
|
6692
6771
|
}
|
|
6693
6772
|
let state2 = await buildState();
|
|
6694
6773
|
if (!state2?.hasMatched) {
|
|
6695
|
-
|
|
6774
|
+
logger13.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6696
6775
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6697
6776
|
}
|
|
6698
6777
|
let mutationCount = 0;
|
|
@@ -6729,7 +6808,7 @@ var Mutation = {
|
|
|
6729
6808
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6730
6809
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6731
6810
|
mutationCount += 1;
|
|
6732
|
-
|
|
6811
|
+
logger13.info(
|
|
6733
6812
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6734
6813
|
);
|
|
6735
6814
|
const signal = await invokeMutationCallback({
|
|
@@ -6742,7 +6821,7 @@ var Mutation = {
|
|
|
6742
6821
|
continue;
|
|
6743
6822
|
}
|
|
6744
6823
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6745
|
-
|
|
6824
|
+
logger13.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6746
6825
|
return {
|
|
6747
6826
|
mutationCount,
|
|
6748
6827
|
stableTime: waitForStableTime,
|
|
@@ -6769,7 +6848,7 @@ var Mutation = {
|
|
|
6769
6848
|
const onMutation = options.onMutation;
|
|
6770
6849
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6771
6850
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6772
|
-
|
|
6851
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6773
6852
|
const monitorKey = generateKey("pk_mon");
|
|
6774
6853
|
const callbackName = generateKey("pk_mon_cb");
|
|
6775
6854
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6912,7 +6991,7 @@ var Mutation = {
|
|
|
6912
6991
|
return total;
|
|
6913
6992
|
};
|
|
6914
6993
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
6915
|
-
|
|
6994
|
+
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
6916
6995
|
return {
|
|
6917
6996
|
stop: async () => {
|
|
6918
6997
|
let totalMutations = 0;
|
|
@@ -6925,7 +7004,7 @@ var Mutation = {
|
|
|
6925
7004
|
}, cleanerName);
|
|
6926
7005
|
} catch (e) {
|
|
6927
7006
|
}
|
|
6928
|
-
|
|
7007
|
+
logger13.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
6929
7008
|
return { totalMutations };
|
|
6930
7009
|
}
|
|
6931
7010
|
};
|
|
@@ -7794,7 +7873,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7794
7873
|
};
|
|
7795
7874
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7796
7875
|
var Logger = {
|
|
7797
|
-
setLogger: (
|
|
7876
|
+
setLogger: (logger17) => setDefaultLogger(logger17),
|
|
7798
7877
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7799
7878
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7800
7879
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7802,8 +7881,8 @@ var Logger = {
|
|
|
7802
7881
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7803
7882
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7804
7883
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7805
|
-
useTemplate: (
|
|
7806
|
-
if (
|
|
7884
|
+
useTemplate: (logger17) => {
|
|
7885
|
+
if (logger17) return createTemplateLogger(createBaseLogger("", logger17));
|
|
7807
7886
|
return createTemplateLogger();
|
|
7808
7887
|
}
|
|
7809
7888
|
};
|
|
@@ -7877,7 +7956,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
7877
7956
|
];
|
|
7878
7957
|
var cachedStripLogoSrcPromise = null;
|
|
7879
7958
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
7880
|
-
var
|
|
7959
|
+
var logger14 = createInternalLogger("Watermarkify");
|
|
7881
7960
|
var normalizeText = (value) => String(value || "").trim();
|
|
7882
7961
|
var toInline = (value, maxLen = 200) => {
|
|
7883
7962
|
const text = normalizeText(value);
|
|
@@ -8119,9 +8198,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8119
8198
|
location: toInline(resolved.location, 80)
|
|
8120
8199
|
};
|
|
8121
8200
|
if (enrichment.ip || enrichment.location) {
|
|
8122
|
-
|
|
8201
|
+
logger14.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8123
8202
|
} else {
|
|
8124
|
-
|
|
8203
|
+
logger14.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8125
8204
|
}
|
|
8126
8205
|
return enrichment;
|
|
8127
8206
|
} finally {
|
|
@@ -8310,12 +8389,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8310
8389
|
};
|
|
8311
8390
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8312
8391
|
if (!page || typeof page.context !== "function") {
|
|
8313
|
-
|
|
8392
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8314
8393
|
return buffer;
|
|
8315
8394
|
}
|
|
8316
8395
|
const renderScope = await openProbePage(page);
|
|
8317
8396
|
if (!renderScope?.page) {
|
|
8318
|
-
|
|
8397
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8319
8398
|
return buffer;
|
|
8320
8399
|
}
|
|
8321
8400
|
try {
|
|
@@ -8380,13 +8459,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8380
8459
|
fullPage: true,
|
|
8381
8460
|
animations: "disabled"
|
|
8382
8461
|
}).catch((error) => {
|
|
8383
|
-
|
|
8462
|
+
logger14.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8384
8463
|
return null;
|
|
8385
8464
|
});
|
|
8386
8465
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8387
8466
|
return composed;
|
|
8388
8467
|
}
|
|
8389
|
-
|
|
8468
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8390
8469
|
return buffer;
|
|
8391
8470
|
} finally {
|
|
8392
8471
|
await renderScope.close().catch(() => {
|
|
@@ -8399,7 +8478,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8399
8478
|
}
|
|
8400
8479
|
const probeScope = await openProbePage(page);
|
|
8401
8480
|
if (!probeScope?.page) {
|
|
8402
|
-
|
|
8481
|
+
logger14.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8403
8482
|
return null;
|
|
8404
8483
|
}
|
|
8405
8484
|
const timeoutMs = Math.max(
|
|
@@ -8408,12 +8487,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8408
8487
|
);
|
|
8409
8488
|
try {
|
|
8410
8489
|
const probePage = probeScope.page;
|
|
8411
|
-
|
|
8490
|
+
logger14.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8412
8491
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8413
8492
|
waitUntil: "commit",
|
|
8414
8493
|
timeout: timeoutMs
|
|
8415
8494
|
}).catch((error) => {
|
|
8416
|
-
|
|
8495
|
+
logger14.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8417
8496
|
return null;
|
|
8418
8497
|
});
|
|
8419
8498
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8435,13 +8514,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8435
8514
|
}
|
|
8436
8515
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8437
8516
|
if (parsed?.ip || parsed?.location) {
|
|
8438
|
-
|
|
8517
|
+
logger14.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8439
8518
|
return parsed;
|
|
8440
8519
|
}
|
|
8441
|
-
|
|
8520
|
+
logger14.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8442
8521
|
return null;
|
|
8443
8522
|
} catch (error) {
|
|
8444
|
-
|
|
8523
|
+
logger14.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8445
8524
|
return null;
|
|
8446
8525
|
} finally {
|
|
8447
8526
|
await probeScope.close().catch(() => {
|
|
@@ -8455,10 +8534,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8455
8534
|
ip: toInline(options.ip, 80),
|
|
8456
8535
|
location: toInline(options.location, 80)
|
|
8457
8536
|
};
|
|
8458
|
-
|
|
8537
|
+
logger14.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8459
8538
|
if (!merged.ip || !merged.location) {
|
|
8460
8539
|
if (cached?.ip || cached?.location) {
|
|
8461
|
-
|
|
8540
|
+
logger14.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8462
8541
|
}
|
|
8463
8542
|
fillEnrichment(merged, cached);
|
|
8464
8543
|
}
|
|
@@ -8482,15 +8561,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8482
8561
|
"x-geo-country"
|
|
8483
8562
|
]), 80);
|
|
8484
8563
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8485
|
-
|
|
8564
|
+
logger14.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8486
8565
|
merged.location = headerLocation || merged.location;
|
|
8487
8566
|
}
|
|
8488
8567
|
}
|
|
8489
8568
|
writeCachedEnrichment(page, merged);
|
|
8490
8569
|
if (merged.ip || merged.location) {
|
|
8491
|
-
|
|
8570
|
+
logger14.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8492
8571
|
} else {
|
|
8493
|
-
|
|
8572
|
+
logger14.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8494
8573
|
}
|
|
8495
8574
|
return merged;
|
|
8496
8575
|
};
|
|
@@ -9303,7 +9382,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9303
9382
|
}
|
|
9304
9383
|
const imageInfo = readImageInfo(buffer);
|
|
9305
9384
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9306
|
-
|
|
9385
|
+
logger14.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9307
9386
|
return buffer;
|
|
9308
9387
|
}
|
|
9309
9388
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9321,7 +9400,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9321
9400
|
|
|
9322
9401
|
// src/internals/compression.js
|
|
9323
9402
|
import { Jimp, JimpMime, ResizeStrategy } from "jimp";
|
|
9324
|
-
var
|
|
9403
|
+
var logger15 = createInternalLogger("Compression");
|
|
9325
9404
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9326
9405
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9327
9406
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9440,18 +9519,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9440
9519
|
return buffer.toString("base64");
|
|
9441
9520
|
}
|
|
9442
9521
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9443
|
-
|
|
9522
|
+
logger15.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9444
9523
|
return null;
|
|
9445
9524
|
});
|
|
9446
9525
|
if (!result?.buffer) {
|
|
9447
9526
|
return buffer.toString("base64");
|
|
9448
9527
|
}
|
|
9449
9528
|
if (result.withinLimit) {
|
|
9450
|
-
|
|
9529
|
+
logger15.info(
|
|
9451
9530
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9452
9531
|
);
|
|
9453
9532
|
} else {
|
|
9454
|
-
|
|
9533
|
+
logger15.warning(
|
|
9455
9534
|
`captureScreen \u538B\u7F29\u540E\u4ECD\u8D85\u8FC7\u76EE\u6807: ${originalBytes} -> ${result.bytes} bytes, maxBytes=${compression.maxBytes}, format=${result.format}, quality=${result.quality}, scale=${result.scale}`
|
|
9456
9535
|
);
|
|
9457
9536
|
}
|
|
@@ -9459,7 +9538,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9459
9538
|
};
|
|
9460
9539
|
|
|
9461
9540
|
// src/share.js
|
|
9462
|
-
var
|
|
9541
|
+
var logger16 = createInternalLogger("Share");
|
|
9463
9542
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9464
9543
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9465
9544
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9596,7 +9675,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9596
9675
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9597
9676
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9598
9677
|
let matched = false;
|
|
9599
|
-
|
|
9678
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9600
9679
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9601
9680
|
mode,
|
|
9602
9681
|
onMutation: (context = {}) => {
|
|
@@ -9614,12 +9693,12 @@ ${text}`;
|
|
|
9614
9693
|
});
|
|
9615
9694
|
}
|
|
9616
9695
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9617
|
-
|
|
9696
|
+
logger16.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9618
9697
|
}
|
|
9619
9698
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9620
9699
|
if (!candidate) return;
|
|
9621
9700
|
matched = true;
|
|
9622
|
-
|
|
9701
|
+
logger16.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9623
9702
|
if (onMatch) {
|
|
9624
9703
|
onMatch({
|
|
9625
9704
|
link: candidate,
|
|
@@ -9635,7 +9714,7 @@ ${text}`;
|
|
|
9635
9714
|
return {
|
|
9636
9715
|
stop: async () => {
|
|
9637
9716
|
const result = await monitor.stop();
|
|
9638
|
-
|
|
9717
|
+
logger16.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9639
9718
|
return result;
|
|
9640
9719
|
}
|
|
9641
9720
|
};
|
|
@@ -9684,8 +9763,8 @@ var Share = {
|
|
|
9684
9763
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9685
9764
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9686
9765
|
}
|
|
9687
|
-
|
|
9688
|
-
|
|
9766
|
+
logger16.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9767
|
+
logger16.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9689
9768
|
const stats = {
|
|
9690
9769
|
actionTimedOut: false,
|
|
9691
9770
|
domMutationCount: 0,
|
|
@@ -9697,7 +9776,7 @@ var Share = {
|
|
|
9697
9776
|
responseSampleUrls: []
|
|
9698
9777
|
};
|
|
9699
9778
|
if (isAborted()) {
|
|
9700
|
-
|
|
9779
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9701
9780
|
return {
|
|
9702
9781
|
link: null,
|
|
9703
9782
|
payloadText: "",
|
|
@@ -9720,7 +9799,7 @@ var Share = {
|
|
|
9720
9799
|
link: validated,
|
|
9721
9800
|
payloadText: String(payloadText || "")
|
|
9722
9801
|
};
|
|
9723
|
-
|
|
9802
|
+
logger16.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9724
9803
|
return true;
|
|
9725
9804
|
};
|
|
9726
9805
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9755,7 +9834,7 @@ var Share = {
|
|
|
9755
9834
|
try {
|
|
9756
9835
|
await monitor.stop();
|
|
9757
9836
|
} catch (error) {
|
|
9758
|
-
|
|
9837
|
+
logger16.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9759
9838
|
}
|
|
9760
9839
|
};
|
|
9761
9840
|
const onResponse = async (response) => {
|
|
@@ -9769,29 +9848,29 @@ var Share = {
|
|
|
9769
9848
|
stats.responseSampleUrls.push(url);
|
|
9770
9849
|
}
|
|
9771
9850
|
if (stats.responseObserved <= 5) {
|
|
9772
|
-
|
|
9851
|
+
logger16.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9773
9852
|
}
|
|
9774
9853
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9775
9854
|
stats.responseMatched += 1;
|
|
9776
9855
|
stats.lastMatchedUrl = url;
|
|
9777
|
-
|
|
9856
|
+
logger16.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9778
9857
|
const text = await response.text();
|
|
9779
9858
|
const hit = resolveResponseCandidate(text);
|
|
9780
9859
|
if (!hit?.link) {
|
|
9781
9860
|
if (stats.responseMatched <= 3) {
|
|
9782
|
-
|
|
9861
|
+
logger16.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9783
9862
|
}
|
|
9784
9863
|
return;
|
|
9785
9864
|
}
|
|
9786
9865
|
stats.responseResolved += 1;
|
|
9787
|
-
|
|
9866
|
+
logger16.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9788
9867
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9789
9868
|
} catch (error) {
|
|
9790
|
-
|
|
9869
|
+
logger16.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9791
9870
|
}
|
|
9792
9871
|
};
|
|
9793
9872
|
if (share.mode === "dom") {
|
|
9794
|
-
|
|
9873
|
+
logger16.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9795
9874
|
domMonitor = await createDomShareMonitor(page, {
|
|
9796
9875
|
prefix: share.prefix,
|
|
9797
9876
|
selectors: domSelectors,
|
|
@@ -9806,17 +9885,17 @@ var Share = {
|
|
|
9806
9885
|
});
|
|
9807
9886
|
}
|
|
9808
9887
|
if (share.mode === "response") {
|
|
9809
|
-
|
|
9888
|
+
logger16.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9810
9889
|
page.on("response", onResponse);
|
|
9811
9890
|
}
|
|
9812
9891
|
if (share.mode === "custom") {
|
|
9813
|
-
|
|
9892
|
+
logger16.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9814
9893
|
}
|
|
9815
9894
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9816
9895
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9817
9896
|
try {
|
|
9818
9897
|
const actionTimeout = getRemainingMs();
|
|
9819
|
-
|
|
9898
|
+
logger16.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9820
9899
|
let actionValue;
|
|
9821
9900
|
if (!isAborted() && actionTimeout > 0) {
|
|
9822
9901
|
let timer = null;
|
|
@@ -9829,30 +9908,30 @@ var Share = {
|
|
|
9829
9908
|
]);
|
|
9830
9909
|
if (timer) clearTimeout(timer);
|
|
9831
9910
|
if (actionResult.type === "error") {
|
|
9832
|
-
|
|
9911
|
+
logger16.fail("captureLink.performActions", actionResult.error);
|
|
9833
9912
|
throw actionResult.error;
|
|
9834
9913
|
}
|
|
9835
9914
|
if (actionResult.type === "timeout") {
|
|
9836
9915
|
stats.actionTimedOut = true;
|
|
9837
|
-
|
|
9916
|
+
logger16.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9838
9917
|
} else {
|
|
9839
9918
|
actionValue = actionResult.result;
|
|
9840
|
-
|
|
9919
|
+
logger16.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9841
9920
|
}
|
|
9842
9921
|
}
|
|
9843
9922
|
if (share.mode === "custom") {
|
|
9844
9923
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9845
9924
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9846
9925
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9847
|
-
|
|
9926
|
+
logger16.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9848
9927
|
} else {
|
|
9849
|
-
|
|
9928
|
+
logger16.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9850
9929
|
}
|
|
9851
9930
|
}
|
|
9852
9931
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9853
9932
|
while (true) {
|
|
9854
9933
|
if (isAborted()) {
|
|
9855
|
-
|
|
9934
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9856
9935
|
return {
|
|
9857
9936
|
link: null,
|
|
9858
9937
|
payloadText: "",
|
|
@@ -9862,7 +9941,7 @@ var Share = {
|
|
|
9862
9941
|
}
|
|
9863
9942
|
const selected = candidates[share.mode];
|
|
9864
9943
|
if (selected?.link) {
|
|
9865
|
-
|
|
9944
|
+
logger16.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9866
9945
|
return {
|
|
9867
9946
|
link: selected.link,
|
|
9868
9947
|
payloadText: selected.payloadText,
|
|
@@ -9875,7 +9954,7 @@ var Share = {
|
|
|
9875
9954
|
if (remaining <= 0) break;
|
|
9876
9955
|
const now = Date.now();
|
|
9877
9956
|
if (now >= nextProgressLogTs) {
|
|
9878
|
-
|
|
9957
|
+
logger16.info(
|
|
9879
9958
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9880
9959
|
);
|
|
9881
9960
|
nextProgressLogTs = now + 5e3;
|
|
@@ -9883,11 +9962,11 @@ var Share = {
|
|
|
9883
9962
|
await delay5(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9884
9963
|
}
|
|
9885
9964
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9886
|
-
|
|
9965
|
+
logger16.warning(
|
|
9887
9966
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9888
9967
|
);
|
|
9889
9968
|
}
|
|
9890
|
-
|
|
9969
|
+
logger16.warning(
|
|
9891
9970
|
`captureLink ${timeoutDisabled ? "\u672A\u62FF\u5230\u94FE\u63A5" : "\u8D85\u65F6\u672A\u62FF\u5230\u94FE\u63A5"}: mode=${share.mode}, actionTimedOut=${stats.actionTimedOut}, domMutationCount=${stats.domMutationCount}, responseObserved=${stats.responseObserved}, responseMatched=${stats.responseMatched}, lastMatchedUrl=${stats.lastMatchedUrl || "none"}`
|
|
9892
9971
|
);
|
|
9893
9972
|
return {
|
|
@@ -9899,7 +9978,7 @@ var Share = {
|
|
|
9899
9978
|
} finally {
|
|
9900
9979
|
if (share.mode === "response") {
|
|
9901
9980
|
page.off("response", onResponse);
|
|
9902
|
-
|
|
9981
|
+
logger16.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
9903
9982
|
}
|
|
9904
9983
|
await stopDomMonitor();
|
|
9905
9984
|
}
|