@skrillex1224/playwright-toolkit 2.1.273 → 2.1.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +0 -1
- package/dist/browser.js.map +2 -2
- package/dist/index.cjs +386 -134
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +386 -134
- package/dist/index.js.map +4 -4
- package/index.d.ts +46 -0
- package/package.json +7 -1
package/dist/index.cjs
CHANGED
|
@@ -221,7 +221,6 @@ var ActorInfo = {
|
|
|
221
221
|
name: "DeepSeek",
|
|
222
222
|
domain: "chat.deepseek.com",
|
|
223
223
|
path: "/",
|
|
224
|
-
device: Device.Mobile,
|
|
225
224
|
share: {
|
|
226
225
|
mode: "response",
|
|
227
226
|
prefix: "https://chat.deepseek.com/share/",
|
|
@@ -375,18 +374,18 @@ var fallbackLog = {
|
|
|
375
374
|
error: (...args) => console.error(...args),
|
|
376
375
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
377
376
|
};
|
|
378
|
-
var resolveLogMethod = (
|
|
379
|
-
if (
|
|
380
|
-
return
|
|
377
|
+
var resolveLogMethod = (logger17, name) => {
|
|
378
|
+
if (logger17 && typeof logger17[name] === "function") {
|
|
379
|
+
return logger17[name].bind(logger17);
|
|
381
380
|
}
|
|
382
|
-
if (name === "warning" &&
|
|
383
|
-
return
|
|
381
|
+
if (name === "warning" && logger17 && typeof logger17.warn === "function") {
|
|
382
|
+
return logger17.warn.bind(logger17);
|
|
384
383
|
}
|
|
385
384
|
return fallbackLog[name];
|
|
386
385
|
};
|
|
387
386
|
var defaultLogger = null;
|
|
388
|
-
var setDefaultLogger = (
|
|
389
|
-
defaultLogger =
|
|
387
|
+
var setDefaultLogger = (logger17) => {
|
|
388
|
+
defaultLogger = logger17;
|
|
390
389
|
};
|
|
391
390
|
var resolveLogger = (explicitLogger) => {
|
|
392
391
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -413,8 +412,8 @@ var colorize = (text, color) => {
|
|
|
413
412
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
414
413
|
const name = prefix ? String(prefix) : "";
|
|
415
414
|
const dispatch = (methodName, icon, message, color) => {
|
|
416
|
-
const
|
|
417
|
-
const logFn = resolveLogMethod(
|
|
415
|
+
const logger17 = resolveLogger(explicitLogger);
|
|
416
|
+
const logFn = resolveLogMethod(logger17, methodName);
|
|
418
417
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
419
418
|
const line = formatLine(name, icon, message);
|
|
420
419
|
const coloredLine = colorize(line, color);
|
|
@@ -768,7 +767,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
768
767
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
769
768
|
return 0;
|
|
770
769
|
}
|
|
771
|
-
const
|
|
770
|
+
const hasOwn2 = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
772
771
|
const isVisible = (el, style, rect) => {
|
|
773
772
|
if (!el || !style || !rect) return false;
|
|
774
773
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -808,7 +807,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
808
807
|
return true;
|
|
809
808
|
});
|
|
810
809
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
811
|
-
if (!
|
|
810
|
+
if (!hasOwn2(el.dataset, "pkAffixedAdjusted")) {
|
|
812
811
|
el.dataset.pkAffixedAdjusted = "1";
|
|
813
812
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
814
813
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -839,7 +838,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
839
838
|
};
|
|
840
839
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
841
840
|
await page.evaluate((className) => {
|
|
842
|
-
const
|
|
841
|
+
const hasOwn2 = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
843
842
|
const expansionKeys = [
|
|
844
843
|
"pkOrigOverflow",
|
|
845
844
|
"pkOrigHeight",
|
|
@@ -847,28 +846,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
847
846
|
"pkOrigMaxHeight"
|
|
848
847
|
];
|
|
849
848
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
850
|
-
if (
|
|
849
|
+
if (hasOwn2(el.dataset, "pkOrigPosition")) {
|
|
851
850
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
852
851
|
delete el.dataset.pkOrigPosition;
|
|
853
852
|
delete el.dataset.pkOrigPositionPriority;
|
|
854
853
|
}
|
|
855
|
-
if (
|
|
854
|
+
if (hasOwn2(el.dataset, "pkOrigTop")) {
|
|
856
855
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
857
856
|
delete el.dataset.pkOrigTop;
|
|
858
857
|
delete el.dataset.pkOrigTopPriority;
|
|
859
858
|
}
|
|
860
|
-
if (
|
|
859
|
+
if (hasOwn2(el.dataset, "pkOrigBottom")) {
|
|
861
860
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
862
861
|
delete el.dataset.pkOrigBottom;
|
|
863
862
|
delete el.dataset.pkOrigBottomPriority;
|
|
864
863
|
}
|
|
865
|
-
if (
|
|
864
|
+
if (hasOwn2(el.dataset, "pkOrigTranslate")) {
|
|
866
865
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
867
866
|
delete el.dataset.pkOrigTranslate;
|
|
868
867
|
delete el.dataset.pkOrigTranslatePriority;
|
|
869
868
|
}
|
|
870
869
|
delete el.dataset.pkAffixedAdjusted;
|
|
871
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
870
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn2(el.dataset, key));
|
|
872
871
|
if (!stillExpanded) {
|
|
873
872
|
el.classList.remove(className);
|
|
874
873
|
}
|
|
@@ -5056,10 +5055,261 @@ var Launch = {
|
|
|
5056
5055
|
}
|
|
5057
5056
|
};
|
|
5058
5057
|
|
|
5058
|
+
// src/cloakbrowser.js
|
|
5059
|
+
var import_node_child_process2 = require("node:child_process");
|
|
5060
|
+
var import_node_util = require("node:util");
|
|
5061
|
+
var logger9 = createInternalLogger("CloakBrowser");
|
|
5062
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5063
|
+
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5064
|
+
maxConcurrency: 1,
|
|
5065
|
+
maxRequestRetries: 0,
|
|
5066
|
+
requestHandlerTimeoutSecs: 240,
|
|
5067
|
+
navigationTimeoutSecs: 120
|
|
5068
|
+
});
|
|
5069
|
+
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5070
|
+
humanize: true
|
|
5071
|
+
});
|
|
5072
|
+
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5073
|
+
waitUntil: "commit"
|
|
5074
|
+
});
|
|
5075
|
+
var cachedCloakBrowserModulePromise = null;
|
|
5076
|
+
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5077
|
+
var loadCloakBrowserModule = async () => {
|
|
5078
|
+
if (!cachedCloakBrowserModulePromise) {
|
|
5079
|
+
cachedCloakBrowserModulePromise = import("cloakbrowser").catch((error) => {
|
|
5080
|
+
cachedCloakBrowserModulePromise = null;
|
|
5081
|
+
throw new Error("cloakbrowser \u6A21\u5757\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5 cloakbrowser\u3002", {
|
|
5082
|
+
cause: error
|
|
5083
|
+
});
|
|
5084
|
+
});
|
|
5085
|
+
}
|
|
5086
|
+
return cachedCloakBrowserModulePromise;
|
|
5087
|
+
};
|
|
5088
|
+
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5089
|
+
const { buildLaunchOptions } = await loadCloakBrowserModule();
|
|
5090
|
+
return await buildLaunchOptions(normalizeObject(options));
|
|
5091
|
+
};
|
|
5092
|
+
var normalizeObject = (value) => {
|
|
5093
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5094
|
+
return {};
|
|
5095
|
+
}
|
|
5096
|
+
return value;
|
|
5097
|
+
};
|
|
5098
|
+
var normalizeStringArray = (value) => {
|
|
5099
|
+
if (!Array.isArray(value)) {
|
|
5100
|
+
return [];
|
|
5101
|
+
}
|
|
5102
|
+
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5103
|
+
};
|
|
5104
|
+
var resolveCloakBrowserProxy = (proxyConfiguration = {}) => {
|
|
5105
|
+
const config = normalizeObject(proxyConfiguration);
|
|
5106
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5107
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5108
|
+
if (!enableProxy || !proxyUrl) {
|
|
5109
|
+
return null;
|
|
5110
|
+
}
|
|
5111
|
+
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5112
|
+
if (byPassDomains.length === 0) {
|
|
5113
|
+
return proxyUrl;
|
|
5114
|
+
}
|
|
5115
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5116
|
+
return {
|
|
5117
|
+
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5118
|
+
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5119
|
+
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5120
|
+
bypass: byPassDomains.join(",")
|
|
5121
|
+
};
|
|
5122
|
+
};
|
|
5123
|
+
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5124
|
+
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5125
|
+
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5126
|
+
};
|
|
5127
|
+
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5128
|
+
const normalizedRecommendedGotoOptions = normalizeObject(recommendedGotoOptions);
|
|
5129
|
+
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5130
|
+
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5131
|
+
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5132
|
+
if (gotoOptions[key] == null) {
|
|
5133
|
+
gotoOptions[key] = value;
|
|
5134
|
+
}
|
|
5135
|
+
}
|
|
5136
|
+
};
|
|
5137
|
+
};
|
|
5138
|
+
var attachCloakBrowserHumanizeHook = ({
|
|
5139
|
+
browserPoolOptions = {},
|
|
5140
|
+
activeBrowsers,
|
|
5141
|
+
patchedBrowsers,
|
|
5142
|
+
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5143
|
+
} = {}) => {
|
|
5144
|
+
const normalizedBrowserPoolOptions = normalizeObject(browserPoolOptions);
|
|
5145
|
+
const shouldHumanize = humanizeOptions !== false;
|
|
5146
|
+
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5147
|
+
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5148
|
+
...normalizeObject(humanizeOptions)
|
|
5149
|
+
} : null;
|
|
5150
|
+
return {
|
|
5151
|
+
...normalizedBrowserPoolOptions,
|
|
5152
|
+
useFingerprints: false,
|
|
5153
|
+
postLaunchHooks: [
|
|
5154
|
+
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5155
|
+
async (_pageId, browserController) => {
|
|
5156
|
+
const browser = browserController?.browser;
|
|
5157
|
+
if (!browser || typeof browser.contexts !== "function") {
|
|
5158
|
+
return;
|
|
5159
|
+
}
|
|
5160
|
+
activeBrowsers.add(browser);
|
|
5161
|
+
if (typeof browser.once === "function") {
|
|
5162
|
+
browser.once("disconnected", () => {
|
|
5163
|
+
activeBrowsers.delete(browser);
|
|
5164
|
+
});
|
|
5165
|
+
}
|
|
5166
|
+
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5167
|
+
return;
|
|
5168
|
+
}
|
|
5169
|
+
const { humanizeBrowser } = await loadCloakBrowserModule();
|
|
5170
|
+
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5171
|
+
patchedBrowsers.add(browser);
|
|
5172
|
+
}
|
|
5173
|
+
]
|
|
5174
|
+
};
|
|
5175
|
+
};
|
|
5176
|
+
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5177
|
+
const browsers = Array.from(activeBrowsers || []);
|
|
5178
|
+
activeBrowsers?.clear?.();
|
|
5179
|
+
await Promise.allSettled(
|
|
5180
|
+
browsers.map(async (browser) => {
|
|
5181
|
+
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5182
|
+
return;
|
|
5183
|
+
}
|
|
5184
|
+
await browser.close().catch(() => {
|
|
5185
|
+
});
|
|
5186
|
+
})
|
|
5187
|
+
);
|
|
5188
|
+
};
|
|
5189
|
+
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5190
|
+
if (!fingerprintArg) {
|
|
5191
|
+
return;
|
|
5192
|
+
}
|
|
5193
|
+
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5194
|
+
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5195
|
+
return;
|
|
5196
|
+
}
|
|
5197
|
+
logger9.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5198
|
+
});
|
|
5199
|
+
};
|
|
5200
|
+
var CloakBrowser = {
|
|
5201
|
+
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5202
|
+
return resolveCloakBrowserProxy(proxyConfiguration);
|
|
5203
|
+
},
|
|
5204
|
+
extractFingerprintArg(launchOptions = {}) {
|
|
5205
|
+
return extractFingerprintArg(launchOptions);
|
|
5206
|
+
},
|
|
5207
|
+
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5208
|
+
return createStableGotoHook(recommendedGotoOptions);
|
|
5209
|
+
},
|
|
5210
|
+
async buildLaunchOptions(options = {}) {
|
|
5211
|
+
return await buildCloakLaunchOptions(options);
|
|
5212
|
+
},
|
|
5213
|
+
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5214
|
+
const normalizedOptions = normalizeObject(options);
|
|
5215
|
+
const {
|
|
5216
|
+
proxyConfiguration = {},
|
|
5217
|
+
runInHeadfulMode = false,
|
|
5218
|
+
isRunningOnApify = false,
|
|
5219
|
+
launcher = null,
|
|
5220
|
+
cloakOptions = {},
|
|
5221
|
+
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5222
|
+
crawlerBaseOptions = {},
|
|
5223
|
+
browserPoolOptions = {},
|
|
5224
|
+
launchContext = {},
|
|
5225
|
+
preNavigationHooks = [],
|
|
5226
|
+
postNavigationHooks = [],
|
|
5227
|
+
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5228
|
+
} = normalizedOptions;
|
|
5229
|
+
const normalizedCloakOptions = normalizeObject(cloakOptions);
|
|
5230
|
+
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5231
|
+
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5232
|
+
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5233
|
+
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5234
|
+
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakBrowserProxy(proxyConfiguration);
|
|
5235
|
+
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5236
|
+
const mergedCloakOptions = {
|
|
5237
|
+
...normalizedCloakOptions,
|
|
5238
|
+
headless,
|
|
5239
|
+
proxy,
|
|
5240
|
+
args: [...defaultArgs, ...extraArgs]
|
|
5241
|
+
};
|
|
5242
|
+
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5243
|
+
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5244
|
+
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5245
|
+
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5246
|
+
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5247
|
+
const crawlerOptions = {
|
|
5248
|
+
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5249
|
+
...normalizeObject(crawlerBaseOptions),
|
|
5250
|
+
headless,
|
|
5251
|
+
launchContext: {
|
|
5252
|
+
useIncognitoPages: true,
|
|
5253
|
+
...normalizeObject(launchContext),
|
|
5254
|
+
...launcher ? { launcher } : {},
|
|
5255
|
+
launchOptions
|
|
5256
|
+
},
|
|
5257
|
+
browserPoolOptions: attachCloakBrowserHumanizeHook({
|
|
5258
|
+
browserPoolOptions,
|
|
5259
|
+
activeBrowsers,
|
|
5260
|
+
patchedBrowsers,
|
|
5261
|
+
humanizeOptions
|
|
5262
|
+
}),
|
|
5263
|
+
preNavigationHooks: [internalPreNavigationHook, ...normalizedPreNavigationHooks],
|
|
5264
|
+
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5265
|
+
};
|
|
5266
|
+
const closeActiveBrowsers = async () => {
|
|
5267
|
+
await closeTrackedBrowsers(activeBrowsers);
|
|
5268
|
+
};
|
|
5269
|
+
const forceTerminateActiveProcesses = async () => {
|
|
5270
|
+
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5271
|
+
};
|
|
5272
|
+
const cleanup = async () => {
|
|
5273
|
+
await closeActiveBrowsers();
|
|
5274
|
+
await forceTerminateActiveProcesses();
|
|
5275
|
+
};
|
|
5276
|
+
return {
|
|
5277
|
+
headless,
|
|
5278
|
+
launchOptions,
|
|
5279
|
+
fingerprintArg,
|
|
5280
|
+
crawlerOptions,
|
|
5281
|
+
closeActiveBrowsers,
|
|
5282
|
+
forceTerminateActiveProcesses,
|
|
5283
|
+
cleanup
|
|
5284
|
+
};
|
|
5285
|
+
}
|
|
5286
|
+
};
|
|
5287
|
+
var createCloakLaunchModule = (baseLaunch = {}) => {
|
|
5288
|
+
const normalizedBaseLaunch = normalizeObject(baseLaunch);
|
|
5289
|
+
return {
|
|
5290
|
+
...normalizedBaseLaunch,
|
|
5291
|
+
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5292
|
+
return CloakBrowser.resolveProxyConfiguration(proxyConfiguration);
|
|
5293
|
+
},
|
|
5294
|
+
extractFingerprintArg(launchOptions = {}) {
|
|
5295
|
+
return CloakBrowser.extractFingerprintArg(launchOptions);
|
|
5296
|
+
},
|
|
5297
|
+
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5298
|
+
return CloakBrowser.createStableGotoHook(recommendedGotoOptions);
|
|
5299
|
+
},
|
|
5300
|
+
async buildLaunchOptions(options = {}) {
|
|
5301
|
+
return await CloakBrowser.buildLaunchOptions(options);
|
|
5302
|
+
},
|
|
5303
|
+
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5304
|
+
return await CloakBrowser.createPlaywrightCrawlerRuntime(options);
|
|
5305
|
+
}
|
|
5306
|
+
};
|
|
5307
|
+
};
|
|
5308
|
+
|
|
5059
5309
|
// src/live-view.js
|
|
5060
5310
|
var import_express = __toESM(require("express"), 1);
|
|
5061
5311
|
var import_apify = require("apify");
|
|
5062
|
-
var
|
|
5312
|
+
var logger10 = createInternalLogger("LiveView");
|
|
5063
5313
|
async function startLiveViewServer(liveViewKey) {
|
|
5064
5314
|
const app = (0, import_express.default)();
|
|
5065
5315
|
app.get("/", async (req, res) => {
|
|
@@ -5084,13 +5334,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5084
5334
|
</html>
|
|
5085
5335
|
`);
|
|
5086
5336
|
} catch (error) {
|
|
5087
|
-
|
|
5337
|
+
logger10.fail("Live View Server", error);
|
|
5088
5338
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5089
5339
|
}
|
|
5090
5340
|
});
|
|
5091
5341
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5092
5342
|
app.listen(port, () => {
|
|
5093
|
-
|
|
5343
|
+
logger10.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5094
5344
|
});
|
|
5095
5345
|
}
|
|
5096
5346
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5098,10 +5348,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5098
5348
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5099
5349
|
await import_apify.Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5100
5350
|
if (logMessage) {
|
|
5101
|
-
|
|
5351
|
+
logger10.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5102
5352
|
}
|
|
5103
5353
|
} catch (e) {
|
|
5104
|
-
|
|
5354
|
+
logger10.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5105
5355
|
}
|
|
5106
5356
|
}
|
|
5107
5357
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5210,7 +5460,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5210
5460
|
};
|
|
5211
5461
|
|
|
5212
5462
|
// src/internals/captcha/bytedance.js
|
|
5213
|
-
var
|
|
5463
|
+
var logger11 = createInternalLogger("Captcha");
|
|
5214
5464
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5215
5465
|
apiType: "31234",
|
|
5216
5466
|
maxRetries: 3,
|
|
@@ -5342,7 +5592,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5342
5592
|
}
|
|
5343
5593
|
await (0, import_promises.writeFile)(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5344
5594
|
}
|
|
5345
|
-
|
|
5595
|
+
logger11.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5346
5596
|
};
|
|
5347
5597
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5348
5598
|
if (!options.debugArtifacts) {
|
|
@@ -5379,14 +5629,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5379
5629
|
if (!isContainerVisible) {
|
|
5380
5630
|
return null;
|
|
5381
5631
|
}
|
|
5382
|
-
|
|
5632
|
+
logger11.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5383
5633
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5384
5634
|
let isIframeVisible = await waitForVisible(
|
|
5385
5635
|
iframeLocator,
|
|
5386
5636
|
options.iframeVisibleTimeoutMs
|
|
5387
5637
|
);
|
|
5388
5638
|
if (!isIframeVisible) {
|
|
5389
|
-
|
|
5639
|
+
logger11.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5390
5640
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5391
5641
|
isIframeVisible = await waitForVisible(
|
|
5392
5642
|
iframeLocator,
|
|
@@ -5396,7 +5646,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5396
5646
|
if (!isIframeVisible) {
|
|
5397
5647
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5398
5648
|
}
|
|
5399
|
-
|
|
5649
|
+
logger11.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5400
5650
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5401
5651
|
if (!frame) {
|
|
5402
5652
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -5512,11 +5762,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
5512
5762
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
5513
5763
|
...options,
|
|
5514
5764
|
page,
|
|
5515
|
-
logger:
|
|
5765
|
+
logger: logger11,
|
|
5516
5766
|
forceMouse: true
|
|
5517
5767
|
}).catch(() => false);
|
|
5518
5768
|
if (!clicked) {
|
|
5519
|
-
|
|
5769
|
+
logger11.warn("Refresh button not found.");
|
|
5520
5770
|
return false;
|
|
5521
5771
|
}
|
|
5522
5772
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -5547,24 +5797,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
5547
5797
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
5548
5798
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
5549
5799
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
5550
|
-
|
|
5800
|
+
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");
|
|
5551
5801
|
hasLoggedGuideMask = true;
|
|
5552
5802
|
}
|
|
5553
5803
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
5554
|
-
|
|
5804
|
+
logger11.info(
|
|
5555
5805
|
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"
|
|
5556
5806
|
);
|
|
5557
5807
|
return;
|
|
5558
5808
|
}
|
|
5559
5809
|
if (hasErrorTextVisible) {
|
|
5560
|
-
|
|
5810
|
+
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");
|
|
5561
5811
|
await refreshCaptcha(page, frame, options);
|
|
5562
5812
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5563
5813
|
hasSeenLoading = false;
|
|
5564
5814
|
continue;
|
|
5565
5815
|
}
|
|
5566
5816
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
5567
|
-
|
|
5817
|
+
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`);
|
|
5568
5818
|
await refreshCaptcha(page, frame, options);
|
|
5569
5819
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5570
5820
|
hasSeenLoading = false;
|
|
@@ -5612,7 +5862,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
5612
5862
|
accepted
|
|
5613
5863
|
};
|
|
5614
5864
|
dragAttempts.push(attemptInfo);
|
|
5615
|
-
|
|
5865
|
+
logger11.info(
|
|
5616
5866
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
5617
5867
|
);
|
|
5618
5868
|
if (accepted) {
|
|
@@ -5630,7 +5880,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
5630
5880
|
dragAttempts,
|
|
5631
5881
|
finalState: await readPromptCaptchaState(frame, options)
|
|
5632
5882
|
}).catch((error) => {
|
|
5633
|
-
|
|
5883
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5634
5884
|
});
|
|
5635
5885
|
return {
|
|
5636
5886
|
accepted: false,
|
|
@@ -5647,16 +5897,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5647
5897
|
...options
|
|
5648
5898
|
};
|
|
5649
5899
|
if (!config.token) {
|
|
5650
|
-
|
|
5900
|
+
logger11.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
5651
5901
|
return false;
|
|
5652
5902
|
}
|
|
5653
|
-
|
|
5903
|
+
logger11.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
5654
5904
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
5655
|
-
|
|
5905
|
+
logger11.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
5656
5906
|
try {
|
|
5657
5907
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
5658
5908
|
if (!captchaContext) {
|
|
5659
|
-
|
|
5909
|
+
logger11.info("Captcha container is not visible anymore.");
|
|
5660
5910
|
return true;
|
|
5661
5911
|
}
|
|
5662
5912
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -5669,7 +5919,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5669
5919
|
"ready",
|
|
5670
5920
|
config
|
|
5671
5921
|
).catch((error) => {
|
|
5672
|
-
|
|
5922
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5673
5923
|
});
|
|
5674
5924
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
5675
5925
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -5681,16 +5931,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5681
5931
|
});
|
|
5682
5932
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
5683
5933
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
5684
|
-
|
|
5934
|
+
logger11.warn(
|
|
5685
5935
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
5686
5936
|
);
|
|
5687
5937
|
await refreshCaptcha(page, frame, config);
|
|
5688
5938
|
continue;
|
|
5689
5939
|
}
|
|
5690
|
-
|
|
5940
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
5691
5941
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
5692
5942
|
if (!dropTarget) {
|
|
5693
|
-
|
|
5943
|
+
logger11.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
5694
5944
|
await refreshCaptcha(page, frame, config);
|
|
5695
5945
|
continue;
|
|
5696
5946
|
}
|
|
@@ -5701,7 +5951,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5701
5951
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
5702
5952
|
);
|
|
5703
5953
|
}
|
|
5704
|
-
|
|
5954
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
5705
5955
|
for (const imageIndex of normalizedIndexes) {
|
|
5706
5956
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
5707
5957
|
throw new Error(
|
|
@@ -5733,52 +5983,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5733
5983
|
}
|
|
5734
5984
|
}
|
|
5735
5985
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
5736
|
-
|
|
5986
|
+
logger11.info(
|
|
5737
5987
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
5738
5988
|
);
|
|
5739
5989
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
5740
5990
|
...config,
|
|
5741
5991
|
page,
|
|
5742
|
-
logger:
|
|
5992
|
+
logger: logger11,
|
|
5743
5993
|
forceMouse: true,
|
|
5744
5994
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
5745
5995
|
}).catch(() => false);
|
|
5746
5996
|
if (!submitted) {
|
|
5747
|
-
|
|
5997
|
+
logger11.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
5748
5998
|
}
|
|
5749
5999
|
await page.waitForTimeout(config.submitWaitMs);
|
|
5750
6000
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
5751
|
-
|
|
6001
|
+
logger11.info(
|
|
5752
6002
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
5753
6003
|
);
|
|
5754
6004
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
5755
6005
|
if (!stillVisible) {
|
|
5756
|
-
|
|
6006
|
+
logger11.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
5757
6007
|
return true;
|
|
5758
6008
|
}
|
|
5759
6009
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
5760
6010
|
beforeSubmitState,
|
|
5761
6011
|
afterSubmitState
|
|
5762
6012
|
}).catch((error) => {
|
|
5763
|
-
|
|
6013
|
+
logger11.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5764
6014
|
});
|
|
5765
|
-
|
|
6015
|
+
logger11.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
5766
6016
|
await page.waitForTimeout(2e3);
|
|
5767
6017
|
await refreshCaptcha(page, frame, config);
|
|
5768
6018
|
} catch (error) {
|
|
5769
|
-
|
|
6019
|
+
logger11.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5770
6020
|
}
|
|
5771
6021
|
if (attempt < config.maxRetries) {
|
|
5772
6022
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
5773
6023
|
}
|
|
5774
6024
|
}
|
|
5775
|
-
|
|
6025
|
+
logger11.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
5776
6026
|
return false;
|
|
5777
6027
|
}
|
|
5778
6028
|
var sloveCaptcha = solveCaptcha;
|
|
5779
6029
|
|
|
5780
6030
|
// src/chaptcha.js
|
|
5781
|
-
var
|
|
6031
|
+
var logger12 = createInternalLogger("Captcha");
|
|
5782
6032
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
5783
6033
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
5784
6034
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -5865,7 +6115,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
5865
6115
|
};
|
|
5866
6116
|
})();
|
|
5867
6117
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
5868
|
-
|
|
6118
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
5869
6119
|
cleanupFns.push(async () => {
|
|
5870
6120
|
try {
|
|
5871
6121
|
await page.evaluate((name) => {
|
|
@@ -5889,14 +6139,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
5889
6139
|
}
|
|
5890
6140
|
};
|
|
5891
6141
|
page.on("framenavigated", frameHandler);
|
|
5892
|
-
|
|
6142
|
+
logger12.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
5893
6143
|
cleanupFns.push(async () => {
|
|
5894
6144
|
page.off("framenavigated", frameHandler);
|
|
5895
6145
|
});
|
|
5896
6146
|
}
|
|
5897
6147
|
return {
|
|
5898
6148
|
stop: async () => {
|
|
5899
|
-
|
|
6149
|
+
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
5900
6150
|
for (const fn of cleanupFns) {
|
|
5901
6151
|
await fn();
|
|
5902
6152
|
}
|
|
@@ -5935,7 +6185,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
5935
6185
|
);
|
|
5936
6186
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
5937
6187
|
callCaptchaRecognitionApi,
|
|
5938
|
-
logger:
|
|
6188
|
+
logger: logger12
|
|
5939
6189
|
});
|
|
5940
6190
|
}
|
|
5941
6191
|
var Captcha = {
|
|
@@ -5946,7 +6196,7 @@ var Captcha = {
|
|
|
5946
6196
|
// src/mutation.js
|
|
5947
6197
|
var import_node_crypto = require("node:crypto");
|
|
5948
6198
|
var import_uuid2 = require("uuid");
|
|
5949
|
-
var
|
|
6199
|
+
var logger13 = createInternalLogger("Mutation");
|
|
5950
6200
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
5951
6201
|
Added: "added",
|
|
5952
6202
|
Changed: "changed",
|
|
@@ -5979,14 +6229,14 @@ var Mutation = {
|
|
|
5979
6229
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
5980
6230
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
5981
6231
|
const onMutation = options.onMutation;
|
|
5982
|
-
|
|
6232
|
+
logger13.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
5983
6233
|
if (initialTimeout > 0) {
|
|
5984
6234
|
const selectorQuery = selectorList.join(",");
|
|
5985
6235
|
try {
|
|
5986
6236
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
5987
|
-
|
|
6237
|
+
logger13.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
5988
6238
|
} catch (e) {
|
|
5989
|
-
|
|
6239
|
+
logger13.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
5990
6240
|
throw e;
|
|
5991
6241
|
}
|
|
5992
6242
|
}
|
|
@@ -6002,7 +6252,7 @@ var Mutation = {
|
|
|
6002
6252
|
return "__CONTINUE__";
|
|
6003
6253
|
}
|
|
6004
6254
|
});
|
|
6005
|
-
|
|
6255
|
+
logger13.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
6006
6256
|
} catch (e) {
|
|
6007
6257
|
}
|
|
6008
6258
|
}
|
|
@@ -6117,9 +6367,9 @@ var Mutation = {
|
|
|
6117
6367
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6118
6368
|
);
|
|
6119
6369
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6120
|
-
|
|
6370
|
+
logger13.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6121
6371
|
}
|
|
6122
|
-
|
|
6372
|
+
logger13.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6123
6373
|
return result;
|
|
6124
6374
|
},
|
|
6125
6375
|
/**
|
|
@@ -6291,22 +6541,22 @@ var Mutation = {
|
|
|
6291
6541
|
return "__CONTINUE__";
|
|
6292
6542
|
}
|
|
6293
6543
|
};
|
|
6294
|
-
|
|
6544
|
+
logger13.start(
|
|
6295
6545
|
"waitForStableAcrossRoots",
|
|
6296
6546
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6297
6547
|
);
|
|
6298
6548
|
if (initialTimeout > 0) {
|
|
6299
6549
|
try {
|
|
6300
6550
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6301
|
-
|
|
6551
|
+
logger13.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6302
6552
|
} catch (e) {
|
|
6303
|
-
|
|
6553
|
+
logger13.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6304
6554
|
throw e;
|
|
6305
6555
|
}
|
|
6306
6556
|
}
|
|
6307
6557
|
let state = await buildState();
|
|
6308
6558
|
if (!state?.hasMatched) {
|
|
6309
|
-
|
|
6559
|
+
logger13.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6310
6560
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6311
6561
|
}
|
|
6312
6562
|
let mutationCount = 0;
|
|
@@ -6343,7 +6593,7 @@ var Mutation = {
|
|
|
6343
6593
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6344
6594
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6345
6595
|
mutationCount += 1;
|
|
6346
|
-
|
|
6596
|
+
logger13.info(
|
|
6347
6597
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6348
6598
|
);
|
|
6349
6599
|
const signal = await invokeMutationCallback({
|
|
@@ -6356,7 +6606,7 @@ var Mutation = {
|
|
|
6356
6606
|
continue;
|
|
6357
6607
|
}
|
|
6358
6608
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6359
|
-
|
|
6609
|
+
logger13.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6360
6610
|
return {
|
|
6361
6611
|
mutationCount,
|
|
6362
6612
|
stableTime: waitForStableTime,
|
|
@@ -6383,7 +6633,7 @@ var Mutation = {
|
|
|
6383
6633
|
const onMutation = options.onMutation;
|
|
6384
6634
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6385
6635
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6386
|
-
|
|
6636
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6387
6637
|
const monitorKey = generateKey("pk_mon");
|
|
6388
6638
|
const callbackName = generateKey("pk_mon_cb");
|
|
6389
6639
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6526,7 +6776,7 @@ var Mutation = {
|
|
|
6526
6776
|
return total;
|
|
6527
6777
|
};
|
|
6528
6778
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
6529
|
-
|
|
6779
|
+
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
6530
6780
|
return {
|
|
6531
6781
|
stop: async () => {
|
|
6532
6782
|
let totalMutations = 0;
|
|
@@ -6539,7 +6789,7 @@ var Mutation = {
|
|
|
6539
6789
|
}, cleanerName);
|
|
6540
6790
|
} catch (e) {
|
|
6541
6791
|
}
|
|
6542
|
-
|
|
6792
|
+
logger13.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
6543
6793
|
return { totalMutations };
|
|
6544
6794
|
}
|
|
6545
6795
|
};
|
|
@@ -7408,7 +7658,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7408
7658
|
};
|
|
7409
7659
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7410
7660
|
var Logger = {
|
|
7411
|
-
setLogger: (
|
|
7661
|
+
setLogger: (logger17) => setDefaultLogger(logger17),
|
|
7412
7662
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7413
7663
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7414
7664
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7416,8 +7666,8 @@ var Logger = {
|
|
|
7416
7666
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7417
7667
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7418
7668
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7419
|
-
useTemplate: (
|
|
7420
|
-
if (
|
|
7669
|
+
useTemplate: (logger17) => {
|
|
7670
|
+
if (logger17) return createTemplateLogger(createBaseLogger("", logger17));
|
|
7421
7671
|
return createTemplateLogger();
|
|
7422
7672
|
}
|
|
7423
7673
|
};
|
|
@@ -7491,7 +7741,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
7491
7741
|
];
|
|
7492
7742
|
var cachedStripLogoSrcPromise = null;
|
|
7493
7743
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
7494
|
-
var
|
|
7744
|
+
var logger14 = createInternalLogger("Watermarkify");
|
|
7495
7745
|
var normalizeText = (value) => String(value || "").trim();
|
|
7496
7746
|
var toInline = (value, maxLen = 200) => {
|
|
7497
7747
|
const text = normalizeText(value);
|
|
@@ -7733,9 +7983,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
7733
7983
|
location: toInline(resolved.location, 80)
|
|
7734
7984
|
};
|
|
7735
7985
|
if (enrichment.ip || enrichment.location) {
|
|
7736
|
-
|
|
7986
|
+
logger14.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
7737
7987
|
} else {
|
|
7738
|
-
|
|
7988
|
+
logger14.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
7739
7989
|
}
|
|
7740
7990
|
return enrichment;
|
|
7741
7991
|
} finally {
|
|
@@ -7921,12 +8171,12 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
7921
8171
|
};
|
|
7922
8172
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
7923
8173
|
if (!page || typeof page.context !== "function") {
|
|
7924
|
-
|
|
8174
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
7925
8175
|
return buffer;
|
|
7926
8176
|
}
|
|
7927
8177
|
const renderScope = await openProbePage(page);
|
|
7928
8178
|
if (!renderScope?.page) {
|
|
7929
|
-
|
|
8179
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
7930
8180
|
return buffer;
|
|
7931
8181
|
}
|
|
7932
8182
|
try {
|
|
@@ -7971,13 +8221,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
7971
8221
|
fullPage: true,
|
|
7972
8222
|
animations: "disabled"
|
|
7973
8223
|
}).catch((error) => {
|
|
7974
|
-
|
|
8224
|
+
logger14.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
7975
8225
|
return null;
|
|
7976
8226
|
});
|
|
7977
8227
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
7978
8228
|
return composed;
|
|
7979
8229
|
}
|
|
7980
|
-
|
|
8230
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
7981
8231
|
return buffer;
|
|
7982
8232
|
} finally {
|
|
7983
8233
|
await renderScope.close().catch(() => {
|
|
@@ -7990,7 +8240,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7990
8240
|
}
|
|
7991
8241
|
const probeScope = await openProbePage(page);
|
|
7992
8242
|
if (!probeScope?.page) {
|
|
7993
|
-
|
|
8243
|
+
logger14.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
7994
8244
|
return null;
|
|
7995
8245
|
}
|
|
7996
8246
|
const timeoutMs = Math.max(
|
|
@@ -7999,12 +8249,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7999
8249
|
);
|
|
8000
8250
|
try {
|
|
8001
8251
|
const probePage = probeScope.page;
|
|
8002
|
-
|
|
8252
|
+
logger14.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8003
8253
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8004
8254
|
waitUntil: "commit",
|
|
8005
8255
|
timeout: timeoutMs
|
|
8006
8256
|
}).catch((error) => {
|
|
8007
|
-
|
|
8257
|
+
logger14.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8008
8258
|
return null;
|
|
8009
8259
|
});
|
|
8010
8260
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8026,13 +8276,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8026
8276
|
}
|
|
8027
8277
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8028
8278
|
if (parsed?.ip || parsed?.location) {
|
|
8029
|
-
|
|
8279
|
+
logger14.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8030
8280
|
return parsed;
|
|
8031
8281
|
}
|
|
8032
|
-
|
|
8282
|
+
logger14.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8033
8283
|
return null;
|
|
8034
8284
|
} catch (error) {
|
|
8035
|
-
|
|
8285
|
+
logger14.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8036
8286
|
return null;
|
|
8037
8287
|
} finally {
|
|
8038
8288
|
await probeScope.close().catch(() => {
|
|
@@ -8046,10 +8296,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8046
8296
|
ip: toInline(options.ip, 80),
|
|
8047
8297
|
location: toInline(options.location, 80)
|
|
8048
8298
|
};
|
|
8049
|
-
|
|
8299
|
+
logger14.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8050
8300
|
if (!merged.ip || !merged.location) {
|
|
8051
8301
|
if (cached?.ip || cached?.location) {
|
|
8052
|
-
|
|
8302
|
+
logger14.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8053
8303
|
}
|
|
8054
8304
|
fillEnrichment(merged, cached);
|
|
8055
8305
|
}
|
|
@@ -8073,15 +8323,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8073
8323
|
"x-geo-country"
|
|
8074
8324
|
]), 80);
|
|
8075
8325
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8076
|
-
|
|
8326
|
+
logger14.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8077
8327
|
merged.location = headerLocation || merged.location;
|
|
8078
8328
|
}
|
|
8079
8329
|
}
|
|
8080
8330
|
writeCachedEnrichment(page, merged);
|
|
8081
8331
|
if (merged.ip || merged.location) {
|
|
8082
|
-
|
|
8332
|
+
logger14.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8083
8333
|
} else {
|
|
8084
|
-
|
|
8334
|
+
logger14.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8085
8335
|
}
|
|
8086
8336
|
return merged;
|
|
8087
8337
|
};
|
|
@@ -8894,7 +9144,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8894
9144
|
}
|
|
8895
9145
|
const imageInfo = readImageInfo(buffer);
|
|
8896
9146
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
8897
|
-
|
|
9147
|
+
logger14.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
8898
9148
|
return buffer;
|
|
8899
9149
|
}
|
|
8900
9150
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -8912,7 +9162,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8912
9162
|
|
|
8913
9163
|
// src/internals/compression.js
|
|
8914
9164
|
var import_jimp = require("jimp");
|
|
8915
|
-
var
|
|
9165
|
+
var logger15 = createInternalLogger("Compression");
|
|
8916
9166
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
8917
9167
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
8918
9168
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9031,18 +9281,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9031
9281
|
return buffer.toString("base64");
|
|
9032
9282
|
}
|
|
9033
9283
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9034
|
-
|
|
9284
|
+
logger15.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9035
9285
|
return null;
|
|
9036
9286
|
});
|
|
9037
9287
|
if (!result?.buffer) {
|
|
9038
9288
|
return buffer.toString("base64");
|
|
9039
9289
|
}
|
|
9040
9290
|
if (result.withinLimit) {
|
|
9041
|
-
|
|
9291
|
+
logger15.info(
|
|
9042
9292
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9043
9293
|
);
|
|
9044
9294
|
} else {
|
|
9045
|
-
|
|
9295
|
+
logger15.warning(
|
|
9046
9296
|
`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}`
|
|
9047
9297
|
);
|
|
9048
9298
|
}
|
|
@@ -9050,7 +9300,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9050
9300
|
};
|
|
9051
9301
|
|
|
9052
9302
|
// src/share.js
|
|
9053
|
-
var
|
|
9303
|
+
var logger16 = createInternalLogger("Share");
|
|
9054
9304
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9055
9305
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9056
9306
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9187,7 +9437,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9187
9437
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9188
9438
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9189
9439
|
let matched = false;
|
|
9190
|
-
|
|
9440
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9191
9441
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9192
9442
|
mode,
|
|
9193
9443
|
onMutation: (context = {}) => {
|
|
@@ -9205,12 +9455,12 @@ ${text}`;
|
|
|
9205
9455
|
});
|
|
9206
9456
|
}
|
|
9207
9457
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9208
|
-
|
|
9458
|
+
logger16.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9209
9459
|
}
|
|
9210
9460
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9211
9461
|
if (!candidate) return;
|
|
9212
9462
|
matched = true;
|
|
9213
|
-
|
|
9463
|
+
logger16.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9214
9464
|
if (onMatch) {
|
|
9215
9465
|
onMatch({
|
|
9216
9466
|
link: candidate,
|
|
@@ -9226,7 +9476,7 @@ ${text}`;
|
|
|
9226
9476
|
return {
|
|
9227
9477
|
stop: async () => {
|
|
9228
9478
|
const result = await monitor.stop();
|
|
9229
|
-
|
|
9479
|
+
logger16.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9230
9480
|
return result;
|
|
9231
9481
|
}
|
|
9232
9482
|
};
|
|
@@ -9275,8 +9525,8 @@ var Share = {
|
|
|
9275
9525
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9276
9526
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9277
9527
|
}
|
|
9278
|
-
|
|
9279
|
-
|
|
9528
|
+
logger16.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9529
|
+
logger16.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9280
9530
|
const stats = {
|
|
9281
9531
|
actionTimedOut: false,
|
|
9282
9532
|
domMutationCount: 0,
|
|
@@ -9288,7 +9538,7 @@ var Share = {
|
|
|
9288
9538
|
responseSampleUrls: []
|
|
9289
9539
|
};
|
|
9290
9540
|
if (isAborted()) {
|
|
9291
|
-
|
|
9541
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9292
9542
|
return {
|
|
9293
9543
|
link: null,
|
|
9294
9544
|
payloadText: "",
|
|
@@ -9311,7 +9561,7 @@ var Share = {
|
|
|
9311
9561
|
link: validated,
|
|
9312
9562
|
payloadText: String(payloadText || "")
|
|
9313
9563
|
};
|
|
9314
|
-
|
|
9564
|
+
logger16.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9315
9565
|
return true;
|
|
9316
9566
|
};
|
|
9317
9567
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9346,7 +9596,7 @@ var Share = {
|
|
|
9346
9596
|
try {
|
|
9347
9597
|
await monitor.stop();
|
|
9348
9598
|
} catch (error) {
|
|
9349
|
-
|
|
9599
|
+
logger16.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9350
9600
|
}
|
|
9351
9601
|
};
|
|
9352
9602
|
const onResponse = async (response) => {
|
|
@@ -9360,29 +9610,29 @@ var Share = {
|
|
|
9360
9610
|
stats.responseSampleUrls.push(url);
|
|
9361
9611
|
}
|
|
9362
9612
|
if (stats.responseObserved <= 5) {
|
|
9363
|
-
|
|
9613
|
+
logger16.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9364
9614
|
}
|
|
9365
9615
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9366
9616
|
stats.responseMatched += 1;
|
|
9367
9617
|
stats.lastMatchedUrl = url;
|
|
9368
|
-
|
|
9618
|
+
logger16.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9369
9619
|
const text = await response.text();
|
|
9370
9620
|
const hit = resolveResponseCandidate(text);
|
|
9371
9621
|
if (!hit?.link) {
|
|
9372
9622
|
if (stats.responseMatched <= 3) {
|
|
9373
|
-
|
|
9623
|
+
logger16.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9374
9624
|
}
|
|
9375
9625
|
return;
|
|
9376
9626
|
}
|
|
9377
9627
|
stats.responseResolved += 1;
|
|
9378
|
-
|
|
9628
|
+
logger16.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9379
9629
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9380
9630
|
} catch (error) {
|
|
9381
|
-
|
|
9631
|
+
logger16.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9382
9632
|
}
|
|
9383
9633
|
};
|
|
9384
9634
|
if (share.mode === "dom") {
|
|
9385
|
-
|
|
9635
|
+
logger16.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9386
9636
|
domMonitor = await createDomShareMonitor(page, {
|
|
9387
9637
|
prefix: share.prefix,
|
|
9388
9638
|
selectors: domSelectors,
|
|
@@ -9397,17 +9647,17 @@ var Share = {
|
|
|
9397
9647
|
});
|
|
9398
9648
|
}
|
|
9399
9649
|
if (share.mode === "response") {
|
|
9400
|
-
|
|
9650
|
+
logger16.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9401
9651
|
page.on("response", onResponse);
|
|
9402
9652
|
}
|
|
9403
9653
|
if (share.mode === "custom") {
|
|
9404
|
-
|
|
9654
|
+
logger16.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9405
9655
|
}
|
|
9406
9656
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9407
9657
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9408
9658
|
try {
|
|
9409
9659
|
const actionTimeout = getRemainingMs();
|
|
9410
|
-
|
|
9660
|
+
logger16.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9411
9661
|
let actionValue;
|
|
9412
9662
|
if (!isAborted() && actionTimeout > 0) {
|
|
9413
9663
|
let timer = null;
|
|
@@ -9420,30 +9670,30 @@ var Share = {
|
|
|
9420
9670
|
]);
|
|
9421
9671
|
if (timer) clearTimeout(timer);
|
|
9422
9672
|
if (actionResult.type === "error") {
|
|
9423
|
-
|
|
9673
|
+
logger16.fail("captureLink.performActions", actionResult.error);
|
|
9424
9674
|
throw actionResult.error;
|
|
9425
9675
|
}
|
|
9426
9676
|
if (actionResult.type === "timeout") {
|
|
9427
9677
|
stats.actionTimedOut = true;
|
|
9428
|
-
|
|
9678
|
+
logger16.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9429
9679
|
} else {
|
|
9430
9680
|
actionValue = actionResult.result;
|
|
9431
|
-
|
|
9681
|
+
logger16.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9432
9682
|
}
|
|
9433
9683
|
}
|
|
9434
9684
|
if (share.mode === "custom") {
|
|
9435
9685
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9436
9686
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9437
9687
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9438
|
-
|
|
9688
|
+
logger16.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9439
9689
|
} else {
|
|
9440
|
-
|
|
9690
|
+
logger16.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9441
9691
|
}
|
|
9442
9692
|
}
|
|
9443
9693
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9444
9694
|
while (true) {
|
|
9445
9695
|
if (isAborted()) {
|
|
9446
|
-
|
|
9696
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9447
9697
|
return {
|
|
9448
9698
|
link: null,
|
|
9449
9699
|
payloadText: "",
|
|
@@ -9453,7 +9703,7 @@ var Share = {
|
|
|
9453
9703
|
}
|
|
9454
9704
|
const selected = candidates[share.mode];
|
|
9455
9705
|
if (selected?.link) {
|
|
9456
|
-
|
|
9706
|
+
logger16.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9457
9707
|
return {
|
|
9458
9708
|
link: selected.link,
|
|
9459
9709
|
payloadText: selected.payloadText,
|
|
@@ -9466,7 +9716,7 @@ var Share = {
|
|
|
9466
9716
|
if (remaining <= 0) break;
|
|
9467
9717
|
const now = Date.now();
|
|
9468
9718
|
if (now >= nextProgressLogTs) {
|
|
9469
|
-
|
|
9719
|
+
logger16.info(
|
|
9470
9720
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9471
9721
|
);
|
|
9472
9722
|
nextProgressLogTs = now + 5e3;
|
|
@@ -9474,11 +9724,11 @@ var Share = {
|
|
|
9474
9724
|
await (0, import_delay4.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9475
9725
|
}
|
|
9476
9726
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9477
|
-
|
|
9727
|
+
logger16.warning(
|
|
9478
9728
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9479
9729
|
);
|
|
9480
9730
|
}
|
|
9481
|
-
|
|
9731
|
+
logger16.warning(
|
|
9482
9732
|
`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"}`
|
|
9483
9733
|
);
|
|
9484
9734
|
return {
|
|
@@ -9490,7 +9740,7 @@ var Share = {
|
|
|
9490
9740
|
} finally {
|
|
9491
9741
|
if (share.mode === "response") {
|
|
9492
9742
|
page.off("response", onResponse);
|
|
9493
|
-
|
|
9743
|
+
logger16.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
9494
9744
|
}
|
|
9495
9745
|
await stopDomMonitor();
|
|
9496
9746
|
}
|
|
@@ -9533,14 +9783,15 @@ var Share = {
|
|
|
9533
9783
|
|
|
9534
9784
|
// entrys/node.js
|
|
9535
9785
|
Logger.setLogger(import_crawlee.log);
|
|
9536
|
-
var usePlaywrightToolKit = () => {
|
|
9537
|
-
|
|
9786
|
+
var usePlaywrightToolKit = (mode = "default") => {
|
|
9787
|
+
const launchModule = mode === "cloakbrowser" ? createCloakLaunchModule(Launch) : Launch;
|
|
9788
|
+
const toolkit = {
|
|
9538
9789
|
ApifyKit,
|
|
9539
9790
|
AntiCheat,
|
|
9540
9791
|
DeviceInput,
|
|
9541
9792
|
DeviceView,
|
|
9542
9793
|
Humanize: Humanize2,
|
|
9543
|
-
Launch,
|
|
9794
|
+
Launch: launchModule,
|
|
9544
9795
|
LiveView,
|
|
9545
9796
|
Constants: constants_exports,
|
|
9546
9797
|
Utils,
|
|
@@ -9554,6 +9805,7 @@ var usePlaywrightToolKit = () => {
|
|
|
9554
9805
|
ByPass,
|
|
9555
9806
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
9556
9807
|
};
|
|
9808
|
+
return toolkit;
|
|
9557
9809
|
};
|
|
9558
9810
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9559
9811
|
0 && (module.exports = {
|