@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.js
CHANGED
|
@@ -1059,7 +1059,7 @@ import { serializeError as serializeError2 } from "serialize-error";
|
|
|
1059
1059
|
|
|
1060
1060
|
// src/internals/proxy-meter-runtime.js
|
|
1061
1061
|
import { spawn, spawnSync } from "child_process";
|
|
1062
|
-
import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
1062
|
+
import { createWriteStream, existsSync, mkdirSync, readFileSync, rmSync } from "fs";
|
|
1063
1063
|
import { tmpdir } from "os";
|
|
1064
1064
|
import path from "path";
|
|
1065
1065
|
import { fileURLToPath } from "url";
|
|
@@ -1168,6 +1168,18 @@ var ensureLogPath = () => {
|
|
|
1168
1168
|
const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
|
|
1169
1169
|
return path.join(baseDir, label);
|
|
1170
1170
|
};
|
|
1171
|
+
var ensureStdioLogPath = (logPath) => `${logPath}.stdio.log`;
|
|
1172
|
+
var writeChildOutput = (stream, output, prefix) => {
|
|
1173
|
+
if (!stream || !output) return;
|
|
1174
|
+
output.on("data", (chunk) => {
|
|
1175
|
+
const text = chunk?.toString?.() || String(chunk || "");
|
|
1176
|
+
if (!text) return;
|
|
1177
|
+
for (const line of text.split(/\r?\n/)) {
|
|
1178
|
+
if (!line) continue;
|
|
1179
|
+
stream.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] ${prefix} ${line}\n`);
|
|
1180
|
+
}
|
|
1181
|
+
});
|
|
1182
|
+
};
|
|
1171
1183
|
var readSnapshot = (logPath) => {
|
|
1172
1184
|
if (!logPath || !existsSync(logPath)) return null;
|
|
1173
1185
|
try {
|
|
@@ -1335,6 +1347,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
1335
1347
|
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
1336
1348
|
const port = pickFreePort();
|
|
1337
1349
|
const logPath = ensureLogPath();
|
|
1350
|
+
const stdioLogPath = ensureStdioLogPath(logPath);
|
|
1338
1351
|
const scriptPath = resolveScriptPath();
|
|
1339
1352
|
const debugMode = Boolean(options.debugMode);
|
|
1340
1353
|
const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
|
|
@@ -1347,19 +1360,26 @@ var startProxyMeter = (options = {}) => {
|
|
|
1347
1360
|
PROXY_METER_DEBUG: debugMode ? "1" : "0",
|
|
1348
1361
|
PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
|
|
1349
1362
|
};
|
|
1363
|
+
const stdioLog = createWriteStream(stdioLogPath, { flags: "a" });
|
|
1364
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] start script=${scriptPath} port=${port} snapshot=${logPath}\n`);
|
|
1350
1365
|
const child = spawn(process.execPath, [scriptPath], {
|
|
1351
1366
|
env,
|
|
1352
|
-
stdio: ["ignore", "
|
|
1367
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
1353
1368
|
});
|
|
1354
|
-
child.
|
|
1369
|
+
writeChildOutput(stdioLog, child.stdout, "stdout");
|
|
1370
|
+
writeChildOutput(stdioLog, child.stderr, "stderr");
|
|
1371
|
+
child.once("exit", (code, signal) => {
|
|
1372
|
+
stdioLog.write(`[${(/* @__PURE__ */ new Date()).toISOString()}] [proxy-meter-runtime] exit code=${code ?? ""} signal=${signal ?? ""}\n`);
|
|
1373
|
+
stdioLog.end();
|
|
1355
1374
|
if (code && code !== 0) {
|
|
1356
|
-
logger2.warn(`[proxy-meter] exited with code ${code}`);
|
|
1375
|
+
logger2.warn(`[proxy-meter] exited with code ${code}; stdio=${stdioLogPath}`);
|
|
1357
1376
|
}
|
|
1358
1377
|
});
|
|
1359
1378
|
runtime = {
|
|
1360
1379
|
proc: child,
|
|
1361
1380
|
port,
|
|
1362
1381
|
logPath,
|
|
1382
|
+
stdioLogPath,
|
|
1363
1383
|
startedAt: Date.now()
|
|
1364
1384
|
};
|
|
1365
1385
|
registerCleanup();
|
|
@@ -5290,49 +5310,6 @@ var normalizeStringArray = (value) => {
|
|
|
5290
5310
|
}
|
|
5291
5311
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5292
5312
|
};
|
|
5293
|
-
var hashStableSeed = (value = "") => {
|
|
5294
|
-
const raw = String(value || "").trim();
|
|
5295
|
-
if (!raw) return "";
|
|
5296
|
-
let hash = 2166136261;
|
|
5297
|
-
for (let index = 0; index < raw.length; index += 1) {
|
|
5298
|
-
hash ^= raw.charCodeAt(index);
|
|
5299
|
-
hash = Math.imul(hash, 16777619);
|
|
5300
|
-
}
|
|
5301
|
-
const normalized = hash >>> 0 || 1;
|
|
5302
|
-
return String(normalized);
|
|
5303
|
-
};
|
|
5304
|
-
var extractProxySeedSource = (proxyConfiguration = {}) => {
|
|
5305
|
-
const config = normalizeObject2(proxyConfiguration);
|
|
5306
|
-
return String(config.proxy_url || "").trim();
|
|
5307
|
-
};
|
|
5308
|
-
var resolveCloakRuntimeHints = (runtimeState = {}, proxyConfiguration = {}, cloakOptions = {}) => {
|
|
5309
|
-
const normalizedCloakOptions = normalizeObject2(cloakOptions);
|
|
5310
|
-
const browserProfileCore = RuntimeEnv.getBrowserProfileCore(runtimeState);
|
|
5311
|
-
const baseConfig = DefaultAntiCheat.getBaseConfig();
|
|
5312
|
-
const locale = String(
|
|
5313
|
-
normalizedCloakOptions.locale || browserProfileCore?.locale || baseConfig.locale || ""
|
|
5314
|
-
).trim();
|
|
5315
|
-
const timezone = String(
|
|
5316
|
-
normalizedCloakOptions.timezone || normalizedCloakOptions.timezoneId || browserProfileCore?.timezone_id || baseConfig.timezoneId || ""
|
|
5317
|
-
).trim();
|
|
5318
|
-
const explicitArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5319
|
-
const hasExplicitFingerprint = explicitArgs.some((arg) => arg.startsWith("--fingerprint="));
|
|
5320
|
-
const fingerprintSeedSource = String(
|
|
5321
|
-
runtimeState?.envId || browserProfileCore?.schema_version && JSON.stringify({
|
|
5322
|
-
envId: runtimeState?.envId || "",
|
|
5323
|
-
timezone: browserProfileCore?.timezone_id || "",
|
|
5324
|
-
locale: browserProfileCore?.locale || "",
|
|
5325
|
-
browserMajorVersion: browserProfileCore?.browser_major_version || "",
|
|
5326
|
-
device: browserProfileCore?.device || ""
|
|
5327
|
-
}) || extractProxySeedSource(proxyConfiguration)
|
|
5328
|
-
).trim();
|
|
5329
|
-
return {
|
|
5330
|
-
locale,
|
|
5331
|
-
timezone,
|
|
5332
|
-
fingerprintSeed: hasExplicitFingerprint ? "" : hashStableSeed(fingerprintSeedSource),
|
|
5333
|
-
hasExplicitFingerprint
|
|
5334
|
-
};
|
|
5335
|
-
};
|
|
5336
5313
|
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5337
5314
|
const config = normalizeObject2(proxyConfiguration);
|
|
5338
5315
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
@@ -5468,7 +5445,6 @@ var CloakLaunch = {
|
|
|
5468
5445
|
runInHeadfulMode = false,
|
|
5469
5446
|
isRunningOnApify = false,
|
|
5470
5447
|
launcher = null,
|
|
5471
|
-
runtimeState = null,
|
|
5472
5448
|
cloakOptions = {},
|
|
5473
5449
|
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5474
5450
|
crawlerBaseOptions = {},
|
|
@@ -5483,7 +5459,6 @@ var CloakLaunch = {
|
|
|
5483
5459
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5484
5460
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5485
5461
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5486
|
-
const runtimeHints = resolveCloakRuntimeHints(runtimeState, proxyConfiguration, normalizedCloakOptions);
|
|
5487
5462
|
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5488
5463
|
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5489
5464
|
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
@@ -5493,13 +5468,7 @@ var CloakLaunch = {
|
|
|
5493
5468
|
...normalizedCloakOptions,
|
|
5494
5469
|
headless,
|
|
5495
5470
|
proxy,
|
|
5496
|
-
|
|
5497
|
-
...runtimeHints.timezone ? { timezone: runtimeHints.timezone } : {},
|
|
5498
|
-
args: [
|
|
5499
|
-
...defaultArgs,
|
|
5500
|
-
...extraArgs,
|
|
5501
|
-
...runtimeHints.fingerprintSeed ? [`--fingerprint=${runtimeHints.fingerprintSeed}`] : []
|
|
5502
|
-
]
|
|
5471
|
+
args: [...defaultArgs, ...extraArgs]
|
|
5503
5472
|
};
|
|
5504
5473
|
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5505
5474
|
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
@@ -6326,7 +6295,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6326
6295
|
let isStopped = false;
|
|
6327
6296
|
let isHandling = false;
|
|
6328
6297
|
let frameHandler = null;
|
|
6329
|
-
let
|
|
6298
|
+
let exposedFunctionName = null;
|
|
6330
6299
|
const triggerDetected = async () => {
|
|
6331
6300
|
if (isStopped || isHandling) return;
|
|
6332
6301
|
isHandling = true;
|
|
@@ -6338,16 +6307,12 @@ function useCaptchaMonitor(page, options) {
|
|
|
6338
6307
|
};
|
|
6339
6308
|
const cleanupFns = [];
|
|
6340
6309
|
if (domSelector) {
|
|
6341
|
-
|
|
6310
|
+
exposedFunctionName = `__c_d_${uuidv4().replace(/-/g, "_")}`;
|
|
6342
6311
|
const cleanerName = `__c_cleaner_${uuidv4().replace(/-/g, "_")}`;
|
|
6343
|
-
|
|
6312
|
+
page.exposeFunction(exposedFunctionName, triggerDetected).catch(() => {
|
|
6313
|
+
});
|
|
6314
|
+
page.addInitScript(({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
6344
6315
|
(() => {
|
|
6345
|
-
if (typeof window[cleanupName] === "function") {
|
|
6346
|
-
try {
|
|
6347
|
-
window[cleanupName]();
|
|
6348
|
-
} catch {
|
|
6349
|
-
}
|
|
6350
|
-
}
|
|
6351
6316
|
let observer = null;
|
|
6352
6317
|
const checkAndReport = () => {
|
|
6353
6318
|
const element = document.querySelector(selector);
|
|
@@ -6373,7 +6338,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6373
6338
|
}
|
|
6374
6339
|
};
|
|
6375
6340
|
if (document.readyState === "loading") {
|
|
6376
|
-
window.addEventListener("DOMContentLoaded", mountObserver
|
|
6341
|
+
window.addEventListener("DOMContentLoaded", mountObserver);
|
|
6377
6342
|
} else {
|
|
6378
6343
|
mountObserver();
|
|
6379
6344
|
}
|
|
@@ -6384,41 +6349,9 @@ function useCaptchaMonitor(page, options) {
|
|
|
6384
6349
|
}
|
|
6385
6350
|
};
|
|
6386
6351
|
})();
|
|
6387
|
-
};
|
|
6388
|
-
|
|
6389
|
-
selector: domSelector,
|
|
6390
|
-
callbackName: exposedFunctionName,
|
|
6391
|
-
cleanerName
|
|
6392
|
-
};
|
|
6393
|
-
const domMonitorReady = (async () => {
|
|
6394
|
-
await page.exposeFunction(exposedFunctionName, triggerDetected);
|
|
6395
|
-
await page.addInitScript(installDomMonitor, installArgs);
|
|
6396
|
-
await page.evaluate(installDomMonitor, installArgs).catch(() => {
|
|
6397
|
-
});
|
|
6398
|
-
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6399
|
-
})().catch((error) => {
|
|
6400
|
-
if (isStopped) {
|
|
6401
|
-
return;
|
|
6402
|
-
}
|
|
6403
|
-
logger12.warn(`DOM \u76D1\u63A7\u521D\u59CB\u5316\u5931\u8D25 (${domSelector}): ${error?.message || error}`);
|
|
6404
|
-
});
|
|
6405
|
-
domFrameHandler = async (frame) => {
|
|
6406
|
-
if (frame !== page.mainFrame() || isStopped) {
|
|
6407
|
-
return;
|
|
6408
|
-
}
|
|
6409
|
-
await domMonitorReady;
|
|
6410
|
-
if (isStopped) {
|
|
6411
|
-
return;
|
|
6412
|
-
}
|
|
6413
|
-
await page.evaluate(installDomMonitor, installArgs).catch(() => {
|
|
6414
|
-
});
|
|
6415
|
-
};
|
|
6416
|
-
page.on("framenavigated", domFrameHandler);
|
|
6352
|
+
}, { selector: domSelector, callbackName: exposedFunctionName, cleanerName });
|
|
6353
|
+
logger12.success("useCaptchaMonitor", `DOM \u76D1\u63A7\u5DF2\u542F\u7528\uFF1A${domSelector}`);
|
|
6417
6354
|
cleanupFns.push(async () => {
|
|
6418
|
-
if (domFrameHandler) {
|
|
6419
|
-
page.off("framenavigated", domFrameHandler);
|
|
6420
|
-
}
|
|
6421
|
-
await domMonitorReady;
|
|
6422
6355
|
try {
|
|
6423
6356
|
await page.evaluate((name) => {
|
|
6424
6357
|
if (window[name]) {
|
|
@@ -6449,10 +6382,10 @@ function useCaptchaMonitor(page, options) {
|
|
|
6449
6382
|
return {
|
|
6450
6383
|
stop: async () => {
|
|
6451
6384
|
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6452
|
-
isStopped = true;
|
|
6453
6385
|
for (const fn of cleanupFns) {
|
|
6454
6386
|
await fn();
|
|
6455
6387
|
}
|
|
6388
|
+
isStopped = true;
|
|
6456
6389
|
}
|
|
6457
6390
|
};
|
|
6458
6391
|
}
|