@skrillex1224/playwright-toolkit 3.0.5 → 3.0.7
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 +97 -10
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +97 -10
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5318,6 +5318,49 @@ var normalizeStringArray = (value) => {
|
|
|
5318
5318
|
}
|
|
5319
5319
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5320
5320
|
};
|
|
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
|
+
};
|
|
5321
5364
|
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5322
5365
|
const config = normalizeObject2(proxyConfiguration);
|
|
5323
5366
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
@@ -5453,6 +5496,7 @@ var CloakLaunch = {
|
|
|
5453
5496
|
runInHeadfulMode = false,
|
|
5454
5497
|
isRunningOnApify = false,
|
|
5455
5498
|
launcher = null,
|
|
5499
|
+
runtimeState = null,
|
|
5456
5500
|
cloakOptions = {},
|
|
5457
5501
|
humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
|
|
5458
5502
|
crawlerBaseOptions = {},
|
|
@@ -5467,6 +5511,7 @@ var CloakLaunch = {
|
|
|
5467
5511
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5468
5512
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5469
5513
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5514
|
+
const runtimeHints = resolveCloakRuntimeHints(runtimeState, proxyConfiguration, normalizedCloakOptions);
|
|
5470
5515
|
const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
|
|
5471
5516
|
const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5472
5517
|
const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
|
|
@@ -5476,7 +5521,13 @@ var CloakLaunch = {
|
|
|
5476
5521
|
...normalizedCloakOptions,
|
|
5477
5522
|
headless,
|
|
5478
5523
|
proxy,
|
|
5479
|
-
|
|
5524
|
+
...runtimeHints.locale ? { locale: runtimeHints.locale } : {},
|
|
5525
|
+
...runtimeHints.timezone ? { timezone: runtimeHints.timezone } : {},
|
|
5526
|
+
args: [
|
|
5527
|
+
...defaultArgs,
|
|
5528
|
+
...extraArgs,
|
|
5529
|
+
...runtimeHints.fingerprintSeed ? [`--fingerprint=${runtimeHints.fingerprintSeed}`] : []
|
|
5530
|
+
]
|
|
5480
5531
|
};
|
|
5481
5532
|
const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
|
|
5482
5533
|
const fingerprintArg = extractFingerprintArg(launchOptions);
|
|
@@ -6303,7 +6354,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6303
6354
|
let isStopped = false;
|
|
6304
6355
|
let isHandling = false;
|
|
6305
6356
|
let frameHandler = null;
|
|
6306
|
-
let
|
|
6357
|
+
let domFrameHandler = null;
|
|
6307
6358
|
const triggerDetected = async () => {
|
|
6308
6359
|
if (isStopped || isHandling) return;
|
|
6309
6360
|
isHandling = true;
|
|
@@ -6315,12 +6366,16 @@ function useCaptchaMonitor(page, options) {
|
|
|
6315
6366
|
};
|
|
6316
6367
|
const cleanupFns = [];
|
|
6317
6368
|
if (domSelector) {
|
|
6318
|
-
exposedFunctionName = `__c_d_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
6369
|
+
const exposedFunctionName = `__c_d_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
6319
6370
|
const cleanerName = `__c_cleaner_${(0, import_uuid.v4)().replace(/-/g, "_")}`;
|
|
6320
|
-
|
|
6321
|
-
});
|
|
6322
|
-
page.addInitScript(({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
6371
|
+
const installDomMonitor = ({ selector, callbackName, cleanerName: cleanupName }) => {
|
|
6323
6372
|
(() => {
|
|
6373
|
+
if (typeof window[cleanupName] === "function") {
|
|
6374
|
+
try {
|
|
6375
|
+
window[cleanupName]();
|
|
6376
|
+
} catch {
|
|
6377
|
+
}
|
|
6378
|
+
}
|
|
6324
6379
|
let observer = null;
|
|
6325
6380
|
const checkAndReport = () => {
|
|
6326
6381
|
const element = document.querySelector(selector);
|
|
@@ -6346,7 +6401,7 @@ function useCaptchaMonitor(page, options) {
|
|
|
6346
6401
|
}
|
|
6347
6402
|
};
|
|
6348
6403
|
if (document.readyState === "loading") {
|
|
6349
|
-
window.addEventListener("DOMContentLoaded", mountObserver);
|
|
6404
|
+
window.addEventListener("DOMContentLoaded", mountObserver, { once: true });
|
|
6350
6405
|
} else {
|
|
6351
6406
|
mountObserver();
|
|
6352
6407
|
}
|
|
@@ -6357,9 +6412,41 @@ function useCaptchaMonitor(page, options) {
|
|
|
6357
6412
|
}
|
|
6358
6413
|
};
|
|
6359
6414
|
})();
|
|
6360
|
-
}
|
|
6361
|
-
|
|
6415
|
+
};
|
|
6416
|
+
const installArgs = {
|
|
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);
|
|
6362
6445
|
cleanupFns.push(async () => {
|
|
6446
|
+
if (domFrameHandler) {
|
|
6447
|
+
page.off("framenavigated", domFrameHandler);
|
|
6448
|
+
}
|
|
6449
|
+
await domMonitorReady;
|
|
6363
6450
|
try {
|
|
6364
6451
|
await page.evaluate((name) => {
|
|
6365
6452
|
if (window[name]) {
|
|
@@ -6390,10 +6477,10 @@ function useCaptchaMonitor(page, options) {
|
|
|
6390
6477
|
return {
|
|
6391
6478
|
stop: async () => {
|
|
6392
6479
|
logger12.info("\u6B63\u5728\u505C\u6B62\u9A8C\u8BC1\u7801\u76D1\u63A7...");
|
|
6480
|
+
isStopped = true;
|
|
6393
6481
|
for (const fn of cleanupFns) {
|
|
6394
6482
|
await fn();
|
|
6395
6483
|
}
|
|
6396
|
-
isStopped = true;
|
|
6397
6484
|
}
|
|
6398
6485
|
};
|
|
6399
6486
|
}
|