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