@skrillex1224/playwright-toolkit 2.1.274 → 2.1.276
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 +425 -146
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +425 -146
- package/dist/index.js.map +4 -4
- package/index.d.ts +48 -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 {
|
|
@@ -7918,14 +8169,17 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
7918
8169
|
</html>
|
|
7919
8170
|
`;
|
|
7920
8171
|
};
|
|
7921
|
-
var
|
|
8172
|
+
var normalizeWatermarkifyRenderMode = (value) => {
|
|
8173
|
+
return String(value || "default").trim().toLowerCase() === "cloakbrowser" ? "cloakbrowser" : "default";
|
|
8174
|
+
};
|
|
8175
|
+
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
7922
8176
|
if (!page || typeof page.context !== "function") {
|
|
7923
|
-
|
|
8177
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
7924
8178
|
return buffer;
|
|
7925
8179
|
}
|
|
7926
8180
|
const renderScope = await openProbePage(page);
|
|
7927
8181
|
if (!renderScope?.page) {
|
|
7928
|
-
|
|
8182
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
7929
8183
|
return buffer;
|
|
7930
8184
|
}
|
|
7931
8185
|
try {
|
|
@@ -7942,15 +8196,35 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
7942
8196
|
height: viewportHeight
|
|
7943
8197
|
}).catch(() => {
|
|
7944
8198
|
});
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
7951
|
-
|
|
7952
|
-
|
|
7953
|
-
|
|
8199
|
+
const renderMode = normalizeWatermarkifyRenderMode(options.mode);
|
|
8200
|
+
if (renderMode === "cloakbrowser") {
|
|
8201
|
+
const renderHtml = buildWatermarkifyRenderHtml({
|
|
8202
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8203
|
+
overlaySvg,
|
|
8204
|
+
width: safeWidth,
|
|
8205
|
+
height: safeHeight,
|
|
8206
|
+
imageHeight: safeImageHeight
|
|
8207
|
+
});
|
|
8208
|
+
await renderPage.goto("about:blank", {
|
|
8209
|
+
waitUntil: "commit"
|
|
8210
|
+
}).catch(() => {
|
|
8211
|
+
});
|
|
8212
|
+
await renderPage.evaluate((html) => {
|
|
8213
|
+
document.open();
|
|
8214
|
+
document.write(html);
|
|
8215
|
+
document.close();
|
|
8216
|
+
}, renderHtml);
|
|
8217
|
+
} else {
|
|
8218
|
+
await renderPage.setContent(buildWatermarkifyRenderHtml({
|
|
8219
|
+
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8220
|
+
overlaySvg,
|
|
8221
|
+
width: safeWidth,
|
|
8222
|
+
height: safeHeight,
|
|
8223
|
+
imageHeight: safeImageHeight
|
|
8224
|
+
}), {
|
|
8225
|
+
waitUntil: "load"
|
|
8226
|
+
});
|
|
8227
|
+
}
|
|
7954
8228
|
await renderPage.waitForFunction(() => {
|
|
7955
8229
|
const image = document.getElementById("pk-base-image");
|
|
7956
8230
|
return image instanceof HTMLImageElement && image.complete && image.naturalWidth > 0 && image.naturalHeight > 0;
|
|
@@ -7970,13 +8244,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
7970
8244
|
fullPage: true,
|
|
7971
8245
|
animations: "disabled"
|
|
7972
8246
|
}).catch((error) => {
|
|
7973
|
-
|
|
8247
|
+
logger14.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
7974
8248
|
return null;
|
|
7975
8249
|
});
|
|
7976
8250
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
7977
8251
|
return composed;
|
|
7978
8252
|
}
|
|
7979
|
-
|
|
8253
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
7980
8254
|
return buffer;
|
|
7981
8255
|
} finally {
|
|
7982
8256
|
await renderScope.close().catch(() => {
|
|
@@ -7989,7 +8263,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7989
8263
|
}
|
|
7990
8264
|
const probeScope = await openProbePage(page);
|
|
7991
8265
|
if (!probeScope?.page) {
|
|
7992
|
-
|
|
8266
|
+
logger14.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
7993
8267
|
return null;
|
|
7994
8268
|
}
|
|
7995
8269
|
const timeoutMs = Math.max(
|
|
@@ -7998,12 +8272,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7998
8272
|
);
|
|
7999
8273
|
try {
|
|
8000
8274
|
const probePage = probeScope.page;
|
|
8001
|
-
|
|
8275
|
+
logger14.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
8002
8276
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
8003
8277
|
waitUntil: "commit",
|
|
8004
8278
|
timeout: timeoutMs
|
|
8005
8279
|
}).catch((error) => {
|
|
8006
|
-
|
|
8280
|
+
logger14.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
8007
8281
|
return null;
|
|
8008
8282
|
});
|
|
8009
8283
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -8025,13 +8299,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
8025
8299
|
}
|
|
8026
8300
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8027
8301
|
if (parsed?.ip || parsed?.location) {
|
|
8028
|
-
|
|
8302
|
+
logger14.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8029
8303
|
return parsed;
|
|
8030
8304
|
}
|
|
8031
|
-
|
|
8305
|
+
logger14.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8032
8306
|
return null;
|
|
8033
8307
|
} catch (error) {
|
|
8034
|
-
|
|
8308
|
+
logger14.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8035
8309
|
return null;
|
|
8036
8310
|
} finally {
|
|
8037
8311
|
await probeScope.close().catch(() => {
|
|
@@ -8045,10 +8319,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8045
8319
|
ip: toInline(options.ip, 80),
|
|
8046
8320
|
location: toInline(options.location, 80)
|
|
8047
8321
|
};
|
|
8048
|
-
|
|
8322
|
+
logger14.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8049
8323
|
if (!merged.ip || !merged.location) {
|
|
8050
8324
|
if (cached?.ip || cached?.location) {
|
|
8051
|
-
|
|
8325
|
+
logger14.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8052
8326
|
}
|
|
8053
8327
|
fillEnrichment(merged, cached);
|
|
8054
8328
|
}
|
|
@@ -8072,15 +8346,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8072
8346
|
"x-geo-country"
|
|
8073
8347
|
]), 80);
|
|
8074
8348
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8075
|
-
|
|
8349
|
+
logger14.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8076
8350
|
merged.location = headerLocation || merged.location;
|
|
8077
8351
|
}
|
|
8078
8352
|
}
|
|
8079
8353
|
writeCachedEnrichment(page, merged);
|
|
8080
8354
|
if (merged.ip || merged.location) {
|
|
8081
|
-
|
|
8355
|
+
logger14.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8082
8356
|
} else {
|
|
8083
|
-
|
|
8357
|
+
logger14.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8084
8358
|
}
|
|
8085
8359
|
return merged;
|
|
8086
8360
|
};
|
|
@@ -8885,7 +9159,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
|
|
|
8885
9159
|
</svg>
|
|
8886
9160
|
`;
|
|
8887
9161
|
};
|
|
8888
|
-
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
9162
|
+
var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {}) => {
|
|
8889
9163
|
const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
|
|
8890
9164
|
const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
|
|
8891
9165
|
if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
|
|
@@ -8893,7 +9167,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8893
9167
|
}
|
|
8894
9168
|
const imageInfo = readImageInfo(buffer);
|
|
8895
9169
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
8896
|
-
|
|
9170
|
+
logger14.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
8897
9171
|
return buffer;
|
|
8898
9172
|
}
|
|
8899
9173
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -8906,12 +9180,12 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8906
9180
|
if (!overlaySvg) {
|
|
8907
9181
|
return buffer;
|
|
8908
9182
|
}
|
|
8909
|
-
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo);
|
|
9183
|
+
return await composeScreenshotBufferWithBrowser(page, buffer, overlaySvg, outputImageInfo, options);
|
|
8910
9184
|
};
|
|
8911
9185
|
|
|
8912
9186
|
// src/internals/compression.js
|
|
8913
9187
|
var import_jimp = require("jimp");
|
|
8914
|
-
var
|
|
9188
|
+
var logger15 = createInternalLogger("Compression");
|
|
8915
9189
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
8916
9190
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
8917
9191
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9030,18 +9304,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9030
9304
|
return buffer.toString("base64");
|
|
9031
9305
|
}
|
|
9032
9306
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9033
|
-
|
|
9307
|
+
logger15.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9034
9308
|
return null;
|
|
9035
9309
|
});
|
|
9036
9310
|
if (!result?.buffer) {
|
|
9037
9311
|
return buffer.toString("base64");
|
|
9038
9312
|
}
|
|
9039
9313
|
if (result.withinLimit) {
|
|
9040
|
-
|
|
9314
|
+
logger15.info(
|
|
9041
9315
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9042
9316
|
);
|
|
9043
9317
|
} else {
|
|
9044
|
-
|
|
9318
|
+
logger15.warning(
|
|
9045
9319
|
`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
9320
|
);
|
|
9047
9321
|
}
|
|
@@ -9049,7 +9323,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9049
9323
|
};
|
|
9050
9324
|
|
|
9051
9325
|
// src/share.js
|
|
9052
|
-
var
|
|
9326
|
+
var logger16 = createInternalLogger("Share");
|
|
9053
9327
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9054
9328
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9055
9329
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9186,7 +9460,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9186
9460
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9187
9461
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9188
9462
|
let matched = false;
|
|
9189
|
-
|
|
9463
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9190
9464
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9191
9465
|
mode,
|
|
9192
9466
|
onMutation: (context = {}) => {
|
|
@@ -9204,12 +9478,12 @@ ${text}`;
|
|
|
9204
9478
|
});
|
|
9205
9479
|
}
|
|
9206
9480
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9207
|
-
|
|
9481
|
+
logger16.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9208
9482
|
}
|
|
9209
9483
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9210
9484
|
if (!candidate) return;
|
|
9211
9485
|
matched = true;
|
|
9212
|
-
|
|
9486
|
+
logger16.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9213
9487
|
if (onMatch) {
|
|
9214
9488
|
onMatch({
|
|
9215
9489
|
link: candidate,
|
|
@@ -9225,7 +9499,7 @@ ${text}`;
|
|
|
9225
9499
|
return {
|
|
9226
9500
|
stop: async () => {
|
|
9227
9501
|
const result = await monitor.stop();
|
|
9228
|
-
|
|
9502
|
+
logger16.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9229
9503
|
return result;
|
|
9230
9504
|
}
|
|
9231
9505
|
};
|
|
@@ -9274,8 +9548,8 @@ var Share = {
|
|
|
9274
9548
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9275
9549
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9276
9550
|
}
|
|
9277
|
-
|
|
9278
|
-
|
|
9551
|
+
logger16.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9552
|
+
logger16.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9279
9553
|
const stats = {
|
|
9280
9554
|
actionTimedOut: false,
|
|
9281
9555
|
domMutationCount: 0,
|
|
@@ -9287,7 +9561,7 @@ var Share = {
|
|
|
9287
9561
|
responseSampleUrls: []
|
|
9288
9562
|
};
|
|
9289
9563
|
if (isAborted()) {
|
|
9290
|
-
|
|
9564
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9291
9565
|
return {
|
|
9292
9566
|
link: null,
|
|
9293
9567
|
payloadText: "",
|
|
@@ -9310,7 +9584,7 @@ var Share = {
|
|
|
9310
9584
|
link: validated,
|
|
9311
9585
|
payloadText: String(payloadText || "")
|
|
9312
9586
|
};
|
|
9313
|
-
|
|
9587
|
+
logger16.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9314
9588
|
return true;
|
|
9315
9589
|
};
|
|
9316
9590
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9345,7 +9619,7 @@ var Share = {
|
|
|
9345
9619
|
try {
|
|
9346
9620
|
await monitor.stop();
|
|
9347
9621
|
} catch (error) {
|
|
9348
|
-
|
|
9622
|
+
logger16.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9349
9623
|
}
|
|
9350
9624
|
};
|
|
9351
9625
|
const onResponse = async (response) => {
|
|
@@ -9359,29 +9633,29 @@ var Share = {
|
|
|
9359
9633
|
stats.responseSampleUrls.push(url);
|
|
9360
9634
|
}
|
|
9361
9635
|
if (stats.responseObserved <= 5) {
|
|
9362
|
-
|
|
9636
|
+
logger16.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9363
9637
|
}
|
|
9364
9638
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9365
9639
|
stats.responseMatched += 1;
|
|
9366
9640
|
stats.lastMatchedUrl = url;
|
|
9367
|
-
|
|
9641
|
+
logger16.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9368
9642
|
const text = await response.text();
|
|
9369
9643
|
const hit = resolveResponseCandidate(text);
|
|
9370
9644
|
if (!hit?.link) {
|
|
9371
9645
|
if (stats.responseMatched <= 3) {
|
|
9372
|
-
|
|
9646
|
+
logger16.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9373
9647
|
}
|
|
9374
9648
|
return;
|
|
9375
9649
|
}
|
|
9376
9650
|
stats.responseResolved += 1;
|
|
9377
|
-
|
|
9651
|
+
logger16.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9378
9652
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9379
9653
|
} catch (error) {
|
|
9380
|
-
|
|
9654
|
+
logger16.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9381
9655
|
}
|
|
9382
9656
|
};
|
|
9383
9657
|
if (share.mode === "dom") {
|
|
9384
|
-
|
|
9658
|
+
logger16.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9385
9659
|
domMonitor = await createDomShareMonitor(page, {
|
|
9386
9660
|
prefix: share.prefix,
|
|
9387
9661
|
selectors: domSelectors,
|
|
@@ -9396,17 +9670,17 @@ var Share = {
|
|
|
9396
9670
|
});
|
|
9397
9671
|
}
|
|
9398
9672
|
if (share.mode === "response") {
|
|
9399
|
-
|
|
9673
|
+
logger16.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9400
9674
|
page.on("response", onResponse);
|
|
9401
9675
|
}
|
|
9402
9676
|
if (share.mode === "custom") {
|
|
9403
|
-
|
|
9677
|
+
logger16.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9404
9678
|
}
|
|
9405
9679
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9406
9680
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9407
9681
|
try {
|
|
9408
9682
|
const actionTimeout = getRemainingMs();
|
|
9409
|
-
|
|
9683
|
+
logger16.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9410
9684
|
let actionValue;
|
|
9411
9685
|
if (!isAborted() && actionTimeout > 0) {
|
|
9412
9686
|
let timer = null;
|
|
@@ -9419,30 +9693,30 @@ var Share = {
|
|
|
9419
9693
|
]);
|
|
9420
9694
|
if (timer) clearTimeout(timer);
|
|
9421
9695
|
if (actionResult.type === "error") {
|
|
9422
|
-
|
|
9696
|
+
logger16.fail("captureLink.performActions", actionResult.error);
|
|
9423
9697
|
throw actionResult.error;
|
|
9424
9698
|
}
|
|
9425
9699
|
if (actionResult.type === "timeout") {
|
|
9426
9700
|
stats.actionTimedOut = true;
|
|
9427
|
-
|
|
9701
|
+
logger16.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9428
9702
|
} else {
|
|
9429
9703
|
actionValue = actionResult.result;
|
|
9430
|
-
|
|
9704
|
+
logger16.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9431
9705
|
}
|
|
9432
9706
|
}
|
|
9433
9707
|
if (share.mode === "custom") {
|
|
9434
9708
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9435
9709
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9436
9710
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9437
|
-
|
|
9711
|
+
logger16.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9438
9712
|
} else {
|
|
9439
|
-
|
|
9713
|
+
logger16.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9440
9714
|
}
|
|
9441
9715
|
}
|
|
9442
9716
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9443
9717
|
while (true) {
|
|
9444
9718
|
if (isAborted()) {
|
|
9445
|
-
|
|
9719
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9446
9720
|
return {
|
|
9447
9721
|
link: null,
|
|
9448
9722
|
payloadText: "",
|
|
@@ -9452,7 +9726,7 @@ var Share = {
|
|
|
9452
9726
|
}
|
|
9453
9727
|
const selected = candidates[share.mode];
|
|
9454
9728
|
if (selected?.link) {
|
|
9455
|
-
|
|
9729
|
+
logger16.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9456
9730
|
return {
|
|
9457
9731
|
link: selected.link,
|
|
9458
9732
|
payloadText: selected.payloadText,
|
|
@@ -9465,7 +9739,7 @@ var Share = {
|
|
|
9465
9739
|
if (remaining <= 0) break;
|
|
9466
9740
|
const now = Date.now();
|
|
9467
9741
|
if (now >= nextProgressLogTs) {
|
|
9468
|
-
|
|
9742
|
+
logger16.info(
|
|
9469
9743
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9470
9744
|
);
|
|
9471
9745
|
nextProgressLogTs = now + 5e3;
|
|
@@ -9473,11 +9747,11 @@ var Share = {
|
|
|
9473
9747
|
await (0, import_delay4.default)(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9474
9748
|
}
|
|
9475
9749
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9476
|
-
|
|
9750
|
+
logger16.warning(
|
|
9477
9751
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9478
9752
|
);
|
|
9479
9753
|
}
|
|
9480
|
-
|
|
9754
|
+
logger16.warning(
|
|
9481
9755
|
`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
9756
|
);
|
|
9483
9757
|
return {
|
|
@@ -9489,7 +9763,7 @@ var Share = {
|
|
|
9489
9763
|
} finally {
|
|
9490
9764
|
if (share.mode === "response") {
|
|
9491
9765
|
page.off("response", onResponse);
|
|
9492
|
-
|
|
9766
|
+
logger16.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
9493
9767
|
}
|
|
9494
9768
|
await stopDomMonitor();
|
|
9495
9769
|
}
|
|
@@ -9504,6 +9778,7 @@ var Share = {
|
|
|
9504
9778
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
9505
9779
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
9506
9780
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
9781
|
+
* @param {'default'|'cloakbrowser'} [options.mode] 截图水印合成模式,默认 default
|
|
9507
9782
|
* @returns {Promise<string>} base64 image
|
|
9508
9783
|
*/
|
|
9509
9784
|
async captureScreen(page, options = {}) {
|
|
@@ -9524,7 +9799,9 @@ var Share = {
|
|
|
9524
9799
|
...screenshotWatermarkify,
|
|
9525
9800
|
capturedAt
|
|
9526
9801
|
});
|
|
9527
|
-
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page
|
|
9802
|
+
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page, {
|
|
9803
|
+
mode: options.mode === "cloakbrowser" ? "cloakbrowser" : "default"
|
|
9804
|
+
});
|
|
9528
9805
|
}
|
|
9529
9806
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
9530
9807
|
}
|
|
@@ -9532,14 +9809,15 @@ var Share = {
|
|
|
9532
9809
|
|
|
9533
9810
|
// entrys/node.js
|
|
9534
9811
|
Logger.setLogger(import_crawlee.log);
|
|
9535
|
-
var usePlaywrightToolKit = () => {
|
|
9536
|
-
|
|
9812
|
+
var usePlaywrightToolKit = (mode = "default") => {
|
|
9813
|
+
const launchModule = mode === "cloakbrowser" ? createCloakLaunchModule(Launch) : Launch;
|
|
9814
|
+
const toolkit = {
|
|
9537
9815
|
ApifyKit,
|
|
9538
9816
|
AntiCheat,
|
|
9539
9817
|
DeviceInput,
|
|
9540
9818
|
DeviceView,
|
|
9541
9819
|
Humanize: Humanize2,
|
|
9542
|
-
Launch,
|
|
9820
|
+
Launch: launchModule,
|
|
9543
9821
|
LiveView,
|
|
9544
9822
|
Constants: constants_exports,
|
|
9545
9823
|
Utils,
|
|
@@ -9553,6 +9831,7 @@ var usePlaywrightToolKit = () => {
|
|
|
9553
9831
|
ByPass,
|
|
9554
9832
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
9555
9833
|
};
|
|
9834
|
+
return toolkit;
|
|
9556
9835
|
};
|
|
9557
9836
|
// Annotate the CommonJS export names for ESM import in node:
|
|
9558
9837
|
0 && (module.exports = {
|