@skrillex1224/playwright-toolkit 2.1.273 → 2.1.275
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +0 -1
- package/dist/browser.js.map +2 -2
- package/dist/index.cjs +386 -134
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +386 -134
- package/dist/index.js.map +4 -4
- package/index.d.ts +46 -0
- package/package.json +7 -1
package/dist/index.js
CHANGED
|
@@ -194,7 +194,6 @@ var ActorInfo = {
|
|
|
194
194
|
name: "DeepSeek",
|
|
195
195
|
domain: "chat.deepseek.com",
|
|
196
196
|
path: "/",
|
|
197
|
-
device: Device.Mobile,
|
|
198
197
|
share: {
|
|
199
198
|
mode: "response",
|
|
200
199
|
prefix: "https://chat.deepseek.com/share/",
|
|
@@ -348,18 +347,18 @@ var fallbackLog = {
|
|
|
348
347
|
error: (...args) => console.error(...args),
|
|
349
348
|
debug: (...args) => console.debug ? console.debug(...args) : console.log(...args)
|
|
350
349
|
};
|
|
351
|
-
var resolveLogMethod = (
|
|
352
|
-
if (
|
|
353
|
-
return
|
|
350
|
+
var resolveLogMethod = (logger17, name) => {
|
|
351
|
+
if (logger17 && typeof logger17[name] === "function") {
|
|
352
|
+
return logger17[name].bind(logger17);
|
|
354
353
|
}
|
|
355
|
-
if (name === "warning" &&
|
|
356
|
-
return
|
|
354
|
+
if (name === "warning" && logger17 && typeof logger17.warn === "function") {
|
|
355
|
+
return logger17.warn.bind(logger17);
|
|
357
356
|
}
|
|
358
357
|
return fallbackLog[name];
|
|
359
358
|
};
|
|
360
359
|
var defaultLogger = null;
|
|
361
|
-
var setDefaultLogger = (
|
|
362
|
-
defaultLogger =
|
|
360
|
+
var setDefaultLogger = (logger17) => {
|
|
361
|
+
defaultLogger = logger17;
|
|
363
362
|
};
|
|
364
363
|
var resolveLogger = (explicitLogger) => {
|
|
365
364
|
if (explicitLogger && typeof explicitLogger.info === "function") {
|
|
@@ -386,8 +385,8 @@ var colorize = (text, color) => {
|
|
|
386
385
|
var createBaseLogger = (prefix = "", explicitLogger) => {
|
|
387
386
|
const name = prefix ? String(prefix) : "";
|
|
388
387
|
const dispatch = (methodName, icon, message, color) => {
|
|
389
|
-
const
|
|
390
|
-
const logFn = resolveLogMethod(
|
|
388
|
+
const logger17 = resolveLogger(explicitLogger);
|
|
389
|
+
const logFn = resolveLogMethod(logger17, methodName);
|
|
391
390
|
const timestamp = colorize(`[${formatTimestamp()}]`, ANSI.gray);
|
|
392
391
|
const line = formatLine(name, icon, message);
|
|
393
392
|
const coloredLine = colorize(line, color);
|
|
@@ -741,7 +740,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
741
740
|
if (safeTargetHeight <= viewportHeight + 1) {
|
|
742
741
|
return 0;
|
|
743
742
|
}
|
|
744
|
-
const
|
|
743
|
+
const hasOwn2 = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
745
744
|
const isVisible = (el, style, rect) => {
|
|
746
745
|
if (!el || !style || !rect) return false;
|
|
747
746
|
if (style.display === "none" || style.visibility === "hidden" || style.visibility === "collapse") {
|
|
@@ -781,7 +780,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
781
780
|
return true;
|
|
782
781
|
});
|
|
783
782
|
topLevelCandidates.forEach(({ el, position, edge }) => {
|
|
784
|
-
if (!
|
|
783
|
+
if (!hasOwn2(el.dataset, "pkAffixedAdjusted")) {
|
|
785
784
|
el.dataset.pkAffixedAdjusted = "1";
|
|
786
785
|
el.dataset.pkOrigPosition = el.style.getPropertyValue("position") || "";
|
|
787
786
|
el.dataset.pkOrigPositionPriority = el.style.getPropertyPriority("position") || "";
|
|
@@ -812,7 +811,7 @@ var adjustAffixedElementsForExpandedScreenshot = async (page, options = {}) => {
|
|
|
812
811
|
};
|
|
813
812
|
var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
814
813
|
await page.evaluate((className) => {
|
|
815
|
-
const
|
|
814
|
+
const hasOwn2 = (source, key) => Object.prototype.hasOwnProperty.call(source, key);
|
|
816
815
|
const expansionKeys = [
|
|
817
816
|
"pkOrigOverflow",
|
|
818
817
|
"pkOrigHeight",
|
|
@@ -820,28 +819,28 @@ var restoreAffixedElementsForExpandedScreenshot = async (page) => {
|
|
|
820
819
|
"pkOrigMaxHeight"
|
|
821
820
|
];
|
|
822
821
|
document.querySelectorAll('[data-pk-affixed-adjusted="1"]').forEach((el) => {
|
|
823
|
-
if (
|
|
822
|
+
if (hasOwn2(el.dataset, "pkOrigPosition")) {
|
|
824
823
|
el.style.setProperty("position", el.dataset.pkOrigPosition || "", el.dataset.pkOrigPositionPriority || "");
|
|
825
824
|
delete el.dataset.pkOrigPosition;
|
|
826
825
|
delete el.dataset.pkOrigPositionPriority;
|
|
827
826
|
}
|
|
828
|
-
if (
|
|
827
|
+
if (hasOwn2(el.dataset, "pkOrigTop")) {
|
|
829
828
|
el.style.setProperty("top", el.dataset.pkOrigTop || "", el.dataset.pkOrigTopPriority || "");
|
|
830
829
|
delete el.dataset.pkOrigTop;
|
|
831
830
|
delete el.dataset.pkOrigTopPriority;
|
|
832
831
|
}
|
|
833
|
-
if (
|
|
832
|
+
if (hasOwn2(el.dataset, "pkOrigBottom")) {
|
|
834
833
|
el.style.setProperty("bottom", el.dataset.pkOrigBottom || "", el.dataset.pkOrigBottomPriority || "");
|
|
835
834
|
delete el.dataset.pkOrigBottom;
|
|
836
835
|
delete el.dataset.pkOrigBottomPriority;
|
|
837
836
|
}
|
|
838
|
-
if (
|
|
837
|
+
if (hasOwn2(el.dataset, "pkOrigTranslate")) {
|
|
839
838
|
el.style.setProperty("translate", el.dataset.pkOrigTranslate || "", el.dataset.pkOrigTranslatePriority || "");
|
|
840
839
|
delete el.dataset.pkOrigTranslate;
|
|
841
840
|
delete el.dataset.pkOrigTranslatePriority;
|
|
842
841
|
}
|
|
843
842
|
delete el.dataset.pkAffixedAdjusted;
|
|
844
|
-
const stillExpanded = expansionKeys.some((key) =>
|
|
843
|
+
const stillExpanded = expansionKeys.some((key) => hasOwn2(el.dataset, key));
|
|
845
844
|
if (!stillExpanded) {
|
|
846
845
|
el.classList.remove(className);
|
|
847
846
|
}
|
|
@@ -5028,10 +5027,261 @@ var Launch = {
|
|
|
5028
5027
|
}
|
|
5029
5028
|
};
|
|
5030
5029
|
|
|
5030
|
+
// src/cloakbrowser.js
|
|
5031
|
+
import { execFile } from "node:child_process";
|
|
5032
|
+
import { promisify } from "node:util";
|
|
5033
|
+
var logger9 = createInternalLogger("CloakBrowser");
|
|
5034
|
+
var execFileAsync = promisify(execFile);
|
|
5035
|
+
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5036
|
+
maxConcurrency: 1,
|
|
5037
|
+
maxRequestRetries: 0,
|
|
5038
|
+
requestHandlerTimeoutSecs: 240,
|
|
5039
|
+
navigationTimeoutSecs: 120
|
|
5040
|
+
});
|
|
5041
|
+
var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
5042
|
+
humanize: true
|
|
5043
|
+
});
|
|
5044
|
+
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5045
|
+
waitUntil: "commit"
|
|
5046
|
+
});
|
|
5047
|
+
var cachedCloakBrowserModulePromise = null;
|
|
5048
|
+
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5049
|
+
var loadCloakBrowserModule = async () => {
|
|
5050
|
+
if (!cachedCloakBrowserModulePromise) {
|
|
5051
|
+
cachedCloakBrowserModulePromise = import("cloakbrowser").catch((error) => {
|
|
5052
|
+
cachedCloakBrowserModulePromise = null;
|
|
5053
|
+
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", {
|
|
5054
|
+
cause: error
|
|
5055
|
+
});
|
|
5056
|
+
});
|
|
5057
|
+
}
|
|
5058
|
+
return cachedCloakBrowserModulePromise;
|
|
5059
|
+
};
|
|
5060
|
+
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5061
|
+
const { buildLaunchOptions } = await loadCloakBrowserModule();
|
|
5062
|
+
return await buildLaunchOptions(normalizeObject(options));
|
|
5063
|
+
};
|
|
5064
|
+
var normalizeObject = (value) => {
|
|
5065
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
5066
|
+
return {};
|
|
5067
|
+
}
|
|
5068
|
+
return value;
|
|
5069
|
+
};
|
|
5070
|
+
var normalizeStringArray = (value) => {
|
|
5071
|
+
if (!Array.isArray(value)) {
|
|
5072
|
+
return [];
|
|
5073
|
+
}
|
|
5074
|
+
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5075
|
+
};
|
|
5076
|
+
var resolveCloakBrowserProxy = (proxyConfiguration = {}) => {
|
|
5077
|
+
const config = normalizeObject(proxyConfiguration);
|
|
5078
|
+
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5079
|
+
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
5080
|
+
if (!enableProxy || !proxyUrl) {
|
|
5081
|
+
return null;
|
|
5082
|
+
}
|
|
5083
|
+
const byPassDomains = ByPass.normalizeByPassDomains(config.by_pass_domains);
|
|
5084
|
+
if (byPassDomains.length === 0) {
|
|
5085
|
+
return proxyUrl;
|
|
5086
|
+
}
|
|
5087
|
+
const parsedProxyUrl = new URL(proxyUrl.includes("://") ? proxyUrl : `http://${proxyUrl}`);
|
|
5088
|
+
return {
|
|
5089
|
+
server: `${parsedProxyUrl.protocol}//${parsedProxyUrl.host}`,
|
|
5090
|
+
username: decodeURIComponent(parsedProxyUrl.username || ""),
|
|
5091
|
+
password: decodeURIComponent(parsedProxyUrl.password || ""),
|
|
5092
|
+
bypass: byPassDomains.join(",")
|
|
5093
|
+
};
|
|
5094
|
+
};
|
|
5095
|
+
var extractFingerprintArg = (launchOptions = {}) => {
|
|
5096
|
+
const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
|
|
5097
|
+
return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
|
|
5098
|
+
};
|
|
5099
|
+
var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
|
|
5100
|
+
const normalizedRecommendedGotoOptions = normalizeObject(recommendedGotoOptions);
|
|
5101
|
+
const fallbackGotoOptions = Object.keys(normalizedRecommendedGotoOptions).length > 0 ? normalizedRecommendedGotoOptions : DEFAULT_CLOAK_GOTO_OPTIONS;
|
|
5102
|
+
return async (_crawlingContext, gotoOptions = {}) => {
|
|
5103
|
+
for (const [key, value] of Object.entries(fallbackGotoOptions)) {
|
|
5104
|
+
if (gotoOptions[key] == null) {
|
|
5105
|
+
gotoOptions[key] = value;
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
};
|
|
5109
|
+
};
|
|
5110
|
+
var attachCloakBrowserHumanizeHook = ({
|
|
5111
|
+
browserPoolOptions = {},
|
|
5112
|
+
activeBrowsers,
|
|
5113
|
+
patchedBrowsers,
|
|
5114
|
+
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS
|
|
5115
|
+
} = {}) => {
|
|
5116
|
+
const normalizedBrowserPoolOptions = normalizeObject(browserPoolOptions);
|
|
5117
|
+
const shouldHumanize = humanizeOptions !== false;
|
|
5118
|
+
const normalizedHumanizeOptions = shouldHumanize ? {
|
|
5119
|
+
...DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5120
|
+
...normalizeObject(humanizeOptions)
|
|
5121
|
+
} : null;
|
|
5122
|
+
return {
|
|
5123
|
+
...normalizedBrowserPoolOptions,
|
|
5124
|
+
useFingerprints: false,
|
|
5125
|
+
postLaunchHooks: [
|
|
5126
|
+
...Array.isArray(normalizedBrowserPoolOptions.postLaunchHooks) ? normalizedBrowserPoolOptions.postLaunchHooks : [],
|
|
5127
|
+
async (_pageId, browserController) => {
|
|
5128
|
+
const browser = browserController?.browser;
|
|
5129
|
+
if (!browser || typeof browser.contexts !== "function") {
|
|
5130
|
+
return;
|
|
5131
|
+
}
|
|
5132
|
+
activeBrowsers.add(browser);
|
|
5133
|
+
if (typeof browser.once === "function") {
|
|
5134
|
+
browser.once("disconnected", () => {
|
|
5135
|
+
activeBrowsers.delete(browser);
|
|
5136
|
+
});
|
|
5137
|
+
}
|
|
5138
|
+
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5139
|
+
return;
|
|
5140
|
+
}
|
|
5141
|
+
const { humanizeBrowser } = await loadCloakBrowserModule();
|
|
5142
|
+
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5143
|
+
patchedBrowsers.add(browser);
|
|
5144
|
+
}
|
|
5145
|
+
]
|
|
5146
|
+
};
|
|
5147
|
+
};
|
|
5148
|
+
var closeTrackedBrowsers = async (activeBrowsers) => {
|
|
5149
|
+
const browsers = Array.from(activeBrowsers || []);
|
|
5150
|
+
activeBrowsers?.clear?.();
|
|
5151
|
+
await Promise.allSettled(
|
|
5152
|
+
browsers.map(async (browser) => {
|
|
5153
|
+
if (!browser || typeof browser.isConnected !== "function" || !browser.isConnected()) {
|
|
5154
|
+
return;
|
|
5155
|
+
}
|
|
5156
|
+
await browser.close().catch(() => {
|
|
5157
|
+
});
|
|
5158
|
+
})
|
|
5159
|
+
);
|
|
5160
|
+
};
|
|
5161
|
+
var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
5162
|
+
if (!fingerprintArg) {
|
|
5163
|
+
return;
|
|
5164
|
+
}
|
|
5165
|
+
await execFileAsync("pkill", ["-f", "--", fingerprintArg]).catch((error) => {
|
|
5166
|
+
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5167
|
+
return;
|
|
5168
|
+
}
|
|
5169
|
+
logger9.info(`\u5F3A\u5236\u5173\u95ED CloakBrowser \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5170
|
+
});
|
|
5171
|
+
};
|
|
5172
|
+
var CloakBrowser = {
|
|
5173
|
+
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5174
|
+
return resolveCloakBrowserProxy(proxyConfiguration);
|
|
5175
|
+
},
|
|
5176
|
+
extractFingerprintArg(launchOptions = {}) {
|
|
5177
|
+
return extractFingerprintArg(launchOptions);
|
|
5178
|
+
},
|
|
5179
|
+
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5180
|
+
return createStableGotoHook(recommendedGotoOptions);
|
|
5181
|
+
},
|
|
5182
|
+
async buildLaunchOptions(options = {}) {
|
|
5183
|
+
return await buildCloakLaunchOptions(options);
|
|
5184
|
+
},
|
|
5185
|
+
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5186
|
+
const normalizedOptions = normalizeObject(options);
|
|
5187
|
+
const {
|
|
5188
|
+
proxyConfiguration = {},
|
|
5189
|
+
runInHeadfulMode = false,
|
|
5190
|
+
isRunningOnApify = false,
|
|
5191
|
+
launcher = null,
|
|
5192
|
+
cloakOptions = {},
|
|
5193
|
+
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5194
|
+
crawlerBaseOptions = {},
|
|
5195
|
+
browserPoolOptions = {},
|
|
5196
|
+
launchContext = {},
|
|
5197
|
+
preNavigationHooks = [],
|
|
5198
|
+
postNavigationHooks = [],
|
|
5199
|
+
recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS
|
|
5200
|
+
} = normalizedOptions;
|
|
5201
|
+
const normalizedCloakOptions = normalizeObject(cloakOptions);
|
|
5202
|
+
const activeBrowsers = /* @__PURE__ */ new Set();
|
|
5203
|
+
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5204
|
+
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5205
|
+
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5206
|
+
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakBrowserProxy(proxyConfiguration);
|
|
5207
|
+
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5208
|
+
const mergedCloakOptions = {
|
|
5209
|
+
...normalizedCloakOptions,
|
|
5210
|
+
headless,
|
|
5211
|
+
proxy,
|
|
5212
|
+
args: [...defaultArgs, ...extraArgs]
|
|
5213
|
+
};
|
|
5214
|
+
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5215
|
+
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
5216
|
+
const internalPreNavigationHook = createStableGotoHook(recommendedGotoOptions);
|
|
5217
|
+
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
5218
|
+
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
5219
|
+
const crawlerOptions = {
|
|
5220
|
+
...DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS,
|
|
5221
|
+
...normalizeObject(crawlerBaseOptions),
|
|
5222
|
+
headless,
|
|
5223
|
+
launchContext: {
|
|
5224
|
+
useIncognitoPages: true,
|
|
5225
|
+
...normalizeObject(launchContext),
|
|
5226
|
+
...launcher ? { launcher } : {},
|
|
5227
|
+
launchOptions
|
|
5228
|
+
},
|
|
5229
|
+
browserPoolOptions: attachCloakBrowserHumanizeHook({
|
|
5230
|
+
browserPoolOptions,
|
|
5231
|
+
activeBrowsers,
|
|
5232
|
+
patchedBrowsers,
|
|
5233
|
+
humanizeOptions
|
|
5234
|
+
}),
|
|
5235
|
+
preNavigationHooks: [internalPreNavigationHook, ...normalizedPreNavigationHooks],
|
|
5236
|
+
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
5237
|
+
};
|
|
5238
|
+
const closeActiveBrowsers = async () => {
|
|
5239
|
+
await closeTrackedBrowsers(activeBrowsers);
|
|
5240
|
+
};
|
|
5241
|
+
const forceTerminateActiveProcesses = async () => {
|
|
5242
|
+
await forceTerminateBrowsersByFingerprintArg(fingerprintArg);
|
|
5243
|
+
};
|
|
5244
|
+
const cleanup = async () => {
|
|
5245
|
+
await closeActiveBrowsers();
|
|
5246
|
+
await forceTerminateActiveProcesses();
|
|
5247
|
+
};
|
|
5248
|
+
return {
|
|
5249
|
+
headless,
|
|
5250
|
+
launchOptions,
|
|
5251
|
+
fingerprintArg,
|
|
5252
|
+
crawlerOptions,
|
|
5253
|
+
closeActiveBrowsers,
|
|
5254
|
+
forceTerminateActiveProcesses,
|
|
5255
|
+
cleanup
|
|
5256
|
+
};
|
|
5257
|
+
}
|
|
5258
|
+
};
|
|
5259
|
+
var createCloakLaunchModule = (baseLaunch = {}) => {
|
|
5260
|
+
const normalizedBaseLaunch = normalizeObject(baseLaunch);
|
|
5261
|
+
return {
|
|
5262
|
+
...normalizedBaseLaunch,
|
|
5263
|
+
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5264
|
+
return CloakBrowser.resolveProxyConfiguration(proxyConfiguration);
|
|
5265
|
+
},
|
|
5266
|
+
extractFingerprintArg(launchOptions = {}) {
|
|
5267
|
+
return CloakBrowser.extractFingerprintArg(launchOptions);
|
|
5268
|
+
},
|
|
5269
|
+
createStableGotoHook(recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) {
|
|
5270
|
+
return CloakBrowser.createStableGotoHook(recommendedGotoOptions);
|
|
5271
|
+
},
|
|
5272
|
+
async buildLaunchOptions(options = {}) {
|
|
5273
|
+
return await CloakBrowser.buildLaunchOptions(options);
|
|
5274
|
+
},
|
|
5275
|
+
async createPlaywrightCrawlerRuntime(options = {}) {
|
|
5276
|
+
return await CloakBrowser.createPlaywrightCrawlerRuntime(options);
|
|
5277
|
+
}
|
|
5278
|
+
};
|
|
5279
|
+
};
|
|
5280
|
+
|
|
5031
5281
|
// src/live-view.js
|
|
5032
5282
|
import express from "express";
|
|
5033
5283
|
import { Actor } from "apify";
|
|
5034
|
-
var
|
|
5284
|
+
var logger10 = createInternalLogger("LiveView");
|
|
5035
5285
|
async function startLiveViewServer(liveViewKey) {
|
|
5036
5286
|
const app = express();
|
|
5037
5287
|
app.get("/", async (req, res) => {
|
|
@@ -5056,13 +5306,13 @@ async function startLiveViewServer(liveViewKey) {
|
|
|
5056
5306
|
</html>
|
|
5057
5307
|
`);
|
|
5058
5308
|
} catch (error) {
|
|
5059
|
-
|
|
5309
|
+
logger10.fail("Live View Server", error);
|
|
5060
5310
|
res.status(500).send(`\u65E0\u6CD5\u52A0\u8F7D\u5C4F\u5E55\u622A\u56FE: ${error.message}`);
|
|
5061
5311
|
}
|
|
5062
5312
|
});
|
|
5063
5313
|
const port = process.env.APIFY_CONTAINER_PORT || 4321;
|
|
5064
5314
|
app.listen(port, () => {
|
|
5065
|
-
|
|
5315
|
+
logger10.success("startLiveViewServer", `\u76D1\u542C\u7AEF\u53E3 ${port}`);
|
|
5066
5316
|
});
|
|
5067
5317
|
}
|
|
5068
5318
|
async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
@@ -5070,10 +5320,10 @@ async function takeLiveScreenshot(liveViewKey, page, logMessage) {
|
|
|
5070
5320
|
const buffer = await capturePageScreenshot(page, { type: "png" });
|
|
5071
5321
|
await Actor.setValue(liveViewKey, buffer, { contentType: "image/png" });
|
|
5072
5322
|
if (logMessage) {
|
|
5073
|
-
|
|
5323
|
+
logger10.info(`(\u622A\u56FE): ${logMessage}`);
|
|
5074
5324
|
}
|
|
5075
5325
|
} catch (e) {
|
|
5076
|
-
|
|
5326
|
+
logger10.warn(`\u65E0\u6CD5\u6355\u83B7 Live View \u5C4F\u5E55\u622A\u56FE: ${e.message}`);
|
|
5077
5327
|
}
|
|
5078
5328
|
}
|
|
5079
5329
|
var useLiveView = (liveViewKey = PresetOfLiveViewKey) => {
|
|
@@ -5182,7 +5432,7 @@ var dragCaptchaAction = async (page, sourceLocator, targetLocator, options = {})
|
|
|
5182
5432
|
};
|
|
5183
5433
|
|
|
5184
5434
|
// src/internals/captcha/bytedance.js
|
|
5185
|
-
var
|
|
5435
|
+
var logger11 = createInternalLogger("Captcha");
|
|
5186
5436
|
var DEFAULT_BYTEDANCE_CAPTCHA_OPTIONS = Object.freeze({
|
|
5187
5437
|
apiType: "31234",
|
|
5188
5438
|
maxRetries: 3,
|
|
@@ -5314,7 +5564,7 @@ var collectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase,
|
|
|
5314
5564
|
}
|
|
5315
5565
|
await writeFile(infoPath, JSON.stringify(payload, null, 2), "utf8");
|
|
5316
5566
|
}
|
|
5317
|
-
|
|
5567
|
+
logger11.info(`\u5DF2\u5199\u51FA\u9A8C\u8BC1\u7801\u8C03\u8BD5\u4EA7\u7269\uFF1A${debugDir}`);
|
|
5318
5568
|
};
|
|
5319
5569
|
var maybeCollectCaptchaDebugInfo = async (page, frame, iframeLocator, attempt, phase, options, extra = null) => {
|
|
5320
5570
|
if (!options.debugArtifacts) {
|
|
@@ -5351,14 +5601,14 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5351
5601
|
if (!isContainerVisible) {
|
|
5352
5602
|
return null;
|
|
5353
5603
|
}
|
|
5354
|
-
|
|
5604
|
+
logger11.info("\u68C0\u6D4B\u5230\u9A8C\u8BC1\u7801\u5BB9\u5668\uFF0C\u5F00\u59CB\u7B49\u5F85 iframe \u52A0\u8F7D\u3002");
|
|
5355
5605
|
let iframeLocator = page.locator(options.iframeSelector).first();
|
|
5356
5606
|
let isIframeVisible = await waitForVisible(
|
|
5357
5607
|
iframeLocator,
|
|
5358
5608
|
options.iframeVisibleTimeoutMs
|
|
5359
5609
|
);
|
|
5360
5610
|
if (!isIframeVisible) {
|
|
5361
|
-
|
|
5611
|
+
logger11.warn("\u672A\u5728\u9884\u671F\u9009\u62E9\u5668\u4E2D\u627E\u5230 verifycenter iframe\uFF0C\u5C1D\u8BD5\u5BB9\u5668\u5185\u4EFB\u610F iframe\u3002");
|
|
5362
5612
|
iframeLocator = captchaContainer.locator(options.iframeFallbackSelector).first();
|
|
5363
5613
|
isIframeVisible = await waitForVisible(
|
|
5364
5614
|
iframeLocator,
|
|
@@ -5368,7 +5618,7 @@ var getVerifycenterCaptchaContext = async (page, options) => {
|
|
|
5368
5618
|
if (!isIframeVisible) {
|
|
5369
5619
|
throw new Error("verifycenter iframe not found inside captcha container.");
|
|
5370
5620
|
}
|
|
5371
|
-
|
|
5621
|
+
logger11.info("\u9A8C\u8BC1\u7801 iframe \u5DF2\u53EF\u89C1\uFF0C\u5F00\u59CB\u89E3\u6790\u5185\u5BB9 frame\u3002");
|
|
5372
5622
|
const frame = await resolveContentFrame(page, iframeLocator, options);
|
|
5373
5623
|
if (!frame) {
|
|
5374
5624
|
throw new Error("Failed to resolve verifycenter iframe content frame.");
|
|
@@ -5484,11 +5734,11 @@ var refreshCaptcha = async (page, frame, options) => {
|
|
|
5484
5734
|
const clicked = await clickCaptchaAction(frame, options.refreshTexts, {
|
|
5485
5735
|
...options,
|
|
5486
5736
|
page,
|
|
5487
|
-
logger:
|
|
5737
|
+
logger: logger11,
|
|
5488
5738
|
forceMouse: true
|
|
5489
5739
|
}).catch(() => false);
|
|
5490
5740
|
if (!clicked) {
|
|
5491
|
-
|
|
5741
|
+
logger11.warn("Refresh button not found.");
|
|
5492
5742
|
return false;
|
|
5493
5743
|
}
|
|
5494
5744
|
await page.waitForTimeout(options.refreshWaitMs);
|
|
@@ -5519,24 +5769,24 @@ var waitForCaptchaChallengeReady = async (page, frame, options) => {
|
|
|
5519
5769
|
const hasGuideMaskVisible = options.guideMaskSelector ? await frame.locator(options.guideMaskSelector).first().isVisible({ timeout: options.loadingIndicatorVisibleTimeoutMs }).catch(() => false) : false;
|
|
5520
5770
|
hasSeenGuideMask = hasSeenGuideMask || hasGuideMaskVisible;
|
|
5521
5771
|
if (hasGuideMaskVisible && !hasLoggedGuideMask) {
|
|
5522
|
-
|
|
5772
|
+
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");
|
|
5523
5773
|
hasLoggedGuideMask = true;
|
|
5524
5774
|
}
|
|
5525
5775
|
if (!isLoadingVisible && hasVisibleSourceImage && hasVisibleDropTarget && !hasGuideMaskVisible) {
|
|
5526
|
-
|
|
5776
|
+
logger11.info(
|
|
5527
5777
|
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"
|
|
5528
5778
|
);
|
|
5529
5779
|
return;
|
|
5530
5780
|
}
|
|
5531
5781
|
if (hasErrorTextVisible) {
|
|
5532
|
-
|
|
5782
|
+
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");
|
|
5533
5783
|
await refreshCaptcha(page, frame, options);
|
|
5534
5784
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5535
5785
|
hasSeenLoading = false;
|
|
5536
5786
|
continue;
|
|
5537
5787
|
}
|
|
5538
5788
|
if ((!hasVisibleSourceImage || !hasVisibleDropTarget) && Date.now() >= refreshDeadline) {
|
|
5539
|
-
|
|
5789
|
+
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`);
|
|
5540
5790
|
await refreshCaptcha(page, frame, options);
|
|
5541
5791
|
refreshDeadline = Date.now() + options.challengeReadyRefreshTimeoutMs;
|
|
5542
5792
|
hasSeenLoading = false;
|
|
@@ -5584,7 +5834,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
5584
5834
|
accepted
|
|
5585
5835
|
};
|
|
5586
5836
|
dragAttempts.push(attemptInfo);
|
|
5587
|
-
|
|
5837
|
+
logger11.info(
|
|
5588
5838
|
`\u9A8C\u8BC1\u7801\u62D6\u62FD\u7B2C ${visualIndex + 1} \u5F20\uFF0C\u65B9\u6848 ${plan.name}\uFF0Cbadge ${baselineState.badgeCount} -> ${afterState.badgeCount}\uFF0Cselected ${baselineState.selectedCount} -> ${afterState.selectedCount}`
|
|
5589
5839
|
);
|
|
5590
5840
|
if (accepted) {
|
|
@@ -5602,7 +5852,7 @@ var dragPromptCaptchaImage = async (page, frame, iframeLocator, sourceLocator, d
|
|
|
5602
5852
|
dragAttempts,
|
|
5603
5853
|
finalState: await readPromptCaptchaState(frame, options)
|
|
5604
5854
|
}).catch((error) => {
|
|
5605
|
-
|
|
5855
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u62D6\u62FD\u5931\u8D25\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5606
5856
|
});
|
|
5607
5857
|
return {
|
|
5608
5858
|
accepted: false,
|
|
@@ -5619,16 +5869,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5619
5869
|
...options
|
|
5620
5870
|
};
|
|
5621
5871
|
if (!config.token) {
|
|
5622
|
-
|
|
5872
|
+
logger11.warn("\u7F3A\u5C11\u9A8C\u8BC1\u7801 token\uFF0C\u8DF3\u8FC7\u81EA\u52A8\u8BC6\u522B\u3002");
|
|
5623
5873
|
return false;
|
|
5624
5874
|
}
|
|
5625
|
-
|
|
5875
|
+
logger11.info("\u5F53\u524D\u4F7F\u7528\u672Ctool\u2014\u2014\u6D4B\u8BD5\u7248\u672C");
|
|
5626
5876
|
for (let attempt = 1; attempt <= config.maxRetries; attempt += 1) {
|
|
5627
|
-
|
|
5877
|
+
logger11.info(`\u5F00\u59CB\u7B2C ${attempt}/${config.maxRetries} \u6B21 verifycenter \u9A8C\u8BC1\u7801\u8BC6\u522B\u3002`);
|
|
5628
5878
|
try {
|
|
5629
5879
|
const captchaContext = await getVerifycenterCaptchaContext(page, config);
|
|
5630
5880
|
if (!captchaContext) {
|
|
5631
|
-
|
|
5881
|
+
logger11.info("Captcha container is not visible anymore.");
|
|
5632
5882
|
return true;
|
|
5633
5883
|
}
|
|
5634
5884
|
const { iframeLocator, frame } = captchaContext;
|
|
@@ -5641,7 +5891,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5641
5891
|
"ready",
|
|
5642
5892
|
config
|
|
5643
5893
|
).catch((error) => {
|
|
5644
|
-
|
|
5894
|
+
logger11.warn(`\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5645
5895
|
});
|
|
5646
5896
|
await page.waitForTimeout(config.recognitionDelayMs);
|
|
5647
5897
|
const screenshotBuffer = await iframeLocator.screenshot();
|
|
@@ -5653,16 +5903,16 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5653
5903
|
});
|
|
5654
5904
|
const serialNumbers = extractCaptchaSerialNumbers(apiResponse);
|
|
5655
5905
|
if (apiResponse?.code !== config.recognitionSuccessCode || serialNumbers.length === 0) {
|
|
5656
|
-
|
|
5906
|
+
logger11.warn(
|
|
5657
5907
|
`\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\u3002code=${apiResponse?.code}, msg=${apiResponse?.msg || "unknown"}`
|
|
5658
5908
|
);
|
|
5659
5909
|
await refreshCaptcha(page, frame, config);
|
|
5660
5910
|
continue;
|
|
5661
5911
|
}
|
|
5662
|
-
|
|
5912
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u8BC6\u522B\u6210\u529F\uFF0C\u5E8F\u53F7\uFF1A${serialNumbers.join(", ")}`);
|
|
5663
5913
|
const dropTarget = await findCaptchaDropTarget(frame, config);
|
|
5664
5914
|
if (!dropTarget) {
|
|
5665
|
-
|
|
5915
|
+
logger11.warn("\u672A\u627E\u5230\u9A8C\u8BC1\u7801\u62D6\u62FD\u76EE\u6807\u533A\u57DF\u3002");
|
|
5666
5916
|
await refreshCaptcha(page, frame, config);
|
|
5667
5917
|
continue;
|
|
5668
5918
|
}
|
|
@@ -5673,7 +5923,7 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5673
5923
|
`Captcha image indexes could not be normalized. raw=${serialNumbers.join(", ")}, count=${orderedSourceImages.length}`
|
|
5674
5924
|
);
|
|
5675
5925
|
}
|
|
5676
|
-
|
|
5926
|
+
logger11.info(`\u9A8C\u8BC1\u7801\u89C6\u89C9\u4F4D\u5E8F\u6620\u5C04\uFF1A${normalizedIndexes.map((index) => index + 1).join(", ")}`);
|
|
5677
5927
|
for (const imageIndex of normalizedIndexes) {
|
|
5678
5928
|
if (imageIndex < 0 || imageIndex >= orderedSourceImages.length) {
|
|
5679
5929
|
throw new Error(
|
|
@@ -5705,52 +5955,52 @@ async function solveCaptcha(page, options = {}, dependencies = {}) {
|
|
|
5705
5955
|
}
|
|
5706
5956
|
}
|
|
5707
5957
|
const beforeSubmitState = await readPromptCaptchaState(frame, config);
|
|
5708
|
-
|
|
5958
|
+
logger11.info(
|
|
5709
5959
|
`\u63D0\u4EA4\u524D\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${beforeSubmitState.badgeCount}, selected=${beforeSubmitState.selectedCount}, submitDisabled=${beforeSubmitState.submitDisabled}`
|
|
5710
5960
|
);
|
|
5711
5961
|
const submitted = await clickCaptchaAction(frame, config.submitTexts, {
|
|
5712
5962
|
...config,
|
|
5713
5963
|
page,
|
|
5714
|
-
logger:
|
|
5964
|
+
logger: logger11,
|
|
5715
5965
|
forceMouse: true,
|
|
5716
5966
|
actionVisibleTimeoutMs: config.submitReadyTimeoutMs
|
|
5717
5967
|
}).catch(() => false);
|
|
5718
5968
|
if (!submitted) {
|
|
5719
|
-
|
|
5969
|
+
logger11.warn("\u672A\u627E\u5230\u63D0\u4EA4\u6309\u94AE\uFF0C\u53EF\u80FD\u4F1A\u81EA\u52A8\u63D0\u4EA4\u3002");
|
|
5720
5970
|
}
|
|
5721
5971
|
await page.waitForTimeout(config.submitWaitMs);
|
|
5722
5972
|
const afterSubmitState = await readPromptCaptchaState(frame, config);
|
|
5723
|
-
|
|
5973
|
+
logger11.info(
|
|
5724
5974
|
`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u72B6\u6001\uFF1Abadge=${afterSubmitState.badgeCount}, selected=${afterSubmitState.selectedCount}, submitDisabled=${afterSubmitState.submitDisabled}`
|
|
5725
5975
|
);
|
|
5726
5976
|
const stillVisible = await iframeLocator.isVisible({ timeout: config.containerVisibleTimeoutMs }).catch(() => false);
|
|
5727
5977
|
if (!stillVisible) {
|
|
5728
|
-
|
|
5978
|
+
logger11.info("\u9A8C\u8BC1\u7801\u8BC6\u522B\u5E76\u63D0\u4EA4\u6210\u529F\u3002");
|
|
5729
5979
|
return true;
|
|
5730
5980
|
}
|
|
5731
5981
|
await maybeCollectCaptchaDebugInfo(page, frame, iframeLocator, attempt, "submit-still-visible", config, {
|
|
5732
5982
|
beforeSubmitState,
|
|
5733
5983
|
afterSubmitState
|
|
5734
5984
|
}).catch((error) => {
|
|
5735
|
-
|
|
5985
|
+
logger11.warn(`\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801\u8C03\u8BD5\u6293\u53D6\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5736
5986
|
});
|
|
5737
|
-
|
|
5987
|
+
logger11.warn("\u63D0\u4EA4\u540E\u9A8C\u8BC1\u7801 iframe \u4ECD\u7136\u53EF\u89C1\uFF0C\u51C6\u5907\u5237\u65B0\u540E\u91CD\u8BD5\u3002");
|
|
5738
5988
|
await page.waitForTimeout(2e3);
|
|
5739
5989
|
await refreshCaptcha(page, frame, config);
|
|
5740
5990
|
} catch (error) {
|
|
5741
|
-
|
|
5991
|
+
logger11.error(`\u7B2C ${attempt}/${config.maxRetries} \u6B21\u9A8C\u8BC1\u7801\u8BC6\u522B\u5931\u8D25\uFF1A${error?.message || error}`);
|
|
5742
5992
|
}
|
|
5743
5993
|
if (attempt < config.maxRetries) {
|
|
5744
5994
|
await page.waitForTimeout(config.retryDelayBaseMs + attempt * config.retryDelayStepMs);
|
|
5745
5995
|
}
|
|
5746
5996
|
}
|
|
5747
|
-
|
|
5997
|
+
logger11.error(`\u91CD\u8BD5 ${config.maxRetries} \u6B21\u540E\uFF0C\u9A8C\u8BC1\u7801\u4ECD\u672A\u8BC6\u522B\u6210\u529F\u3002`);
|
|
5748
5998
|
return false;
|
|
5749
5999
|
}
|
|
5750
6000
|
var sloveCaptcha = solveCaptcha;
|
|
5751
6001
|
|
|
5752
6002
|
// src/chaptcha.js
|
|
5753
|
-
var
|
|
6003
|
+
var logger12 = createInternalLogger("Captcha");
|
|
5754
6004
|
var DEFAULT_CAPTCHA_RECOGNITION_OPTIONS = Object.freeze({
|
|
5755
6005
|
token: "eKJvBfwfN0YRav0-VD_44E2VBSfm7l0YtddUQ7cFySI",
|
|
5756
6006
|
apiUrl: "https://api.jfbym.com/api/YmServer/customApi"
|
|
@@ -5837,7 +6087,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
5837
6087
|
};
|
|
5838
6088
|
})();
|
|
5839
6089
|
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
5840
|
-
|
|
6090
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
5841
6091
|
cleanupFns.push(async () => {
|
|
5842
6092
|
try {
|
|
5843
6093
|
await page.evaluate((name) => {
|
|
@@ -5861,14 +6111,14 @@ function useCaptchaMonitor(page, options) {
|
|
|
5861
6111
|
}
|
|
5862
6112
|
};
|
|
5863
6113
|
page.on("framenavigated", frameHandler);
|
|
5864
|
-
|
|
6114
|
+
logger12.success("useCaptchaMonitor", `URL \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${urlPattern}`);
|
|
5865
6115
|
cleanupFns.push(async () => {
|
|
5866
6116
|
page.off("framenavigated", frameHandler);
|
|
5867
6117
|
});
|
|
5868
6118
|
}
|
|
5869
6119
|
return {
|
|
5870
6120
|
stop: async () => {
|
|
5871
|
-
|
|
6121
|
+
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
5872
6122
|
for (const fn of cleanupFns) {
|
|
5873
6123
|
await fn();
|
|
5874
6124
|
}
|
|
@@ -5907,7 +6157,7 @@ async function solveCaptchaWithStrategy(strategyName, page, options = {}) {
|
|
|
5907
6157
|
);
|
|
5908
6158
|
return strategy.sloveCaptcha(page, resolvedOptions, {
|
|
5909
6159
|
callCaptchaRecognitionApi,
|
|
5910
|
-
logger:
|
|
6160
|
+
logger: logger12
|
|
5911
6161
|
});
|
|
5912
6162
|
}
|
|
5913
6163
|
var Captcha = {
|
|
@@ -5918,7 +6168,7 @@ var Captcha = {
|
|
|
5918
6168
|
// src/mutation.js
|
|
5919
6169
|
import { createHash } from "node:crypto";
|
|
5920
6170
|
import { v4 as uuidv42 } from "uuid";
|
|
5921
|
-
var
|
|
6171
|
+
var logger13 = createInternalLogger("Mutation");
|
|
5922
6172
|
var MUTATION_MONITOR_MODE = Object.freeze({
|
|
5923
6173
|
Added: "added",
|
|
5924
6174
|
Changed: "changed",
|
|
@@ -5951,14 +6201,14 @@ var Mutation = {
|
|
|
5951
6201
|
const stableTime = options.stableTime ?? 5 * 1e3;
|
|
5952
6202
|
const timeout = options.timeout ?? 120 * 1e3;
|
|
5953
6203
|
const onMutation = options.onMutation;
|
|
5954
|
-
|
|
6204
|
+
logger13.start("waitForStable", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, \u7A33\u5B9A\u65F6\u95F4=${stableTime}ms`);
|
|
5955
6205
|
if (initialTimeout > 0) {
|
|
5956
6206
|
const selectorQuery = selectorList.join(",");
|
|
5957
6207
|
try {
|
|
5958
6208
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
5959
|
-
|
|
6209
|
+
logger13.info(`waitForStable \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
5960
6210
|
} catch (e) {
|
|
5961
|
-
|
|
6211
|
+
logger13.warning(`waitForStable \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
5962
6212
|
throw e;
|
|
5963
6213
|
}
|
|
5964
6214
|
}
|
|
@@ -5974,7 +6224,7 @@ var Mutation = {
|
|
|
5974
6224
|
return "__CONTINUE__";
|
|
5975
6225
|
}
|
|
5976
6226
|
});
|
|
5977
|
-
|
|
6227
|
+
logger13.info("waitForStable \u5DF2\u542F\u7528 onMutation \u56DE\u8C03");
|
|
5978
6228
|
} catch (e) {
|
|
5979
6229
|
}
|
|
5980
6230
|
}
|
|
@@ -6089,9 +6339,9 @@ var Mutation = {
|
|
|
6089
6339
|
{ selectorList, stableTime, timeout, callbackName, hasCallback: !!onMutation }
|
|
6090
6340
|
);
|
|
6091
6341
|
if (result.mutationCount === 0 && result.stableTime === 0) {
|
|
6092
|
-
|
|
6342
|
+
logger13.warning("waitForStable \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6093
6343
|
}
|
|
6094
|
-
|
|
6344
|
+
logger13.success("waitForStable", `DOM \u7A33\u5B9A, \u603B\u5171 ${result.mutationCount} \u6B21\u53D8\u5316${result.wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6095
6345
|
return result;
|
|
6096
6346
|
},
|
|
6097
6347
|
/**
|
|
@@ -6263,22 +6513,22 @@ var Mutation = {
|
|
|
6263
6513
|
return "__CONTINUE__";
|
|
6264
6514
|
}
|
|
6265
6515
|
};
|
|
6266
|
-
|
|
6516
|
+
logger13.start(
|
|
6267
6517
|
"waitForStableAcrossRoots",
|
|
6268
6518
|
`\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668(\u8DE8 root), \u7A33\u5B9A\u65F6\u95F4=${waitForStableTime}ms`
|
|
6269
6519
|
);
|
|
6270
6520
|
if (initialTimeout > 0) {
|
|
6271
6521
|
try {
|
|
6272
6522
|
await page.waitForSelector(selectorQuery, { timeout: initialTimeout });
|
|
6273
|
-
|
|
6523
|
+
logger13.info(`waitForStableAcrossRoots \u5DF2\u68C0\u6D4B\u5230\u5143\u7D20: ${selectorQuery}`);
|
|
6274
6524
|
} catch (e) {
|
|
6275
|
-
|
|
6525
|
+
logger13.warning(`waitForStableAcrossRoots \u521D\u59CB\u7B49\u5F85\u8D85\u65F6 (${initialTimeout}ms): ${selectorQuery}`);
|
|
6276
6526
|
throw e;
|
|
6277
6527
|
}
|
|
6278
6528
|
}
|
|
6279
6529
|
let state = await buildState();
|
|
6280
6530
|
if (!state?.hasMatched) {
|
|
6281
|
-
|
|
6531
|
+
logger13.warning("waitForStableAcrossRoots \u672A\u627E\u5230\u53EF\u76D1\u63A7\u7684\u5143\u7D20");
|
|
6282
6532
|
return { mutationCount: 0, stableTime: 0, wasPaused: false };
|
|
6283
6533
|
}
|
|
6284
6534
|
let mutationCount = 0;
|
|
@@ -6315,7 +6565,7 @@ var Mutation = {
|
|
|
6315
6565
|
if (lastState.snapshotKey !== lastSnapshotKey) {
|
|
6316
6566
|
lastSnapshotKey = lastState.snapshotKey;
|
|
6317
6567
|
mutationCount += 1;
|
|
6318
|
-
|
|
6568
|
+
logger13.info(
|
|
6319
6569
|
`waitForStableAcrossRoots \u53D8\u5316#${mutationCount}, len=${lastState.snapshotLength}, path=${lastState.primaryPath || "unknown"}, preview="${truncate(lastState.text, 120)}"`
|
|
6320
6570
|
);
|
|
6321
6571
|
const signal = await invokeMutationCallback({
|
|
@@ -6328,7 +6578,7 @@ var Mutation = {
|
|
|
6328
6578
|
continue;
|
|
6329
6579
|
}
|
|
6330
6580
|
if (!isPaused && stableSince > 0 && Date.now() - stableSince >= waitForStableTime) {
|
|
6331
|
-
|
|
6581
|
+
logger13.success("waitForStableAcrossRoots", `DOM \u7A33\u5B9A, \u603B\u5171 ${mutationCount} \u6B21\u53D8\u5316${wasPaused ? ", \u66FE\u6682\u505C\u8BA1\u65F6" : ""}`);
|
|
6332
6582
|
return {
|
|
6333
6583
|
mutationCount,
|
|
6334
6584
|
stableTime: waitForStableTime,
|
|
@@ -6355,7 +6605,7 @@ var Mutation = {
|
|
|
6355
6605
|
const onMutation = options.onMutation;
|
|
6356
6606
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6357
6607
|
const mode = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6358
|
-
|
|
6608
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode}`);
|
|
6359
6609
|
const monitorKey = generateKey("pk_mon");
|
|
6360
6610
|
const callbackName = generateKey("pk_mon_cb");
|
|
6361
6611
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6498,7 +6748,7 @@ var Mutation = {
|
|
|
6498
6748
|
return total;
|
|
6499
6749
|
};
|
|
6500
6750
|
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
6501
|
-
|
|
6751
|
+
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
6502
6752
|
return {
|
|
6503
6753
|
stop: async () => {
|
|
6504
6754
|
let totalMutations = 0;
|
|
@@ -6511,7 +6761,7 @@ var Mutation = {
|
|
|
6511
6761
|
}, cleanerName);
|
|
6512
6762
|
} catch (e) {
|
|
6513
6763
|
}
|
|
6514
|
-
|
|
6764
|
+
logger13.success("useMonitor.stop", `\u76D1\u63A7\u5DF2\u505C\u6B62, \u5171 ${totalMutations} \u6B21\u53D8\u5316`);
|
|
6515
6765
|
return { totalMutations };
|
|
6516
6766
|
}
|
|
6517
6767
|
};
|
|
@@ -7380,7 +7630,7 @@ var createTemplateLogger = (baseLogger = createBaseLogger()) => {
|
|
|
7380
7630
|
};
|
|
7381
7631
|
var getDefaultBaseLogger = () => createBaseLogger("");
|
|
7382
7632
|
var Logger = {
|
|
7383
|
-
setLogger: (
|
|
7633
|
+
setLogger: (logger17) => setDefaultLogger(logger17),
|
|
7384
7634
|
info: (message) => getDefaultBaseLogger().info(message),
|
|
7385
7635
|
success: (message) => getDefaultBaseLogger().success(message),
|
|
7386
7636
|
warning: (message) => getDefaultBaseLogger().warning(message),
|
|
@@ -7388,8 +7638,8 @@ var Logger = {
|
|
|
7388
7638
|
error: (message) => getDefaultBaseLogger().error(message),
|
|
7389
7639
|
debug: (message) => getDefaultBaseLogger().debug(message),
|
|
7390
7640
|
start: (message) => getDefaultBaseLogger().start(message),
|
|
7391
|
-
useTemplate: (
|
|
7392
|
-
if (
|
|
7641
|
+
useTemplate: (logger17) => {
|
|
7642
|
+
if (logger17) return createTemplateLogger(createBaseLogger("", logger17));
|
|
7393
7643
|
return createTemplateLogger();
|
|
7394
7644
|
}
|
|
7395
7645
|
};
|
|
@@ -7463,7 +7713,7 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
|
|
|
7463
7713
|
];
|
|
7464
7714
|
var cachedStripLogoSrcPromise = null;
|
|
7465
7715
|
var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
|
|
7466
|
-
var
|
|
7716
|
+
var logger14 = createInternalLogger("Watermarkify");
|
|
7467
7717
|
var normalizeText = (value) => String(value || "").trim();
|
|
7468
7718
|
var toInline = (value, maxLen = 200) => {
|
|
7469
7719
|
const text = normalizeText(value);
|
|
@@ -7705,9 +7955,9 @@ var resolveWithCustomResolver = async (page, baseMeta, options = {}) => {
|
|
|
7705
7955
|
location: toInline(resolved.location, 80)
|
|
7706
7956
|
};
|
|
7707
7957
|
if (enrichment.ip || enrichment.location) {
|
|
7708
|
-
|
|
7958
|
+
logger14.info(`\u81EA\u5B9A\u4E49 resolver \u547D\u4E2D: ip=${enrichment.ip || "-"}, loc=${enrichment.location || "-"}`);
|
|
7709
7959
|
} else {
|
|
7710
|
-
|
|
7960
|
+
logger14.warning("\u81EA\u5B9A\u4E49 resolver \u5DF2\u6267\u884C\uFF0C\u4F46\u672A\u8FD4\u56DE IP/Loc");
|
|
7711
7961
|
}
|
|
7712
7962
|
return enrichment;
|
|
7713
7963
|
} finally {
|
|
@@ -7893,12 +8143,12 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
7893
8143
|
};
|
|
7894
8144
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}) => {
|
|
7895
8145
|
if (!page || typeof page.context !== "function") {
|
|
7896
|
-
|
|
8146
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u7F3A\u5C11\u53EF\u7528 page");
|
|
7897
8147
|
return buffer;
|
|
7898
8148
|
}
|
|
7899
8149
|
const renderScope = await openProbePage(page);
|
|
7900
8150
|
if (!renderScope?.page) {
|
|
7901
|
-
|
|
8151
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA render page");
|
|
7902
8152
|
return buffer;
|
|
7903
8153
|
}
|
|
7904
8154
|
try {
|
|
@@ -7943,13 +8193,13 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
7943
8193
|
fullPage: true,
|
|
7944
8194
|
animations: "disabled"
|
|
7945
8195
|
}).catch((error) => {
|
|
7946
|
-
|
|
8196
|
+
logger14.warning(`watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
7947
8197
|
return null;
|
|
7948
8198
|
});
|
|
7949
8199
|
if (Buffer.isBuffer(composed) && composed.length > 0) {
|
|
7950
8200
|
return composed;
|
|
7951
8201
|
}
|
|
7952
|
-
|
|
8202
|
+
logger14.warning("watermarkify \u6D4F\u89C8\u5668\u5408\u6210\u5931\u8D25: \u672A\u5F97\u5230\u6709\u6548\u622A\u56FE\u7ED3\u679C");
|
|
7953
8203
|
return buffer;
|
|
7954
8204
|
} finally {
|
|
7955
8205
|
await renderScope.close().catch(() => {
|
|
@@ -7962,7 +8212,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7962
8212
|
}
|
|
7963
8213
|
const probeScope = await openProbePage(page);
|
|
7964
8214
|
if (!probeScope?.page) {
|
|
7965
|
-
|
|
8215
|
+
logger14.warning("ipLookup \u8DF3\u8FC7: \u65E0\u6CD5\u521B\u5EFA probe page");
|
|
7966
8216
|
return null;
|
|
7967
8217
|
}
|
|
7968
8218
|
const timeoutMs = Math.max(
|
|
@@ -7971,12 +8221,12 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7971
8221
|
);
|
|
7972
8222
|
try {
|
|
7973
8223
|
const probePage = probeScope.page;
|
|
7974
|
-
|
|
8224
|
+
logger14.info(`ipLookup \u5C1D\u8BD5: url=${DEFAULT_IP_LOOKUP_URL}, timeoutMs=${timeoutMs}`);
|
|
7975
8225
|
const response = await probePage.goto(DEFAULT_IP_LOOKUP_URL, {
|
|
7976
8226
|
waitUntil: "commit",
|
|
7977
8227
|
timeout: timeoutMs
|
|
7978
8228
|
}).catch((error) => {
|
|
7979
|
-
|
|
8229
|
+
logger14.warning(`ipLookup \u8BF7\u6C42\u5931\u8D25: url=${DEFAULT_IP_LOOKUP_URL}, error=${error instanceof Error ? error.message : String(error)}`);
|
|
7980
8230
|
return null;
|
|
7981
8231
|
});
|
|
7982
8232
|
const status = response && typeof response.status === "function" ? response.status() : 0;
|
|
@@ -7998,13 +8248,13 @@ var resolveWithIpLookup = async (page, options = {}) => {
|
|
|
7998
8248
|
}
|
|
7999
8249
|
const parsed = parseIpIpJsonResponse(rawText);
|
|
8000
8250
|
if (parsed?.ip || parsed?.location) {
|
|
8001
|
-
|
|
8251
|
+
logger14.info(`ipLookup \u6210\u529F: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, ip=${parsed.ip || "-"}, loc=${parsed.location || "-"}`);
|
|
8002
8252
|
return parsed;
|
|
8003
8253
|
}
|
|
8004
|
-
|
|
8254
|
+
logger14.warning(`ipLookup \u672A\u89E3\u6790\u51FA IP/Loc: url=${DEFAULT_IP_LOOKUP_URL}, status=${status || "-"}, contentType=${contentType || "-"}, preview=${shortenTail(rawText, 120) || "[empty]"}`);
|
|
8005
8255
|
return null;
|
|
8006
8256
|
} catch (error) {
|
|
8007
|
-
|
|
8257
|
+
logger14.warning(`ipLookup \u6267\u884C\u5F02\u5E38\uFF0C\u672A\u83B7\u5F97 IP/Loc: ${error instanceof Error ? error.message : String(error)}`);
|
|
8008
8258
|
return null;
|
|
8009
8259
|
} finally {
|
|
8010
8260
|
await probeScope.close().catch(() => {
|
|
@@ -8018,10 +8268,10 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8018
8268
|
ip: toInline(options.ip, 80),
|
|
8019
8269
|
location: toInline(options.location, 80)
|
|
8020
8270
|
};
|
|
8021
|
-
|
|
8271
|
+
logger14.info(`enrichment \u5F00\u59CB: host=${baseMeta.hostname || "-"}, hasPresetIp=${Boolean(merged.ip)}, hasPresetLoc=${Boolean(merged.location)}, ipLookup=${options.ipLookup !== false}`);
|
|
8022
8272
|
if (!merged.ip || !merged.location) {
|
|
8023
8273
|
if (cached?.ip || cached?.location) {
|
|
8024
|
-
|
|
8274
|
+
logger14.info(`enrichment \u547D\u4E2D\u4E0A\u4E0B\u6587\u7F13\u5B58: ip=${cached.ip || "-"}, loc=${cached.location || "-"}`);
|
|
8025
8275
|
}
|
|
8026
8276
|
fillEnrichment(merged, cached);
|
|
8027
8277
|
}
|
|
@@ -8045,15 +8295,15 @@ var resolveEnrichment = async (page, baseMeta, options) => {
|
|
|
8045
8295
|
"x-geo-country"
|
|
8046
8296
|
]), 80);
|
|
8047
8297
|
if (!merged.location || isWeakLocationValue(merged.location) && headerLocation) {
|
|
8048
|
-
|
|
8298
|
+
logger14.info(`enrichment \u4F7F\u7528\u54CD\u5E94\u5934\u8865\u5145 Loc: ${headerLocation || "-"}`);
|
|
8049
8299
|
merged.location = headerLocation || merged.location;
|
|
8050
8300
|
}
|
|
8051
8301
|
}
|
|
8052
8302
|
writeCachedEnrichment(page, merged);
|
|
8053
8303
|
if (merged.ip || merged.location) {
|
|
8054
|
-
|
|
8304
|
+
logger14.info(`enrichment \u5B8C\u6210: ip=${merged.ip || "-"}, loc=${merged.location || "-"}`);
|
|
8055
8305
|
} else {
|
|
8056
|
-
|
|
8306
|
+
logger14.warning("enrichment \u5B8C\u6210: \u672A\u83B7\u5F97 IP/Loc");
|
|
8057
8307
|
}
|
|
8058
8308
|
return merged;
|
|
8059
8309
|
};
|
|
@@ -8866,7 +9116,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8866
9116
|
}
|
|
8867
9117
|
const imageInfo = readImageInfo(buffer);
|
|
8868
9118
|
if (!imageInfo.width || !imageInfo.height || !imageInfo.mimeType) {
|
|
8869
|
-
|
|
9119
|
+
logger14.warning("watermarkify \u8DF3\u8FC7: \u65E0\u6CD5\u89E3\u6790\u622A\u56FE\u5C3A\u5BF8\u6216\u683C\u5F0F");
|
|
8870
9120
|
return buffer;
|
|
8871
9121
|
}
|
|
8872
9122
|
const isMobileStrip = normalizeDevice(meta.device) === Device.Mobile && hasStrip;
|
|
@@ -8884,7 +9134,7 @@ var watermarkifyScreenshotBuffer = async (buffer, meta, page = null) => {
|
|
|
8884
9134
|
|
|
8885
9135
|
// src/internals/compression.js
|
|
8886
9136
|
import { Jimp, JimpMime, ResizeStrategy } from "jimp";
|
|
8887
|
-
var
|
|
9137
|
+
var logger15 = createInternalLogger("Compression");
|
|
8888
9138
|
var DEFAULT_SCREENSHOT_MAX_BYTES = 5 * 1024 * 1024;
|
|
8889
9139
|
var DEFAULT_SCREENSHOT_OUTPUT_TYPE = "jpeg";
|
|
8890
9140
|
var DEFAULT_SCREENSHOT_QUALITY = 0.72;
|
|
@@ -9003,18 +9253,18 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9003
9253
|
return buffer.toString("base64");
|
|
9004
9254
|
}
|
|
9005
9255
|
const result = await compressImageBuffer(buffer, compression).catch((error) => {
|
|
9006
|
-
|
|
9256
|
+
logger15.warning(`captureScreen \u538B\u7F29\u5931\u8D25\uFF0C\u8FD4\u56DE\u539F\u56FE: ${error instanceof Error ? error.message : String(error)}`);
|
|
9007
9257
|
return null;
|
|
9008
9258
|
});
|
|
9009
9259
|
if (!result?.buffer) {
|
|
9010
9260
|
return buffer.toString("base64");
|
|
9011
9261
|
}
|
|
9012
9262
|
if (result.withinLimit) {
|
|
9013
|
-
|
|
9263
|
+
logger15.info(
|
|
9014
9264
|
`captureScreen \u5DF2\u538B\u7F29: ${originalBytes} -> ${result.bytes} bytes, format=${result.format}, quality=${result.quality}, scale=${result.scale}, size=${result.width}x${result.height}`
|
|
9015
9265
|
);
|
|
9016
9266
|
} else {
|
|
9017
|
-
|
|
9267
|
+
logger15.warning(
|
|
9018
9268
|
`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}`
|
|
9019
9269
|
);
|
|
9020
9270
|
}
|
|
@@ -9022,7 +9272,7 @@ var compressImageBufferToBase64 = async (buffer, compression) => {
|
|
|
9022
9272
|
};
|
|
9023
9273
|
|
|
9024
9274
|
// src/share.js
|
|
9025
|
-
var
|
|
9275
|
+
var logger16 = createInternalLogger("Share");
|
|
9026
9276
|
var DEFAULT_TIMEOUT_MS2 = 50 * 1e3;
|
|
9027
9277
|
var DEFAULT_PAYLOAD_SNAPSHOT_MAX_LEN = 500;
|
|
9028
9278
|
var DEFAULT_POLL_INTERVAL_MS = 120;
|
|
@@ -9159,7 +9409,7 @@ var createDomShareMonitor = async (page, options = {}) => {
|
|
|
9159
9409
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9160
9410
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9161
9411
|
let matched = false;
|
|
9162
|
-
|
|
9412
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode}`);
|
|
9163
9413
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9164
9414
|
mode,
|
|
9165
9415
|
onMutation: (context = {}) => {
|
|
@@ -9177,12 +9427,12 @@ ${text}`;
|
|
|
9177
9427
|
});
|
|
9178
9428
|
}
|
|
9179
9429
|
if (mutationCount <= 5 || mutationCount % 50 === 0) {
|
|
9180
|
-
|
|
9430
|
+
logger16.info(`DOM \u53D8\u5316\u5DF2\u6355\u83B7: mutationCount=${mutationCount}, mutationNodes=${mutationNodes.length}`);
|
|
9181
9431
|
}
|
|
9182
9432
|
const [candidate] = Utils.parseLinks(rawDom, { prefix }) || [];
|
|
9183
9433
|
if (!candidate) return;
|
|
9184
9434
|
matched = true;
|
|
9185
|
-
|
|
9435
|
+
logger16.success("captureLink.domHit", `DOM \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: mutationCount=${mutationCount}, link=${candidate}`);
|
|
9186
9436
|
if (onMatch) {
|
|
9187
9437
|
onMatch({
|
|
9188
9438
|
link: candidate,
|
|
@@ -9198,7 +9448,7 @@ ${text}`;
|
|
|
9198
9448
|
return {
|
|
9199
9449
|
stop: async () => {
|
|
9200
9450
|
const result = await monitor.stop();
|
|
9201
|
-
|
|
9451
|
+
logger16.info(`DOM \u76D1\u542C\u5DF2\u505C\u6B62: totalMutations=${result?.totalMutations || 0}`);
|
|
9202
9452
|
return result;
|
|
9203
9453
|
}
|
|
9204
9454
|
};
|
|
@@ -9247,8 +9497,8 @@ var Share = {
|
|
|
9247
9497
|
if (share.mode === "response" && apiMatchers.length === 0) {
|
|
9248
9498
|
throw new Error("Share.captureLink requires share.xurl[0] api matcher when mode=response");
|
|
9249
9499
|
}
|
|
9250
|
-
|
|
9251
|
-
|
|
9500
|
+
logger16.start("captureLink", `mode=${share.mode}, timeoutMs=${timeoutDisabled ? "disabled" : timeoutMs}, prefix=${share.prefix}`);
|
|
9501
|
+
logger16.info(`captureLink \u914D\u7F6E: xurl=${toJsonInline(share.xurl)}, domMode=${domMode}, domSelectors=${toJsonInline(domSelectors, 120)}`);
|
|
9252
9502
|
const stats = {
|
|
9253
9503
|
actionTimedOut: false,
|
|
9254
9504
|
domMutationCount: 0,
|
|
@@ -9260,7 +9510,7 @@ var Share = {
|
|
|
9260
9510
|
responseSampleUrls: []
|
|
9261
9511
|
};
|
|
9262
9512
|
if (isAborted()) {
|
|
9263
|
-
|
|
9513
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9264
9514
|
return {
|
|
9265
9515
|
link: null,
|
|
9266
9516
|
payloadText: "",
|
|
@@ -9283,7 +9533,7 @@ var Share = {
|
|
|
9283
9533
|
link: validated,
|
|
9284
9534
|
payloadText: String(payloadText || "")
|
|
9285
9535
|
};
|
|
9286
|
-
|
|
9536
|
+
logger16.info(`\u5019\u9009\u94FE\u63A5\u5DF2\u786E\u8BA4: source=${source}, link=${validated}`);
|
|
9287
9537
|
return true;
|
|
9288
9538
|
};
|
|
9289
9539
|
const resolveResponseCandidate = (responseText) => {
|
|
@@ -9318,7 +9568,7 @@ var Share = {
|
|
|
9318
9568
|
try {
|
|
9319
9569
|
await monitor.stop();
|
|
9320
9570
|
} catch (error) {
|
|
9321
|
-
|
|
9571
|
+
logger16.warning(`\u505C\u6B62 DOM \u76D1\u542C\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`);
|
|
9322
9572
|
}
|
|
9323
9573
|
};
|
|
9324
9574
|
const onResponse = async (response) => {
|
|
@@ -9332,29 +9582,29 @@ var Share = {
|
|
|
9332
9582
|
stats.responseSampleUrls.push(url);
|
|
9333
9583
|
}
|
|
9334
9584
|
if (stats.responseObserved <= 5) {
|
|
9335
|
-
|
|
9585
|
+
logger16.info(`\u63A5\u53E3\u54CD\u5E94\u91C7\u6837(${stats.responseObserved}): ${url}`);
|
|
9336
9586
|
}
|
|
9337
9587
|
if (!apiMatchers.some((matcher) => url.includes(matcher))) return;
|
|
9338
9588
|
stats.responseMatched += 1;
|
|
9339
9589
|
stats.lastMatchedUrl = url;
|
|
9340
|
-
|
|
9590
|
+
logger16.info(`\u63A5\u53E3\u547D\u4E2D\u5339\u914D(${stats.responseMatched}): ${url}`);
|
|
9341
9591
|
const text = await response.text();
|
|
9342
9592
|
const hit = resolveResponseCandidate(text);
|
|
9343
9593
|
if (!hit?.link) {
|
|
9344
9594
|
if (stats.responseMatched <= 3) {
|
|
9345
|
-
|
|
9595
|
+
logger16.info(`\u63A5\u53E3\u89E3\u6790\u5B8C\u6210\u4F46\u672A\u63D0\u53D6\u5230\u5206\u4EAB\u94FE\u63A5: payloadSize=${text.length}`);
|
|
9346
9596
|
}
|
|
9347
9597
|
return;
|
|
9348
9598
|
}
|
|
9349
9599
|
stats.responseResolved += 1;
|
|
9350
|
-
|
|
9600
|
+
logger16.success("captureLink.responseHit", `\u63A5\u53E3\u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: url=${url}, link=${hit.link}`);
|
|
9351
9601
|
setCandidate("response", hit.link, hit.payloadText);
|
|
9352
9602
|
} catch (error) {
|
|
9353
|
-
|
|
9603
|
+
logger16.warning(`\u63A5\u53E3\u54CD\u5E94\u5904\u7406\u5F02\u5E38: ${error instanceof Error ? error.message : String(error)}`);
|
|
9354
9604
|
}
|
|
9355
9605
|
};
|
|
9356
9606
|
if (share.mode === "dom") {
|
|
9357
|
-
|
|
9607
|
+
logger16.info("\u5F53\u524D\u4E3A DOM \u6A21\u5F0F\uFF0C\u4EC5\u542F\u7528 DOM \u76D1\u542C");
|
|
9358
9608
|
domMonitor = await createDomShareMonitor(page, {
|
|
9359
9609
|
prefix: share.prefix,
|
|
9360
9610
|
selectors: domSelectors,
|
|
@@ -9369,17 +9619,17 @@ var Share = {
|
|
|
9369
9619
|
});
|
|
9370
9620
|
}
|
|
9371
9621
|
if (share.mode === "response") {
|
|
9372
|
-
|
|
9622
|
+
logger16.info(`\u5F53\u524D\u4E3A\u63A5\u53E3\u6A21\u5F0F\uFF0C\u6302\u8F7D response \u76D1\u542C: apiMatchers=${toJsonInline(apiMatchers, 160)}`);
|
|
9373
9623
|
page.on("response", onResponse);
|
|
9374
9624
|
}
|
|
9375
9625
|
if (share.mode === "custom") {
|
|
9376
|
-
|
|
9626
|
+
logger16.info("\u5F53\u524D\u4E3A custom \u6A21\u5F0F\uFF0C\u5C06\u4F7F\u7528 performActions \u8FD4\u56DE\u503C");
|
|
9377
9627
|
}
|
|
9378
9628
|
const deadline = timeoutDisabled ? Infinity : Date.now() + timeoutMs;
|
|
9379
9629
|
const getRemainingMs = () => timeoutDisabled ? Infinity : Math.max(0, deadline - Date.now());
|
|
9380
9630
|
try {
|
|
9381
9631
|
const actionTimeout = getRemainingMs();
|
|
9382
|
-
|
|
9632
|
+
logger16.start("captureLink.performActions", `\u6267\u884C\u52A8\u4F5C\u9884\u7B97=${timeoutDisabled ? "disabled" : `${actionTimeout}ms`}`);
|
|
9383
9633
|
let actionValue;
|
|
9384
9634
|
if (!isAborted() && actionTimeout > 0) {
|
|
9385
9635
|
let timer = null;
|
|
@@ -9392,30 +9642,30 @@ var Share = {
|
|
|
9392
9642
|
]);
|
|
9393
9643
|
if (timer) clearTimeout(timer);
|
|
9394
9644
|
if (actionResult.type === "error") {
|
|
9395
|
-
|
|
9645
|
+
logger16.fail("captureLink.performActions", actionResult.error);
|
|
9396
9646
|
throw actionResult.error;
|
|
9397
9647
|
}
|
|
9398
9648
|
if (actionResult.type === "timeout") {
|
|
9399
9649
|
stats.actionTimedOut = true;
|
|
9400
|
-
|
|
9650
|
+
logger16.warning(`performActions \u5DF2\u8D85\u65F6 (${actionTimeout}ms)\uFF0C\u52A8\u4F5C\u53EF\u80FD\u4ECD\u5728\u5F02\u6B65\u6267\u884C`);
|
|
9401
9651
|
} else {
|
|
9402
9652
|
actionValue = actionResult.result;
|
|
9403
|
-
|
|
9653
|
+
logger16.success("captureLink.performActions", "\u6267\u884C\u52A8\u4F5C\u5B8C\u6210");
|
|
9404
9654
|
}
|
|
9405
9655
|
}
|
|
9406
9656
|
if (share.mode === "custom") {
|
|
9407
9657
|
const customLink = typeof actionValue === "string" ? actionValue : actionValue?.link || actionValue?.payloadText;
|
|
9408
9658
|
const customPayloadText = typeof actionValue === "string" ? actionValue : actionValue?.payloadText;
|
|
9409
9659
|
if (setCandidate("custom", customLink, customPayloadText)) {
|
|
9410
|
-
|
|
9660
|
+
logger16.success("captureLink.customResult", `custom \u547D\u4E2D\u5206\u4EAB\u94FE\u63A5: link=${candidates.custom.link}`);
|
|
9411
9661
|
} else {
|
|
9412
|
-
|
|
9662
|
+
logger16.warning("performActions \u6267\u884C\u5B8C\u6210\u4F46\u672A\u8FD4\u56DE\u6709\u6548\u5206\u4EAB\u94FE\u63A5");
|
|
9413
9663
|
}
|
|
9414
9664
|
}
|
|
9415
9665
|
let nextProgressLogTs = Date.now() + 3e3;
|
|
9416
9666
|
while (true) {
|
|
9417
9667
|
if (isAborted()) {
|
|
9418
|
-
|
|
9668
|
+
logger16.warning(`captureLink \u5DF2\u53D6\u6D88: ${abortReason()}`);
|
|
9419
9669
|
return {
|
|
9420
9670
|
link: null,
|
|
9421
9671
|
payloadText: "",
|
|
@@ -9425,7 +9675,7 @@ var Share = {
|
|
|
9425
9675
|
}
|
|
9426
9676
|
const selected = candidates[share.mode];
|
|
9427
9677
|
if (selected?.link) {
|
|
9428
|
-
|
|
9678
|
+
logger16.success("captureLink", `\u6355\u83B7\u6210\u529F: source=${share.mode}, link=${selected.link}`);
|
|
9429
9679
|
return {
|
|
9430
9680
|
link: selected.link,
|
|
9431
9681
|
payloadText: selected.payloadText,
|
|
@@ -9438,7 +9688,7 @@ var Share = {
|
|
|
9438
9688
|
if (remaining <= 0) break;
|
|
9439
9689
|
const now = Date.now();
|
|
9440
9690
|
if (now >= nextProgressLogTs) {
|
|
9441
|
-
|
|
9691
|
+
logger16.info(
|
|
9442
9692
|
`captureLink \u7B49\u5F85\u4E2D: remaining=${timeoutDisabled ? "disabled" : `${remaining}ms`}, domMutationCount=${stats.domMutationCount}, responseMatched=${stats.responseMatched}`
|
|
9443
9693
|
);
|
|
9444
9694
|
nextProgressLogTs = now + 5e3;
|
|
@@ -9446,11 +9696,11 @@ var Share = {
|
|
|
9446
9696
|
await delay4(Math.max(0, Math.min(DEFAULT_POLL_INTERVAL_MS, remaining)));
|
|
9447
9697
|
}
|
|
9448
9698
|
if (!timeoutDisabled && share.mode === "response" && stats.responseMatched === 0) {
|
|
9449
|
-
|
|
9699
|
+
logger16.warning(
|
|
9450
9700
|
`\u63A5\u53E3\u76D1\u542C\u672A\u547D\u4E2D: apiMatchers=${toJsonInline(apiMatchers, 220)}, \u54CD\u5E94\u6837\u672CURLs=${toJsonInline(stats.responseSampleUrls, 420)}`
|
|
9451
9701
|
);
|
|
9452
9702
|
}
|
|
9453
|
-
|
|
9703
|
+
logger16.warning(
|
|
9454
9704
|
`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"}`
|
|
9455
9705
|
);
|
|
9456
9706
|
return {
|
|
@@ -9462,7 +9712,7 @@ var Share = {
|
|
|
9462
9712
|
} finally {
|
|
9463
9713
|
if (share.mode === "response") {
|
|
9464
9714
|
page.off("response", onResponse);
|
|
9465
|
-
|
|
9715
|
+
logger16.info("response \u76D1\u542C\u5DF2\u5378\u8F7D");
|
|
9466
9716
|
}
|
|
9467
9717
|
await stopDomMonitor();
|
|
9468
9718
|
}
|
|
@@ -9505,14 +9755,15 @@ var Share = {
|
|
|
9505
9755
|
|
|
9506
9756
|
// entrys/node.js
|
|
9507
9757
|
Logger.setLogger(crawleeLog);
|
|
9508
|
-
var usePlaywrightToolKit = () => {
|
|
9509
|
-
|
|
9758
|
+
var usePlaywrightToolKit = (mode = "default") => {
|
|
9759
|
+
const launchModule = mode === "cloakbrowser" ? createCloakLaunchModule(Launch) : Launch;
|
|
9760
|
+
const toolkit = {
|
|
9510
9761
|
ApifyKit,
|
|
9511
9762
|
AntiCheat,
|
|
9512
9763
|
DeviceInput,
|
|
9513
9764
|
DeviceView,
|
|
9514
9765
|
Humanize: Humanize2,
|
|
9515
|
-
Launch,
|
|
9766
|
+
Launch: launchModule,
|
|
9516
9767
|
LiveView,
|
|
9517
9768
|
Constants: constants_exports,
|
|
9518
9769
|
Utils,
|
|
@@ -9526,6 +9777,7 @@ var usePlaywrightToolKit = () => {
|
|
|
9526
9777
|
ByPass,
|
|
9527
9778
|
$Internals: { LOG_TEMPLATES, stripAnsi }
|
|
9528
9779
|
};
|
|
9780
|
+
return toolkit;
|
|
9529
9781
|
};
|
|
9530
9782
|
export {
|
|
9531
9783
|
usePlaywrightToolKit
|