@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.cjs
CHANGED
|
@@ -387,18 +387,18 @@ var fallbackLog = {
|
|
|
387
387
|
error: (...args) => console.error(...args),
|
|
388
388
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
389
389
|
};
|
|
390
|
-
var resolveLogMethod = (
|
|
391
|
-
if (
|
|
392
|
-
return
|
|
390
|
+
var resolveLogMethod = (logger17, name) => {
|
|
391
|
+
if (logger17 && typeof logger17[name] === "function") {
|
|
392
|
+
return logger17[name].bind(logger17);
|
|
393
393
|
}
|
|
394
|
-
if (name === "warning" &&
|
|
395
|
-
return
|
|
394
|
+
if (name === "warning" && logger17 && typeof logger17.warn === "function") {
|
|
395
|
+
return logger17.warn.bind(logger17);
|
|
396
396
|
}
|
|
397
397
|
return fallbackLog[name];
|
|
398
398
|
};
|
|
399
399
|
var defaultLogger = null;
|
|
400
|
-
var setDefaultLogger = (
|
|
401
|
-
defaultLogger =
|
|
400
|
+
var setDefaultLogger = (logger17) => {
|
|
401
|
+
defaultLogger = logger17;
|
|
402
402
|
};
|
|
403
403
|
var resolveLogger = (explicitLogger) => {
|
|
404
404
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -425,8 +425,8 @@ var colorize = (text, color) => {
|
|
|
425
425
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
426
426
|
const name = prefix ? String(prefix) : "";
|
|
427
427
|
const dispatch = (methodName, icon, message, color) => {
|
|
428
|
-
const
|
|
429
|
-
const logFn = resolveLogMethod(
|
|
428
|
+
const logger17 = resolveLogger(explicitLogger);
|
|
429
|
+
const logFn = resolveLogMethod(logger17, methodName);
|
|
430
430
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
431
431
|
const line = formatLine(name, icon, message);
|
|
432
432
|
const coloredLine = colorize(line, color);
|
|
@@ -4865,9 +4865,107 @@ var ByPass = {
|
|
|
4865
4865
|
resolveRouteByProxy
|
|
4866
4866
|
};
|
|
4867
4867
|
|
|
4868
|
-
// src/internals/launch/
|
|
4868
|
+
// src/internals/launch/traffic.js
|
|
4869
4869
|
var logger7 = createInternalLogger("Launch");
|
|
4870
|
-
var
|
|
4870
|
+
var normalizeObject = (value) => {
|
|
4871
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4872
|
+
return {};
|
|
4873
|
+
}
|
|
4874
|
+
return value;
|
|
4875
|
+
};
|
|
4876
|
+
var parseProxyConfiguration = (proxyConfiguration = {}) => {
|
|
4877
|
+
const config = normalizeObject(proxyConfiguration);
|
|
4878
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4879
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4880
|
+
const byPassDomains = enableProxy && proxyUrl ? ByPass.normalizeByPassDomains(config.by_pass_domains) : [];
|
|
4881
|
+
return {
|
|
4882
|
+
byPassDomains,
|
|
4883
|
+
enableProxy,
|
|
4884
|
+
proxyUrl
|
|
4885
|
+
};
|
|
4886
|
+
};
|
|
4887
|
+
var resolveLaunchTraffic = ({
|
|
4888
|
+
proxyConfiguration = {},
|
|
4889
|
+
debugMode = false,
|
|
4890
|
+
useMeter = true
|
|
4891
|
+
} = {}) => {
|
|
4892
|
+
const { byPassDomains, enableProxy, proxyUrl } = parseProxyConfiguration(proxyConfiguration);
|
|
4893
|
+
const byPassRules = ByPass.buildByPassDomainRules(byPassDomains);
|
|
4894
|
+
const proxyMeter = useMeter && enableProxy && proxyUrl ? ProxyMeterRuntime.startProxyMeter({ proxyUrl, debugMode }) : null;
|
|
4895
|
+
const launchProxy = proxyMeter ? { server: proxyMeter.server } : null;
|
|
4896
|
+
if (launchProxy && byPassDomains.length > 0) {
|
|
4897
|
+
launchProxy.bypass = byPassDomains.join(",");
|
|
4898
|
+
}
|
|
4899
|
+
return {
|
|
4900
|
+
byPassDomains,
|
|
4901
|
+
byPassRules,
|
|
4902
|
+
enableProxy,
|
|
4903
|
+
proxyUrl,
|
|
4904
|
+
launchProxy
|
|
4905
|
+
};
|
|
4906
|
+
};
|
|
4907
|
+
var logLaunchTraffic = ({
|
|
4908
|
+
byPassDomains = [],
|
|
4909
|
+
debugMode = false,
|
|
4910
|
+
enabled = false,
|
|
4911
|
+
enableProxy = false,
|
|
4912
|
+
explicitProxy = false,
|
|
4913
|
+
launchProxy = null,
|
|
4914
|
+
proxyUrl = ""
|
|
4915
|
+
} = {}) => {
|
|
4916
|
+
if (!enabled) return;
|
|
4917
|
+
if (explicitProxy) {
|
|
4918
|
+
logger7.info("[\u4EE3\u7406\u5DF2\u542F\u7528] \u4F7F\u7528\u663E\u5F0F proxy \u914D\u7F6E\uFF0C\u8DF3\u8FC7 toolkit \u672C\u5730\u6D41\u91CF\u89C2\u6D4B");
|
|
4919
|
+
return;
|
|
4920
|
+
}
|
|
4921
|
+
if (launchProxy) {
|
|
4922
|
+
let upstreamLabel = "";
|
|
4923
|
+
try {
|
|
4924
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
4925
|
+
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
4926
|
+
} catch {
|
|
4927
|
+
}
|
|
4928
|
+
logger7.info(
|
|
4929
|
+
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${byPassDomains.join(",")}`
|
|
4930
|
+
);
|
|
4931
|
+
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`);
|
|
4932
|
+
return;
|
|
4933
|
+
}
|
|
4934
|
+
if (enableProxy) {
|
|
4935
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
4936
|
+
} else if (proxyUrl) {
|
|
4937
|
+
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
4938
|
+
}
|
|
4939
|
+
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`);
|
|
4940
|
+
};
|
|
4941
|
+
var createLaunchTrafficHook = ({
|
|
4942
|
+
byPassDomains = [],
|
|
4943
|
+
byPassRules = [],
|
|
4944
|
+
enabled = false,
|
|
4945
|
+
launchProxy = null
|
|
4946
|
+
} = {}) => {
|
|
4947
|
+
const patchedPages = /* @__PURE__ */ new WeakSet();
|
|
4948
|
+
return (page) => {
|
|
4949
|
+
if (!page || typeof page.on !== "function" || patchedPages.has(page)) {
|
|
4950
|
+
return;
|
|
4951
|
+
}
|
|
4952
|
+
patchedPages.add(page);
|
|
4953
|
+
page.on("request", (req) => {
|
|
4954
|
+
const requestUrl = req.url();
|
|
4955
|
+
const resourceType = req.resourceType();
|
|
4956
|
+
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
4957
|
+
if (launchProxy) {
|
|
4958
|
+
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
4959
|
+
}
|
|
4960
|
+
if (!enabled || byPassDomains.length === 0) return;
|
|
4961
|
+
if (!matched || !matched.rule) return;
|
|
4962
|
+
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}`);
|
|
4963
|
+
});
|
|
4964
|
+
};
|
|
4965
|
+
};
|
|
4966
|
+
|
|
4967
|
+
// src/internals/launch/default.js
|
|
4968
|
+
var logger8 = createInternalLogger("Launch");
|
|
4871
4969
|
var injectedContexts = /* @__PURE__ */ new WeakSet();
|
|
4872
4970
|
var browserMajorVersionCache = /* @__PURE__ */ new Map();
|
|
4873
4971
|
var DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION = 1;
|
|
@@ -4879,16 +4977,6 @@ var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
|
4879
4977
|
navigationTimeoutSecs: 120
|
|
4880
4978
|
});
|
|
4881
4979
|
var fingerprintInjector = new import_fingerprint_injector.FingerprintInjector();
|
|
4882
|
-
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
4883
|
-
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
4884
|
-
const proxyUrl = String(config.proxy_url || "").trim();
|
|
4885
|
-
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
4886
|
-
if (!enableProxy || !proxyUrl) {
|
|
4887
|
-
return { byPassDomains: [], enableProxy, proxyUrl };
|
|
4888
|
-
}
|
|
4889
|
-
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
4890
|
-
return { byPassDomains, enableProxy, proxyUrl };
|
|
4891
|
-
};
|
|
4892
4980
|
var parseChromeMajorVersion = (rawValue = "") => {
|
|
4893
4981
|
const match = String(rawValue || "").match(/(?:Chrome|Chromium)(?:\/|\s+(?:for Testing\s+)?)(\d+)/i);
|
|
4894
4982
|
return match ? Number(match[1] || 0) : 0;
|
|
@@ -4918,7 +5006,7 @@ var detectBrowserMajorVersion = (launcher) => {
|
|
|
4918
5006
|
});
|
|
4919
5007
|
detectedVersion = parseChromeMajorVersion(rawVersion);
|
|
4920
5008
|
} catch (error) {
|
|
4921
|
-
|
|
5009
|
+
logger8.warn(`\u8BFB\u53D6\u6D4F\u89C8\u5668\u7248\u672C\u5931\u8D25: ${error?.message || error}`);
|
|
4922
5010
|
}
|
|
4923
5011
|
browserMajorVersionCache.set(executablePath, detectedVersion);
|
|
4924
5012
|
return detectedVersion;
|
|
@@ -4955,7 +5043,7 @@ var generateFingerprintForCore = ({ locale, browserMajorVersion, device }) => {
|
|
|
4955
5043
|
if (requestedBrowserMajorVersion <= 0) {
|
|
4956
5044
|
throw error;
|
|
4957
5045
|
}
|
|
4958
|
-
|
|
5046
|
+
logger8.warn(
|
|
4959
5047
|
`\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}`
|
|
4960
5048
|
);
|
|
4961
5049
|
}
|
|
@@ -5000,7 +5088,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
|
|
|
5000
5088
|
schema_version: DEFAULT_BROWSER_PROFILE_SCHEMA_VERSION
|
|
5001
5089
|
};
|
|
5002
5090
|
nextState = RuntimeEnv.setBrowserProfileCore(nextState, browserProfileCore);
|
|
5003
|
-
|
|
5091
|
+
logger8.info(
|
|
5004
5092
|
`\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}`
|
|
5005
5093
|
);
|
|
5006
5094
|
return { runtimeState: nextState, browserProfileCore };
|
|
@@ -5101,13 +5189,12 @@ var DefaultLaunch = {
|
|
|
5101
5189
|
runtimeState = null
|
|
5102
5190
|
} = normalizedOptions;
|
|
5103
5191
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5104
|
-
const
|
|
5105
|
-
const
|
|
5106
|
-
const
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
}
|
|
5192
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5193
|
+
const traffic = resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5194
|
+
const trafficHook = createLaunchTrafficHook({
|
|
5195
|
+
...traffic,
|
|
5196
|
+
enabled: enableByPassLogger
|
|
5197
|
+
});
|
|
5111
5198
|
const replayContext = buildReplayableBrowserProfile(runtimeState, launcher);
|
|
5112
5199
|
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
5113
5200
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
@@ -5118,30 +5205,14 @@ var DefaultLaunch = {
|
|
|
5118
5205
|
],
|
|
5119
5206
|
ignoreDefaultArgs: ["--enable-automation"]
|
|
5120
5207
|
};
|
|
5121
|
-
if (launchProxy) {
|
|
5122
|
-
launchOptions.proxy = launchProxy;
|
|
5123
|
-
}
|
|
5124
|
-
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5125
|
-
if (enableByPassLogger && launchProxy) {
|
|
5126
|
-
let upstreamLabel = "";
|
|
5127
|
-
try {
|
|
5128
|
-
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5129
|
-
upstreamLabel = `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`;
|
|
5130
|
-
} catch {
|
|
5131
|
-
}
|
|
5132
|
-
logger7.info(
|
|
5133
|
-
`[\u4EE3\u7406\u5DF2\u542F\u7528] \u672C\u5730=${launchProxy.server} \u4E0A\u6E38=${upstreamLabel || "-"} \u76F4\u8FDE\u57DF\u540D=${(byPassDomains || []).join(",")}`
|
|
5134
|
-
);
|
|
5135
|
-
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`);
|
|
5136
|
-
} else if (enableByPassLogger && enableProxy && !launchProxy) {
|
|
5137
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=true \u4F46 proxy_url \u4E3A\u7A7A");
|
|
5138
|
-
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`);
|
|
5139
|
-
} else if (enableByPassLogger && !enableProxy && proxyUrl) {
|
|
5140
|
-
logger7.info("[\u4EE3\u7406\u672A\u542F\u7528] enable_proxy=false \u4E14 proxy_url \u5DF2\u914D\u7F6E");
|
|
5141
|
-
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`);
|
|
5142
|
-
} else if (enableByPassLogger) {
|
|
5143
|
-
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`);
|
|
5208
|
+
if (traffic.launchProxy) {
|
|
5209
|
+
launchOptions.proxy = traffic.launchProxy;
|
|
5144
5210
|
}
|
|
5211
|
+
logLaunchTraffic({
|
|
5212
|
+
...traffic,
|
|
5213
|
+
debugMode,
|
|
5214
|
+
enabled: enableByPassLogger
|
|
5215
|
+
});
|
|
5145
5216
|
const onPageCreated = (page) => {
|
|
5146
5217
|
const recommendedGotoOptions = {
|
|
5147
5218
|
waitUntil: "commit"
|
|
@@ -5149,22 +5220,7 @@ var DefaultLaunch = {
|
|
|
5149
5220
|
if (!page || typeof page.on !== "function") {
|
|
5150
5221
|
return recommendedGotoOptions;
|
|
5151
5222
|
}
|
|
5152
|
-
|
|
5153
|
-
return recommendedGotoOptions;
|
|
5154
|
-
}
|
|
5155
|
-
page[REQUEST_HOOK_FLAG] = true;
|
|
5156
|
-
const requestHandler = (req) => {
|
|
5157
|
-
const requestUrl = req.url();
|
|
5158
|
-
const resourceType = req.resourceType();
|
|
5159
|
-
const matched = byPassDomains.length > 0 ? ByPass.findMatchedByPassRule(byPassRules, requestUrl) : null;
|
|
5160
|
-
if (launchProxy) {
|
|
5161
|
-
ProxyMeterRuntime.recordProxyMeterResourceType(requestUrl, resourceType);
|
|
5162
|
-
}
|
|
5163
|
-
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
5164
|
-
if (!matched || !matched.rule) return;
|
|
5165
|
-
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}`);
|
|
5166
|
-
};
|
|
5167
|
-
page.on("request", requestHandler);
|
|
5223
|
+
trafficHook(page);
|
|
5168
5224
|
return recommendedGotoOptions;
|
|
5169
5225
|
};
|
|
5170
5226
|
const launchContext = {
|
|
@@ -5219,7 +5275,7 @@ var DefaultLaunch = {
|
|
|
5219
5275
|
// src/internals/launch/cloak.js
|
|
5220
5276
|
var import_node_child_process2 = require("node:child_process");
|
|
5221
5277
|
var import_node_util = require("node:util");
|
|
5222
|
-
var
|
|
5278
|
+
var logger9 = createInternalLogger("Launch");
|
|
5223
5279
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5224
5280
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5225
5281
|
maxConcurrency: 1,
|
|
@@ -5248,9 +5304,9 @@ var loadCloakModule = async () => {
|
|
|
5248
5304
|
};
|
|
5249
5305
|
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5250
5306
|
const { buildLaunchOptions } = await loadCloakModule();
|
|
5251
|
-
return await buildLaunchOptions(
|
|
5307
|
+
return await buildLaunchOptions(normalizeObject2(options));
|
|
5252
5308
|
};
|
|
5253
|
-
var
|
|
5309
|
+
var normalizeObject2 = (value) => {
|
|
5254
5310
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5255
5311
|
return {};
|
|
5256
5312
|
}
|
|
@@ -5263,7 +5319,7 @@ var normalizeStringArray = (value) => {
|
|
|
5263
5319
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5264
5320
|
};
|
|
5265
5321
|
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5266
|
-
const config =
|
|
5322
|
+
const config = normalizeObject2(proxyConfiguration);
|
|
5267
5323
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5268
5324
|
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5269
5325
|
if (!enableProxy || !proxyUrl) {
|
|
@@ -5286,7 +5342,7 @@ var extractFingerprintArg = (launchOptions = {}) => {
|
|
|
5286
5342
|
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5287
5343
|
};
|
|
5288
5344
|
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5289
|
-
const normalizedRecommendedGotoOptions =
|
|
5345
|
+
const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
|
|
5290
5346
|
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5291
5347
|
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5292
5348
|
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
@@ -5302,11 +5358,11 @@ var attachCloakHumanizeHook = ({
|
|
|
5302
5358
|
patchedBrowsers,
|
|
5303
5359
|
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5304
5360
|
} = {}) => {
|
|
5305
|
-
const normalizedBrowserPoolOptions =
|
|
5361
|
+
const normalizedBrowserPoolOptions = normalizeObject2(browserPoolOptions);
|
|
5306
5362
|
const shouldHumanize = humanizeOptions !== false;
|
|
5307
5363
|
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5308
5364
|
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5309
|
-
...
|
|
5365
|
+
...normalizeObject2(humanizeOptions)
|
|
5310
5366
|
} : null;
|
|
5311
5367
|
return {
|
|
5312
5368
|
...normalizedBrowserPoolOptions,
|
|
@@ -5355,7 +5411,7 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5355
5411
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5356
5412
|
return;
|
|
5357
5413
|
}
|
|
5358
|
-
|
|
5414
|
+
logger9.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5359
5415
|
});
|
|
5360
5416
|
};
|
|
5361
5417
|
var CloakLaunch = {
|
|
@@ -5389,9 +5445,11 @@ var CloakLaunch = {
|
|
|
5389
5445
|
return await buildCloakLaunchOptions(options);
|
|
5390
5446
|
},
|
|
5391
5447
|
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5392
|
-
const normalizedOptions =
|
|
5448
|
+
const normalizedOptions = normalizeObject2(options);
|
|
5393
5449
|
const {
|
|
5394
5450
|
proxyConfiguration = {},
|
|
5451
|
+
log: logOptions = null,
|
|
5452
|
+
debugMode = false,
|
|
5395
5453
|
runInHeadfulMode = false,
|
|
5396
5454
|
isRunningOnApify = false,
|
|
5397
5455
|
launcher = null,
|
|
@@ -5404,13 +5462,16 @@ var CloakLaunch = {
|
|
|
5404
5462
|
postNavigationHooks = [],
|
|
5405
5463
|
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5406
5464
|
} = normalizedOptions;
|
|
5407
|
-
const normalizedCloakOptions =
|
|
5465
|
+
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5408
5466
|
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5409
5467
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5410
5468
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5411
5469
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5412
|
-
const
|
|
5470
|
+
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5471
|
+
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5472
|
+
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
5413
5473
|
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5474
|
+
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5414
5475
|
const mergedCloakOptions = {
|
|
5415
5476
|
...normalizedCloakOptions,
|
|
5416
5477
|
headless,
|
|
@@ -5420,15 +5481,27 @@ var CloakLaunch = {
|
|
|
5420
5481
|
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5421
5482
|
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5422
5483
|
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5484
|
+
const trafficHook = createLaunchTrafficHook({
|
|
5485
|
+
byPassDomains: proxyLaunchState.byPassDomains,
|
|
5486
|
+
byPassRules: proxyLaunchState.byPassRules,
|
|
5487
|
+
enabled: enableByPassLogger,
|
|
5488
|
+
launchProxy: proxyLaunchState.launchProxy
|
|
5489
|
+
});
|
|
5423
5490
|
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5424
5491
|
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5492
|
+
logLaunchTraffic({
|
|
5493
|
+
...proxyLaunchState,
|
|
5494
|
+
debugMode,
|
|
5495
|
+
enabled: enableByPassLogger,
|
|
5496
|
+
explicitProxy: hasExplicitProxy
|
|
5497
|
+
});
|
|
5425
5498
|
const crawlerOptions = {
|
|
5426
5499
|
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5427
|
-
...
|
|
5500
|
+
...normalizeObject2(crawlerBaseOptions),
|
|
5428
5501
|
headless,
|
|
5429
5502
|
launchContext: {
|
|
5430
5503
|
useIncognitoPages: true,
|
|
5431
|
-
...
|
|
5504
|
+
...normalizeObject2(launchContext),
|
|
5432
5505
|
...launcher ? { launcher } : {},
|
|
5433
5506
|
launchOptions
|
|
5434
5507
|
},
|
|
@@ -5438,7 +5511,13 @@ var CloakLaunch = {
|
|
|
5438
5511
|
patchedBrowsers,
|
|
5439
5512
|
humanizeOptions
|
|
5440
5513
|
}),
|
|
5441
|
-
preNavigationHooks: [
|
|
5514
|
+
preNavigationHooks: [
|
|
5515
|
+
async (crawlingContext, gotoOptions = {}) => {
|
|
5516
|
+
trafficHook(crawlingContext?.page);
|
|
5517
|
+
await internalPreNavigationHook(crawlingContext, gotoOptions);
|
|
5518
|
+
},
|
|
5519
|
+
...normalizedPreNavigationHooks
|
|
5520
|
+
],
|
|
5442
5521
|
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5443
5522
|
};
|
|
5444
5523
|
const closeActiveBrowsers = async () => {
|
|
@@ -5473,7 +5552,7 @@ var Launch = withModeReflect("Launch", launchStrategies);
|
|
|
5473
5552
|
// src/live-view.js
|
|
5474
5553
|
var import_express = __toESM(require("express"), 1);
|
|
5475
5554
|
var import_apify = require("apify");
|
|
5476
|
-
var
|
|
5555
|
+
var logger10 = createInternalLogger("LiveView");
|
|
5477
5556
|
async function startLiveViewServer(liveViewKey) {
|
|
5478
5557
|
const app = (0, import_express.default)();
|
|
5479
5558
|
app.get("/", async (req, res) => {
|
|
@@ -5498,13 +5577,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5498
5577
|
</html>
|
|
5499
5578
|
`);
|
|
5500
5579
|
} catch (error) {
|
|
5501
|
-
|
|
5580
|
+
logger10.fail("Live View Server", error);
|
|
5502
5581
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5503
5582
|
}
|
|
5504
5583
|
});
|
|
5505
5584
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5506
5585
|
app.listen(port, () => {
|
|
5507
|
-
|
|
5586
|
+
logger10.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5508
5587
|
});
|
|
5509
5588
|
}
|
|
5510
5589
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5512,10 +5591,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5512
5591
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5513
5592
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5514
5593
|
if (logMessage) {
|
|
5515
|
-
|
|
5594
|
+
logger10.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5516
5595
|
}
|
|
5517
5596
|
} catch (e) {
|
|
5518
|
-
|
|
5597
|
+
logger10.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5519
5598
|
}
|
|
5520
5599
|
}
|
|
5521
5600
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5624,7 +5703,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5624
5703
|
};
|
|
5625
5704
|
|
|
5626
5705
|
// src/internals/captcha/bytedance.js
|
|
5627
|
-
var
|
|
5706
|
+
var logger11 = createInternalLogger("Captcha");
|
|
5628
5707
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5629
5708
|
apiType: "31234",
|
|
5630
5709
|
maxRetries: 3,
|
|
@@ -5756,7 +5835,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5756
5835
|
}
|
|
5757
5836
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5758
5837
|
}
|
|
5759
|
-
|
|
5838
|
+
logger11.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5760
5839
|
};
|
|
5761
5840
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5762
5841
|
if (!options.debugArtifacts) {
|
|
@@ -5793,14 +5872,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5793
5872
|
if (!isContainerVisible) {
|
|
5794
5873
|
return null;
|
|
5795
5874
|
}
|
|
5796
|
-
|
|
5875
|
+
logger11.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5797
5876
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5798
5877
|
let isIframeVisible = await waitForVisible(
|
|
5799
5878
|
iframeLocator,
|
|
5800
5879
|
options.iframeVisibleTimeoutMs
|
|
5801
5880
|
);
|
|
5802
5881
|
if (!isIframeVisible) {
|
|
5803
|
-
|
|
5882
|
+
logger11.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5804
5883
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5805
5884
|
isIframeVisible = await waitForVisible(
|
|
5806
5885
|
iframeLocator,
|
|
@@ -5810,7 +5889,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5810
5889
|
if (!isIframeVisible) {
|
|
5811
5890
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5812
5891
|
}
|
|
5813
|
-
|
|
5892
|
+
logger11.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5814
5893
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5815
5894
|
if (!frame) {
|
|
5816
5895
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -5926,11 +6005,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
5926
6005
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
5927
6006
|
...options,
|
|
5928
6007
|
page,
|
|
5929
|
-
logger:
|
|
6008
|
+
logger: logger11,
|
|
5930
6009
|
forceMouse: true
|
|
5931
6010
|
}).catch(() => false);
|
|
5932
6011
|
if (!clicked) {
|
|
5933
|
-
|
|
6012
|
+
logger11.warn("Refresh button not found.");
|
|
5934
6013
|
return false;
|
|
5935
6014
|
}
|
|
5936
6015
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -5961,24 +6040,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
5961
6040
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
5962
6041
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
5963
6042
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
5964
|
-
|
|
6043
|
+
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");
|
|
5965
6044
|
hasLoggedGuideMask = true;
|
|
5966
6045
|
}
|
|
5967
6046
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
5968
|
-
|
|
6047
|
+
logger11.info(
|
|
5969
6048
|
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"
|
|
5970
6049
|
);
|
|
5971
6050
|
return;
|
|
5972
6051
|
}
|
|
5973
6052
|
if (hasErrorTextVisible) {
|
|
5974
|
-
|
|
6053
|
+
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");
|
|
5975
6054
|
await refreshCaptcha(page, frame, options);
|
|
5976
6055
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5977
6056
|
hasSeenLoading = false;
|
|
5978
6057
|
continue;
|
|
5979
6058
|
}
|
|
5980
6059
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
5981
|
-
|
|
6060
|
+
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`);
|
|
5982
6061
|
await refreshCaptcha(page, frame, options);
|
|
5983
6062
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5984
6063
|
hasSeenLoading = false;
|
|
@@ -6026,7 +6105,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6026
6105
|
accepted
|
|
6027
6106
|
};
|
|
6028
6107
|
dragAttempts.push(attemptInfo);
|
|
6029
|
-
|
|
6108
|
+
logger11.info(
|
|
6030
6109
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
6031
6110
|
);
|
|
6032
6111
|
if (accepted) {
|
|
@@ -6044,7 +6123,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
6044
6123
|
dragAttempts,
|
|
6045
6124
|
finalState: await readPromptCaptchaState(frame, options)
|
|
6046
6125
|
}).catch((error) => {
|
|
6047
|
-
|
|
6126
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6048
6127
|
});
|
|
6049
6128
|
return {
|
|
6050
6129
|
accepted: false,
|
|
@@ -6061,16 +6140,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6061
6140
|
...options
|
|
6062
6141
|
};
|
|
6063
6142
|
if (!config.token) {
|
|
6064
|
-
|
|
6143
|
+
logger11.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
6065
6144
|
return false;
|
|
6066
6145
|
}
|
|
6067
|
-
|
|
6146
|
+
logger11.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
6068
6147
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
6069
|
-
|
|
6148
|
+
logger11.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
6070
6149
|
try {
|
|
6071
6150
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
6072
6151
|
if (!captchaContext) {
|
|
6073
|
-
|
|
6152
|
+
logger11.info("Captcha container is not visible anymore.");
|
|
6074
6153
|
return true;
|
|
6075
6154
|
}
|
|
6076
6155
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -6083,7 +6162,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6083
6162
|
"ready",
|
|
6084
6163
|
config
|
|
6085
6164
|
).catch((error) => {
|
|
6086
|
-
|
|
6165
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6087
6166
|
});
|
|
6088
6167
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
6089
6168
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -6095,16 +6174,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6095
6174
|
});
|
|
6096
6175
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
6097
6176
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
6098
|
-
|
|
6177
|
+
logger11.warn(
|
|
6099
6178
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
6100
6179
|
);
|
|
6101
6180
|
await refreshCaptcha(page, frame, config);
|
|
6102
6181
|
continue;
|
|
6103
6182
|
}
|
|
6104
|
-
|
|
6183
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
6105
6184
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
6106
6185
|
if (!dropTarget) {
|
|
6107
|
-
|
|
6186
|
+
logger11.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
6108
6187
|
await refreshCaptcha(page, frame, config);
|
|
6109
6188
|
continue;
|
|
6110
6189
|
}
|
|
@@ -6115,7 +6194,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6115
6194
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
6116
6195
|
);
|
|
6117
6196
|
}
|
|
6118
|
-
|
|
6197
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
6119
6198
|
for (const imageIndex of normalizedIndexes) {
|
|
6120
6199
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
6121
6200
|
throw new Error(
|
|
@@ -6147,52 +6226,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
6147
6226
|
}
|
|
6148
6227
|
}
|
|
6149
6228
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
6150
|
-
|
|
6229
|
+
logger11.info(
|
|
6151
6230
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
6152
6231
|
);
|
|
6153
6232
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
6154
6233
|
...config,
|
|
6155
6234
|
page,
|
|
6156
|
-
logger:
|
|
6235
|
+
logger: logger11,
|
|
6157
6236
|
forceMouse: true,
|
|
6158
6237
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
6159
6238
|
}).catch(() => false);
|
|
6160
6239
|
if (!submitted) {
|
|
6161
|
-
|
|
6240
|
+
logger11.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
6162
6241
|
}
|
|
6163
6242
|
await page.waitForTimeout(config.submitWaitMs);
|
|
6164
6243
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
6165
|
-
|
|
6244
|
+
logger11.info(
|
|
6166
6245
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
6167
6246
|
);
|
|
6168
6247
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
6169
6248
|
if (!stillVisible) {
|
|
6170
|
-
|
|
6249
|
+
logger11.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
6171
6250
|
return true;
|
|
6172
6251
|
}
|
|
6173
6252
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
6174
6253
|
beforeSubmitState,
|
|
6175
6254
|
afterSubmitState
|
|
6176
6255
|
}).catch((error) => {
|
|
6177
|
-
|
|
6256
|
+
logger11.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6178
6257
|
});
|
|
6179
|
-
|
|
6258
|
+
logger11.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
6180
6259
|
await page.waitForTimeout(2e3);
|
|
6181
6260
|
await refreshCaptcha(page, frame, config);
|
|
6182
6261
|
} catch (error) {
|
|
6183
|
-
|
|
6262
|
+
logger11.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
6184
6263
|
}
|
|
6185
6264
|
if (attempt < config.maxRetries) {
|
|
6186
6265
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
6187
6266
|
}
|
|
6188
6267
|
}
|
|
6189
|
-
|
|
6268
|
+
logger11.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
6190
6269
|
return false;
|
|
6191
6270
|
}
|
|
6192
6271
|
var sloveCaptcha = solveCaptcha;
|
|
6193
6272
|
|
|
6194
6273
|
// src/chaptcha.js
|
|
6195
|
-
var
|
|
6274
|
+
var logger12 = createInternalLogger("Captcha");
|
|
6196
6275
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
6197
6276
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
6198
6277
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -6279,7 +6358,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6279
6358
|
};
|
|
6280
6359
|
})();
|
|
6281
6360
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6282
|
-
|
|
6361
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6283
6362
|
cleanupFns.push(async () => {
|
|
6284
6363
|
try {
|
|
6285
6364
|
await page.evaluate((name) => {
|
|
@@ -6303,14 +6382,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
6303
6382
|
}
|
|
6304
6383
|
};
|
|
6305
6384
|
page.on("framenavigated", frameHandler);
|
|
6306
|
-
|
|
6385
|
+
logger12.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
6307
6386
|
cleanupFns.push(async () => {
|
|
6308
6387
|
page.off("framenavigated", frameHandler);
|
|
6309
6388
|
});
|
|
6310
6389
|
}
|
|
6311
6390
|
return {
|
|
6312
6391
|
stop: async () => {
|
|
6313
|
-
|
|
6392
|
+
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6314
6393
|
for (const fn of cleanupFns) {
|
|
6315
6394
|
await fn();
|
|
6316
6395
|
}
|
|
@@ -6349,7 +6428,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
6349
6428
|
);
|
|
6350
6429
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
6351
6430
|
callCaptchaRecognitionApi,
|
|
6352
|
-
logger:
|
|
6431
|
+
logger: logger12
|
|
6353
6432
|
});
|
|
6354
6433
|
}
|
|
6355
6434
|
var Captcha = {
|
|
@@ -6360,7 +6439,7 @@ var Captcha = {
|
|
|
6360
6439
|
// src/mutation.js
|
|
6361
6440
|
var import_node_crypto = require("node:crypto");
|
|
6362
6441
|
var import_uuid2 = require("uuid");
|
|
6363
|
-
var
|
|
6442
|
+
var logger13 = createInternalLogger("Mutation");
|
|
6364
6443
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
6365
6444
|
Added: "added",
|
|
6366
6445
|
Changed: "changed",
|
|
@@ -6393,14 +6472,14 @@ var Mutation = {
|
|
|
6393
6472
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
6394
6473
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
6395
6474
|
const onMutation = options.onMutation;
|
|
6396
|
-
|
|
6475
|
+
logger13.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
6397
6476
|
if (initialTimeout > 0) {
|
|
6398
6477
|
const selectorQuery = selectorList.join(",");
|
|
6399
6478
|
try {
|
|
6400
6479
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6401
|
-
|
|
6480
|
+
logger13.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6402
6481
|
} catch (e) {
|
|
6403
|
-
|
|
6482
|
+
logger13.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6404
6483
|
throw e;
|
|
6405
6484
|
}
|
|
6406
6485
|
}
|
|
@@ -6416,7 +6495,7 @@ var Mutation = {
|
|
|
6416
6495
|
return "__CONTINUE__";
|
|
6417
6496
|
}
|
|
6418
6497
|
});
|
|
6419
|
-
|
|
6498
|
+
logger13.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6420
6499
|
} catch (e) {
|
|
6421
6500
|
}
|
|
6422
6501
|
}
|
|
@@ -6531,9 +6610,9 @@ var Mutation = {
|
|
|
6531
6610
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6532
6611
|
);
|
|
6533
6612
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6534
|
-
|
|
6613
|
+
logger13.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6535
6614
|
}
|
|
6536
|
-
|
|
6615
|
+
logger13.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6537
6616
|
return result;
|
|
6538
6617
|
},
|
|
6539
6618
|
/**
|
|
@@ -6705,22 +6784,22 @@ var Mutation = {
|
|
|
6705
6784
|
return "__CONTINUE__";
|
|
6706
6785
|
}
|
|
6707
6786
|
};
|
|
6708
|
-
|
|
6787
|
+
logger13.start(
|
|
6709
6788
|
"waitForStableAcrossRoots",
|
|
6710
6789
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6711
6790
|
);
|
|
6712
6791
|
if (initialTimeout > 0) {
|
|
6713
6792
|
try {
|
|
6714
6793
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6715
|
-
|
|
6794
|
+
logger13.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6716
6795
|
} catch (e) {
|
|
6717
|
-
|
|
6796
|
+
logger13.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6718
6797
|
throw e;
|
|
6719
6798
|
}
|
|
6720
6799
|
}
|
|
6721
6800
|
let state2 = await buildState();
|
|
6722
6801
|
if (!state2?.hasMatched) {
|
|
6723
|
-
|
|
6802
|
+
logger13.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6724
6803
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6725
6804
|
}
|
|
6726
6805
|
let mutationCount = 0;
|
|
@@ -6757,7 +6836,7 @@ var Mutation = {
|
|
|
6757
6836
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6758
6837
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6759
6838
|
mutationCount += 1;
|
|
6760
|
-
|
|
6839
|
+
logger13.info(
|
|
6761
6840
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6762
6841
|
);
|
|
6763
6842
|
const signal = await invokeMutationCallback({
|
|
@@ -6770,7 +6849,7 @@ var Mutation = {
|
|
|
6770
6849
|
continue;
|
|
6771
6850
|
}
|
|
6772
6851
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6773
|
-
|
|
6852
|
+
logger13.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6774
6853
|
return {
|
|
6775
6854
|
mutationCount,
|
|
6776
6855
|
stableTime: waitForStableTime,
|
|
@@ -6797,7 +6876,7 @@ var Mutation = {
|
|
|
6797
6876
|
const onMutation = options.onMutation;
|
|
6798
6877
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6799
6878
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6800
|
-
|
|
6879
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6801
6880
|
const monitorKey = generateKey("pk_mon");
|
|
6802
6881
|
const callbackName = generateKey("pk_mon_cb");
|
|
6803
6882
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6940,7 +7019,7 @@ var Mutation = {
|
|
|
6940
7019
|
return total;
|
|
6941
7020
|
};
|
|
6942
7021
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
6943
|
-
|
|
7022
|
+
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
6944
7023
|
return {
|
|
6945
7024
|
stop: async () => {
|
|
6946
7025
|
let totalMutations = 0;
|
|
@@ -6953,7 +7032,7 @@ var Mutation = {
|
|
|
6953
7032
|
}, cleanerName);
|
|
6954
7033
|
} catch (e) {
|
|
6955
7034
|
}
|
|
6956
|
-
|
|
7035
|
+
logger13.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
6957
7036
|
return { totalMutations };
|
|
6958
7037
|
}
|
|
6959
7038
|
};
|
|
@@ -7822,7 +7901,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7822
7901
|
};
|
|
7823
7902
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7824
7903
|
var Logger = {
|
|
7825
|
-
setLogger: (
|
|
7904
|
+
setLogger: (logger17) => setDefaultLogger(logger17),
|
|
7826
7905
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7827
7906
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7828
7907
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7830,8 +7909,8 @@ var Logger = {
|
|
|
7830
7909
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7831
7910
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7832
7911
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7833
|
-
useTemplate: (
|
|
7834
|
-
if (
|
|
7912
|
+
useTemplate: (logger17) => {
|
|
7913
|
+
if (logger17) return createTemplateLogger(createBaseLogger("", logger17));
|
|
7835
7914
|
return createTemplateLogger();
|
|
7836
7915
|
}
|
|
7837
7916
|
};
|
|
@@ -7905,7 +7984,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
7905
7984
|
];
|
|
7906
7985
|
var cachedStripLogoSrcPromise = null;
|
|
7907
7986
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
7908
|
-
var
|
|
7987
|
+
var logger14 = createInternalLogger("Watermarkify");
|
|
7909
7988
|
var normalizeText = (value) => String(value || "").trim();
|
|
7910
7989
|
var toInline = (value, maxLen = 200) => {
|
|
7911
7990
|
const text = normalizeText(value);
|
|
@@ -8147,9 +8226,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
8147
8226
|
location: toInline(resolved.location, 80)
|
|
8148
8227
|
};
|
|
8149
8228
|
if (enrichment.ip || enrichment.location) {
|
|
8150
|
-
|
|
8229
|
+
logger14.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
8151
8230
|
} else {
|
|
8152
|
-
|
|
8231
|
+
logger14.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
8153
8232
|
}
|
|
8154
8233
|
return enrichment;
|
|
8155
8234
|
} finally {
|
|
@@ -8338,12 +8417,12 @@ var normalizeWatermarkifyRenderMode = (value) => {
|
|
|
8338
8417
|
};
|
|
8339
8418
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8340
8419
|
if (!page || typeof page.context !== "function") {
|
|
8341
|
-
|
|
8420
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
8342
8421
|
return buffer;
|
|
8343
8422
|
}
|
|
8344
8423
|
const renderScope = await openProbePage(page);
|
|
8345
8424
|
if (!renderScope?.page) {
|
|
8346
|
-
|
|
8425
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
8347
8426
|
return buffer;
|
|
8348
8427
|
}
|
|
8349
8428
|
try {
|
|
@@ -8408,13 +8487,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8408
8487
|
fullPage: true,
|
|
8409
8488
|
animations: "disabled"
|
|
8410
8489
|
}).catch((error) => {
|
|
8411
|
-
|
|
8490
|
+
logger14.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
8412
8491
|
return null;
|
|
8413
8492
|
});
|
|
8414
8493
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
8415
8494
|
return composed;
|
|
8416
8495
|
}
|
|
8417
|
-
|
|
8496
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
8418
8497
|
return buffer;
|
|
8419
8498
|
} finally {
|
|
8420
8499
|
await renderScope.close().catch(() => {
|
|
@@ -8427,7 +8506,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8427
8506
|
}
|
|
8428
8507
|
const probeScope = await openProbePage(page);
|
|
8429
8508
|
if (!probeScope?.page) {
|
|
8430
|
-
|
|
8509
|
+
logger14.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
8431
8510
|
return null;
|
|
8432
8511
|
}
|
|
8433
8512
|
const timeoutMs = Math.max(
|
|
@@ -8436,12 +8515,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8436
8515
|
);
|
|
8437
8516
|
try {
|
|
8438
8517
|
const probePage = probeScope.page;
|
|
8439
|
-
|
|
8518
|
+
logger14.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8440
8519
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8441
8520
|
waitUntil: "commit",
|
|
8442
8521
|
timeout: timeoutMs
|
|
8443
8522
|
}).catch((error) => {
|
|
8444
|
-
|
|
8523
|
+
logger14.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8445
8524
|
return null;
|
|
8446
8525
|
});
|
|
8447
8526
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8463,13 +8542,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8463
8542
|
}
|
|
8464
8543
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8465
8544
|
if (parsed?.ip || parsed?.location) {
|
|
8466
|
-
|
|
8545
|
+
logger14.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8467
8546
|
return parsed;
|
|
8468
8547
|
}
|
|
8469
|
-
|
|
8548
|
+
logger14.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8470
8549
|
return null;
|
|
8471
8550
|
} catch (error) {
|
|
8472
|
-
|
|
8551
|
+
logger14.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8473
8552
|
return null;
|
|
8474
8553
|
} finally {
|
|
8475
8554
|
await probeScope.close().catch(() => {
|
|
@@ -8483,10 +8562,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8483
8562
|
ip: toInline(options.ip, 80),
|
|
8484
8563
|
location: toInline(options.location, 80)
|
|
8485
8564
|
};
|
|
8486
|
-
|
|
8565
|
+
logger14.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8487
8566
|
if (!merged.ip || !merged.location) {
|
|
8488
8567
|
if (cached?.ip || cached?.location) {
|
|
8489
|
-
|
|
8568
|
+
logger14.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8490
8569
|
}
|
|
8491
8570
|
fillEnrichment(merged, cached);
|
|
8492
8571
|
}
|
|
@@ -8510,15 +8589,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8510
8589
|
"x-geo-country"
|
|
8511
8590
|
]), 80);
|
|
8512
8591
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8513
|
-
|
|
8592
|
+
logger14.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8514
8593
|
merged.location = headerLocation || merged.location;
|
|
8515
8594
|
}
|
|
8516
8595
|
}
|
|
8517
8596
|
writeCachedEnrichment(page, merged);
|
|
8518
8597
|
if (merged.ip || merged.location) {
|
|
8519
|
-
|
|
8598
|
+
logger14.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8520
8599
|
} else {
|
|
8521
|
-
|
|
8600
|
+
logger14.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8522
8601
|
}
|
|
8523
8602
|
return merged;
|
|
8524
8603
|
};
|
|
@@ -9331,7 +9410,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9331
9410
|
}
|
|
9332
9411
|
const imageInfo = readImageInfo(buffer);
|
|
9333
9412
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
9334
|
-
|
|
9413
|
+
logger14.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
9335
9414
|
return buffer;
|
|
9336
9415
|
}
|
|
9337
9416
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -9349,7 +9428,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {
|
|
|
9349
9428
|
|
|
9350
9429
|
// src/internals/compression.js
|
|
9351
9430
|
var import_jimp = require("jimp");
|
|
9352
|
-
var
|
|
9431
|
+
var logger15 = createInternalLogger("Compression");
|
|
9353
9432
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
9354
9433
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
9355
9434
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9468,18 +9547,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9468
9547
|
return buffer.toString("base64");
|
|
9469
9548
|
}
|
|
9470
9549
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9471
|
-
|
|
9550
|
+
logger15.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9472
9551
|
return null;
|
|
9473
9552
|
});
|
|
9474
9553
|
if (!result?.buffer) {
|
|
9475
9554
|
return buffer.toString("base64");
|
|
9476
9555
|
}
|
|
9477
9556
|
if (result.withinLimit) {
|
|
9478
|
-
|
|
9557
|
+
logger15.info(
|
|
9479
9558
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9480
9559
|
);
|
|
9481
9560
|
} else {
|
|
9482
|
-
|
|
9561
|
+
logger15.warning(
|
|
9483
9562
|
`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}`
|
|
9484
9563
|
);
|
|
9485
9564
|
}
|
|
@@ -9487,7 +9566,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9487
9566
|
};
|
|
9488
9567
|
|
|
9489
9568
|
// src/share.js
|
|
9490
|
-
var
|
|
9569
|
+
var logger16 = createInternalLogger("Share");
|
|
9491
9570
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9492
9571
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9493
9572
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9624,7 +9703,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9624
9703
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9625
9704
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9626
9705
|
let matched = false;
|
|
9627
|
-
|
|
9706
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9628
9707
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9629
9708
|
mode,
|
|
9630
9709
|
onMutation: (context = {}) => {
|
|
@@ -9642,12 +9721,12 @@ ${text}`;
|
|
|
9642
9721
|
});
|
|
9643
9722
|
}
|
|
9644
9723
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9645
|
-
|
|
9724
|
+
logger16.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9646
9725
|
}
|
|
9647
9726
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9648
9727
|
if (!candidate) return;
|
|
9649
9728
|
matched = true;
|
|
9650
|
-
|
|
9729
|
+
logger16.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9651
9730
|
if (onMatch) {
|
|
9652
9731
|
onMatch({
|
|
9653
9732
|
link: candidate,
|
|
@@ -9663,7 +9742,7 @@ ${text}`;
|
|
|
9663
9742
|
return {
|
|
9664
9743
|
stop: async () => {
|
|
9665
9744
|
const result = await monitor.stop();
|
|
9666
|
-
|
|
9745
|
+
logger16.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9667
9746
|
return result;
|
|
9668
9747
|
}
|
|
9669
9748
|
};
|
|
@@ -9712,8 +9791,8 @@ var Share = {
|
|
|
9712
9791
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9713
9792
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9714
9793
|
}
|
|
9715
|
-
|
|
9716
|
-
|
|
9794
|
+
logger16.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9795
|
+
logger16.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9717
9796
|
const stats = {
|
|
9718
9797
|
actionTimedOut: false,
|
|
9719
9798
|
domMutationCount: 0,
|
|
@@ -9725,7 +9804,7 @@ var Share = {
|
|
|
9725
9804
|
responseSampleUrls: []
|
|
9726
9805
|
};
|
|
9727
9806
|
if (isAborted()) {
|
|
9728
|
-
|
|
9807
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9729
9808
|
return {
|
|
9730
9809
|
link: null,
|
|
9731
9810
|
payloadText: "",
|
|
@@ -9748,7 +9827,7 @@ var Share = {
|
|
|
9748
9827
|
link: validated,
|
|
9749
9828
|
payloadText: String(payloadText || "")
|
|
9750
9829
|
};
|
|
9751
|
-
|
|
9830
|
+
logger16.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9752
9831
|
return true;
|
|
9753
9832
|
};
|
|
9754
9833
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9783,7 +9862,7 @@ var Share = {
|
|
|
9783
9862
|
try {
|
|
9784
9863
|
await monitor.stop();
|
|
9785
9864
|
} catch (error) {
|
|
9786
|
-
|
|
9865
|
+
logger16.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9787
9866
|
}
|
|
9788
9867
|
};
|
|
9789
9868
|
const onResponse = async (response) => {
|
|
@@ -9797,29 +9876,29 @@ var Share = {
|
|
|
9797
9876
|
stats.responseSampleUrls.push(url);
|
|
9798
9877
|
}
|
|
9799
9878
|
if (stats.responseObserved <= 5) {
|
|
9800
|
-
|
|
9879
|
+
logger16.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9801
9880
|
}
|
|
9802
9881
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9803
9882
|
stats.responseMatched += 1;
|
|
9804
9883
|
stats.lastMatchedUrl = url;
|
|
9805
|
-
|
|
9884
|
+
logger16.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9806
9885
|
const text = await response.text();
|
|
9807
9886
|
const hit = resolveResponseCandidate(text);
|
|
9808
9887
|
if (!hit?.link) {
|
|
9809
9888
|
if (stats.responseMatched <= 3) {
|
|
9810
|
-
|
|
9889
|
+
logger16.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9811
9890
|
}
|
|
9812
9891
|
return;
|
|
9813
9892
|
}
|
|
9814
9893
|
stats.responseResolved += 1;
|
|
9815
|
-
|
|
9894
|
+
logger16.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9816
9895
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9817
9896
|
} catch (error) {
|
|
9818
|
-
|
|
9897
|
+
logger16.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9819
9898
|
}
|
|
9820
9899
|
};
|
|
9821
9900
|
if (share.mode === "dom") {
|
|
9822
|
-
|
|
9901
|
+
logger16.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9823
9902
|
domMonitor = await createDomShareMonitor(page, {
|
|
9824
9903
|
prefix: share.prefix,
|
|
9825
9904
|
selectors: domSelectors,
|
|
@@ -9834,17 +9913,17 @@ var Share = {
|
|
|
9834
9913
|
});
|
|
9835
9914
|
}
|
|
9836
9915
|
if (share.mode === "response") {
|
|
9837
|
-
|
|
9916
|
+
logger16.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9838
9917
|
page.on("response", onResponse);
|
|
9839
9918
|
}
|
|
9840
9919
|
if (share.mode === "custom") {
|
|
9841
|
-
|
|
9920
|
+
logger16.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9842
9921
|
}
|
|
9843
9922
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9844
9923
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9845
9924
|
try {
|
|
9846
9925
|
const actionTimeout = getRemainingMs();
|
|
9847
|
-
|
|
9926
|
+
logger16.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9848
9927
|
let actionValue;
|
|
9849
9928
|
if (!isAborted() && actionTimeout > 0) {
|
|
9850
9929
|
let timer = null;
|
|
@@ -9857,30 +9936,30 @@ var Share = {
|
|
|
9857
9936
|
]);
|
|
9858
9937
|
if (timer) clearTimeout(timer);
|
|
9859
9938
|
if (actionResult.type === "error") {
|
|
9860
|
-
|
|
9939
|
+
logger16.fail("captureLink.performActions", actionResult.error);
|
|
9861
9940
|
throw actionResult.error;
|
|
9862
9941
|
}
|
|
9863
9942
|
if (actionResult.type === "timeout") {
|
|
9864
9943
|
stats.actionTimedOut = true;
|
|
9865
|
-
|
|
9944
|
+
logger16.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9866
9945
|
} else {
|
|
9867
9946
|
actionValue = actionResult.result;
|
|
9868
|
-
|
|
9947
|
+
logger16.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9869
9948
|
}
|
|
9870
9949
|
}
|
|
9871
9950
|
if (share.mode === "custom") {
|
|
9872
9951
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9873
9952
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9874
9953
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9875
|
-
|
|
9954
|
+
logger16.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9876
9955
|
} else {
|
|
9877
|
-
|
|
9956
|
+
logger16.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9878
9957
|
}
|
|
9879
9958
|
}
|
|
9880
9959
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9881
9960
|
while (true) {
|
|
9882
9961
|
if (isAborted()) {
|
|
9883
|
-
|
|
9962
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9884
9963
|
return {
|
|
9885
9964
|
link: null,
|
|
9886
9965
|
payloadText: "",
|
|
@@ -9890,7 +9969,7 @@ var Share = {
|
|
|
9890
9969
|
}
|
|
9891
9970
|
const selected = candidates[share.mode];
|
|
9892
9971
|
if (selected?.link) {
|
|
9893
|
-
|
|
9972
|
+
logger16.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9894
9973
|
return {
|
|
9895
9974
|
link: selected.link,
|
|
9896
9975
|
payloadText: selected.payloadText,
|
|
@@ -9903,7 +9982,7 @@ var Share = {
|
|
|
9903
9982
|
if (remaining <= 0) break;
|
|
9904
9983
|
const now = Date.now();
|
|
9905
9984
|
if (now >= nextProgressLogTs) {
|
|
9906
|
-
|
|
9985
|
+
logger16.info(
|
|
9907
9986
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9908
9987
|
);
|
|
9909
9988
|
nextProgressLogTs = now + 5e3;
|
|
@@ -9911,11 +9990,11 @@ var Share = {
|
|
|
9911
9990
|
await (0, import_delay5.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9912
9991
|
}
|
|
9913
9992
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9914
|
-
|
|
9993
|
+
logger16.warning(
|
|
9915
9994
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9916
9995
|
);
|
|
9917
9996
|
}
|
|
9918
|
-
|
|
9997
|
+
logger16.warning(
|
|
9919
9998
|
`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"}`
|
|
9920
9999
|
);
|
|
9921
10000
|
return {
|
|
@@ -9927,7 +10006,7 @@ var Share = {
|
|
|
9927
10006
|
} finally {
|
|
9928
10007
|
if (share.mode === "response") {
|
|
9929
10008
|
page.off("response", onResponse);
|
|
9930
|
-
|
|
10009
|
+
logger16.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
9931
10010
|
}
|
|
9932
10011
|
await stopDomMonitor();
|
|
9933
10012
|
}
|