@skrillex1224/playwright-toolkit 3.0.7 → 3.0.9
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 +33 -100
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +34 -101
- package/dist/index.js.map +2 -2
- package/dist/internals/proxy-meter.js +51 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1196,6 +1196,18 @@ var ensureLogPath = () => {
|
|
|
1196
1196
|
const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
|
|
1197
1197
|
return import_path.default.join(baseDir, label);
|
|
1198
1198
|
};
|
|
1199
|
+
var ensureStdioLogPath = (logPath) => `${logPath}.stdio.log`;
|
|
1200
|
+
var writeChildOutput = (stream, output, prefix) => {
|
|
1201
|
+
if (!stream || !output) return;
|
|
1202
|
+
output.on("data", (chunk) => {
|
|
1203
|
+
const text = chunk?.toString?.() || String(chunk || "");
|
|
1204
|
+
if (!text) return;
|
|
1205
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1206
|
+
if (!line) continue;
|
|
1207
|
+
stream.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${prefix} ${line}\n`);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
};
|
|
1199
1211
|
var readSnapshot = (logPath) => {
|
|
1200
1212
|
if (!logPath || !(0, import_fs.existsSync)(logPath)) return null;
|
|
1201
1213
|
try {
|
|
@@ -1363,6 +1375,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
1363
1375
|
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
1364
1376
|
const port = pickFreePort();
|
|
1365
1377
|
const logPath = ensureLogPath();
|
|
1378
|
+
const stdioLogPath = ensureStdioLogPath(logPath);
|
|
1366
1379
|
const scriptPath = resolveScriptPath();
|
|
1367
1380
|
const debugMode = Boolean(options.debugMode);
|
|
1368
1381
|
const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
|
|
@@ -1375,19 +1388,26 @@ var startProxyMeter = (options = {}) => {
|
|
|
1375
1388
|
PROXY_METER_DEBUG: debugMode ? "1" : "0",
|
|
1376
1389
|
PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
|
|
1377
1390
|
};
|
|
1391
|
+
const stdioLog = (0, import_fs.createWriteStream)(stdioLogPath, { flags: "a" });
|
|
1392
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] start script=${scriptPath} port=${port} snapshot=${logPath}\n`);
|
|
1378
1393
|
const child = (0, import_child_process.spawn)(process.execPath, [scriptPath], {
|
|
1379
1394
|
env,
|
|
1380
|
-
stdio: ["ignore", "
|
|
1395
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1381
1396
|
});
|
|
1382
|
-
child.
|
|
1397
|
+
writeChildOutput(stdioLog, child.stdout, "stdout");
|
|
1398
|
+
writeChildOutput(stdioLog, child.stderr, "stderr");
|
|
1399
|
+
child.once("exit", (code, signal) => {
|
|
1400
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] exit code=${code ?? ""} signal=${signal ?? ""}\n`);
|
|
1401
|
+
stdioLog.end();
|
|
1383
1402
|
if (code && code !== 0) {
|
|
1384
|
-
logger2.warn(`[proxy-meter] exited with code ${code}`);
|
|
1403
|
+
logger2.warn(`[proxy-meter] exited with code ${code}; stdio=${stdioLogPath}`);
|
|
1385
1404
|
}
|
|
1386
1405
|
});
|
|
1387
1406
|
runtime = {
|
|
1388
1407
|
proc: child,
|
|
1389
1408
|
port,
|
|
1390
1409
|
logPath,
|
|
1410
|
+
stdioLogPath,
|
|
1391
1411
|
startedAt: Date.now()
|
|
1392
1412
|
};
|
|
1393
1413
|
registerCleanup();
|
|
@@ -5318,49 +5338,6 @@ var normalizeStringArray = (value) => {
|
|
|
5318
5338
|
}
|
|
5319
5339
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5320
5340
|
};
|
|
5321
|
-
var hashStableSeed = (value = "") => {
|
|
5322
|
-
const raw = String(value || "").trim();
|
|
5323
|
-
if (!raw) return "";
|
|
5324
|
-
let hash = 2166136261;
|
|
5325
|
-
for (let index = 0; index < raw.length; index += 1) {
|
|
5326
|
-
hash ^= raw.charCodeAt(index);
|
|
5327
|
-
hash = Math.imul(hash, 16777619);
|
|
5328
|
-
}
|
|
5329
|
-
const normalized = hash >>> 0 || 1;
|
|
5330
|
-
return String(normalized);
|
|
5331
|
-
};
|
|
5332
|
-
var extractProxySeedSource = (proxyConfiguration = {}) => {
|
|
5333
|
-
const config = normalizeObject2(proxyConfiguration);
|
|
5334
|
-
return String(config.proxy_url || "").trim();
|
|
5335
|
-
};
|
|
5336
|
-
var resolveCloakRuntimeHints = (runtimeState = {}, proxyConfiguration = {}, cloakOptions = {}) => {
|
|
5337
|
-
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5338
|
-
const browserProfileCore = RuntimeEnv.getBrowserProfileCore(runtimeState);
|
|
5339
|
-
const baseConfig = DefaultAntiCheat.getBaseConfig();
|
|
5340
|
-
const locale = String(
|
|
5341
|
-
normalizedCloakOptions.locale || browserProfileCore?.locale || baseConfig.locale || ""
|
|
5342
|
-
).trim();
|
|
5343
|
-
const timezone = String(
|
|
5344
|
-
normalizedCloakOptions.timezone || normalizedCloakOptions.timezoneId || browserProfileCore?.timezone_id || baseConfig.timezoneId || ""
|
|
5345
|
-
).trim();
|
|
5346
|
-
const explicitArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5347
|
-
const hasExplicitFingerprint = explicitArgs.some((arg) => arg.startsWith("--fingerprint="));
|
|
5348
|
-
const fingerprintSeedSource = String(
|
|
5349
|
-
runtimeState?.envId || browserProfileCore?.schema_version && JSON.stringify({
|
|
5350
|
-
envId: runtimeState?.envId || "",
|
|
5351
|
-
timezone: browserProfileCore?.timezone_id || "",
|
|
5352
|
-
locale: browserProfileCore?.locale || "",
|
|
5353
|
-
browserMajorVersion: browserProfileCore?.browser_major_version || "",
|
|
5354
|
-
device: browserProfileCore?.device || ""
|
|
5355
|
-
}) || extractProxySeedSource(proxyConfiguration)
|
|
5356
|
-
).trim();
|
|
5357
|
-
return {
|
|
5358
|
-
locale,
|
|
5359
|
-
timezone,
|
|
5360
|
-
fingerprintSeed: hasExplicitFingerprint ? "" : hashStableSeed(fingerprintSeedSource),
|
|
5361
|
-
hasExplicitFingerprint
|
|
5362
|
-
};
|
|
5363
|
-
};
|
|
5364
5341
|
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5365
5342
|
const config = normalizeObject2(proxyConfiguration);
|
|
5366
5343
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
@@ -5496,7 +5473,6 @@ var CloakLaunch = {
|
|
|
5496
5473
|
runInHeadfulMode = false,
|
|
5497
5474
|
isRunningOnApify = false,
|
|
5498
5475
|
launcher = null,
|
|
5499
|
-
runtimeState = null,
|
|
5500
5476
|
cloakOptions = {},
|
|
5501
5477
|
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5502
5478
|
crawlerBaseOptions = {},
|
|
@@ -5511,7 +5487,6 @@ var CloakLaunch = {
|
|
|
5511
5487
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5512
5488
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5513
5489
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5514
|
-
const runtimeHints = resolveCloakRuntimeHints(runtimeState, proxyConfiguration, normalizedCloakOptions);
|
|
5515
5490
|
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5516
5491
|
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5517
5492
|
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
@@ -5521,13 +5496,7 @@ var CloakLaunch = {
|
|
|
5521
5496
|
...normalizedCloakOptions,
|
|
5522
5497
|
headless,
|
|
5523
5498
|
proxy,
|
|
5524
|
-
|
|
5525
|
-
...runtimeHints.timezone ? { timezone: runtimeHints.timezone } : {},
|
|
5526
|
-
args: [
|
|
5527
|
-
...defaultArgs,
|
|
5528
|
-
...extraArgs,
|
|
5529
|
-
...runtimeHints.fingerprintSeed ? [`--fingerprint=${runtimeHints.fingerprintSeed}`] : []
|
|
5530
|
-
]
|
|
5499
|
+
args: [...defaultArgs, ...extraArgs]
|
|
5531
5500
|
};
|
|
5532
5501
|
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5533
5502
|
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
@@ -6354,7 +6323,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6354
6323
|
let isStopped = false;
|
|
6355
6324
|
let isHandling = false;
|
|
6356
6325
|
let frameHandler = null;
|
|
6357
|
-
let
|
|
6326
|
+
let exposedFunctionName = null;
|
|
6358
6327
|
const triggerDetected = async () => {
|
|
6359
6328
|
if (isStopped || isHandling) return;
|
|
6360
6329
|
isHandling = true;
|
|
@@ -6366,16 +6335,12 @@ function useCaptchaMonitor(page, options) {
|
|
|
6366
6335
|
};
|
|
6367
6336
|
const cleanupFns = [];
|
|
6368
6337
|
if (domSelector) {
|
|
6369
|
-
|
|
6338
|
+
exposedFunctionName = `__c_d_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
6370
6339
|
const cleanerName = `__c_cleaner_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
6371
|
-
|
|
6340
|
+
page.exposeFunction(exposedFunctionName, triggerDetected).catch(() => {
|
|
6341
|
+
});
|
|
6342
|
+
page.addInitScript(({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
6372
6343
|
(() => {
|
|
6373
|
-
if (typeof window[cleanupName] === "function") {
|
|
6374
|
-
try {
|
|
6375
|
-
window[cleanupName]();
|
|
6376
|
-
} catch {
|
|
6377
|
-
}
|
|
6378
|
-
}
|
|
6379
6344
|
let observer = null;
|
|
6380
6345
|
const checkAndReport = () => {
|
|
6381
6346
|
const element = document.querySelector(selector);
|
|
@@ -6401,7 +6366,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6401
6366
|
}
|
|
6402
6367
|
};
|
|
6403
6368
|
if (document.readyState === "loading") {
|
|
6404
|
-
window.addEventListener("DOMContentLoaded", mountObserver
|
|
6369
|
+
window.addEventListener("DOMContentLoaded", mountObserver);
|
|
6405
6370
|
} else {
|
|
6406
6371
|
mountObserver();
|
|
6407
6372
|
}
|
|
@@ -6412,41 +6377,9 @@ function useCaptchaMonitor(page, options) {
|
|
|
6412
6377
|
}
|
|
6413
6378
|
};
|
|
6414
6379
|
})();
|
|
6415
|
-
};
|
|
6416
|
-
|
|
6417
|
-
selector: domSelector,
|
|
6418
|
-
callbackName: exposedFunctionName,
|
|
6419
|
-
cleanerName
|
|
6420
|
-
};
|
|
6421
|
-
const domMonitorReady = (async () => {
|
|
6422
|
-
await page.exposeFunction(exposedFunctionName, triggerDetected);
|
|
6423
|
-
await page.addInitScript(installDomMonitor, installArgs);
|
|
6424
|
-
await page.evaluate(installDomMonitor, installArgs).catch(() => {
|
|
6425
|
-
});
|
|
6426
|
-
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6427
|
-
})().catch((error) => {
|
|
6428
|
-
if (isStopped) {
|
|
6429
|
-
return;
|
|
6430
|
-
}
|
|
6431
|
-
logger12.warn(`DOM \u76D1\u63A7\u521D\u59CB\u5316\u5931\u8D25 (${domSelector}): ${error?.message || error}`);
|
|
6432
|
-
});
|
|
6433
|
-
domFrameHandler = async (frame) => {
|
|
6434
|
-
if (frame !== page.mainFrame() || isStopped) {
|
|
6435
|
-
return;
|
|
6436
|
-
}
|
|
6437
|
-
await domMonitorReady;
|
|
6438
|
-
if (isStopped) {
|
|
6439
|
-
return;
|
|
6440
|
-
}
|
|
6441
|
-
await page.evaluate(installDomMonitor, installArgs).catch(() => {
|
|
6442
|
-
});
|
|
6443
|
-
};
|
|
6444
|
-
page.on("framenavigated", domFrameHandler);
|
|
6380
|
+
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6381
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6445
6382
|
cleanupFns.push(async () => {
|
|
6446
|
-
if (domFrameHandler) {
|
|
6447
|
-
page.off("framenavigated", domFrameHandler);
|
|
6448
|
-
}
|
|
6449
|
-
await domMonitorReady;
|
|
6450
6383
|
try {
|
|
6451
6384
|
await page.evaluate((name) => {
|
|
6452
6385
|
if (window[name]) {
|
|
@@ -6477,10 +6410,10 @@ function useCaptchaMonitor(page, options) {
|
|
|
6477
6410
|
return {
|
|
6478
6411
|
stop: async () => {
|
|
6479
6412
|
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6480
|
-
isStopped = true;
|
|
6481
6413
|
for (const fn of cleanupFns) {
|
|
6482
6414
|
await fn();
|
|
6483
6415
|
}
|
|
6416
|
+
isStopped = true;
|
|
6484
6417
|
}
|
|
6485
6418
|
};
|
|
6486
6419
|
}
|