@skrillex1224/playwright-toolkit 3.0.16 → 3.0.18

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 CHANGED
@@ -1478,6 +1478,7 @@ var ProxyMeterRuntime = {
1478
1478
 
1479
1479
  // src/runtime-env.js
1480
1480
  var BROWSER_PROFILE_SCHEMA_VERSION = 1;
1481
+ var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
1481
1482
  var rememberedRuntimeState = null;
1482
1483
  var isPlainObject = (value) => value && typeof value === "object" && !Array.isArray(value);
1483
1484
  var normalizeKnownDevice = (value) => {
@@ -1486,6 +1487,22 @@ var normalizeKnownDevice = (value) => {
1486
1487
  if (raw === Device.Desktop) return Device.Desktop;
1487
1488
  return "";
1488
1489
  };
1490
+ var normalizeCloakSeed = (value) => {
1491
+ const numericSeed = Number(value);
1492
+ if (Number.isSafeInteger(numericSeed) && numericSeed > 0) {
1493
+ return numericSeed;
1494
+ }
1495
+ const raw = String(value || "").trim();
1496
+ if (!/^\d+$/.test(raw)) {
1497
+ return 0;
1498
+ }
1499
+ const parsedSeed = Number(raw);
1500
+ return Number.isSafeInteger(parsedSeed) && parsedSeed > 0 ? parsedSeed : 0;
1501
+ };
1502
+ var normalizeCloakFingerprintPlatform = (value) => {
1503
+ const raw = String(value || "").trim().toLowerCase();
1504
+ return SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS.has(raw) ? raw : "";
1505
+ };
1489
1506
  var deepClone = (value) => {
1490
1507
  if (value == null) return value;
1491
1508
  try {
@@ -1856,6 +1873,14 @@ var normalizeBrowserProfileCore = (value) => {
1856
1873
  if (Number.isFinite(browserMajorVersion) && browserMajorVersion > 0) {
1857
1874
  profile.browser_major_version = browserMajorVersion;
1858
1875
  }
1876
+ const cloakSeed = normalizeCloakSeed(source.cloak_seed);
1877
+ if (cloakSeed > 0) {
1878
+ profile.cloak_seed = cloakSeed;
1879
+ }
1880
+ const cloakFingerprintPlatform = normalizeCloakFingerprintPlatform(source.cloak_fingerprint_platform);
1881
+ if (cloakFingerprintPlatform) {
1882
+ profile.cloak_fingerprint_platform = cloakFingerprintPlatform;
1883
+ }
1859
1884
  const schemaVersion = Number(source.schema_version || 0);
1860
1885
  if (Number.isFinite(schemaVersion) && schemaVersion > 0) {
1861
1886
  profile.schema_version = schemaVersion;
@@ -5109,6 +5134,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
5109
5134
  const fingerprint = generated.fingerprint;
5110
5135
  const fingerprintBrowserMajorVersion = parseChromeMajorVersion(fingerprint?.fingerprint?.navigator?.userAgent || "");
5111
5136
  browserProfileCore = {
5137
+ ...browserProfileCore,
5112
5138
  fingerprint,
5113
5139
  device,
5114
5140
  timezone_id: timezoneId,
@@ -5302,6 +5328,7 @@ var DefaultLaunch = {
5302
5328
 
5303
5329
  // src/internals/launch/cloak.js
5304
5330
  var import_node_child_process2 = require("node:child_process");
5331
+ var import_node_crypto = require("node:crypto");
5305
5332
  var import_node_util = require("node:util");
5306
5333
  var logger9 = createInternalLogger("Launch");
5307
5334
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
@@ -5317,9 +5344,15 @@ var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
5317
5344
  var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
5318
5345
  waitUntil: "commit"
5319
5346
  });
5347
+ var DEFAULT_CLOAK_SEED_MIN = 1e4;
5348
+ var DEFAULT_CLOAK_SEED_MAX = 99999;
5320
5349
  var DEFAULT_CLOAK_FINGERPRINT_PLATFORM = "linux";
5350
+ var CLOAK_FINGERPRINT_ARG_PREFIX = "--fingerprint=";
5321
5351
  var CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX = "--fingerprint-platform=";
5322
- var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
5352
+ var CLOAK_FINGERPRINT_TIMEZONE_ARG_PREFIX = "--fingerprint-timezone=";
5353
+ var CLOAK_FINGERPRINT_LOCALE_ARG_PREFIX = "--fingerprint-locale=";
5354
+ var CLOAK_LANG_ARG_PREFIX = "--lang=";
5355
+ var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS2 = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
5323
5356
  var cachedCloakModulePromise = null;
5324
5357
  var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
5325
5358
  var loadCloakModule = async () => {
@@ -5349,16 +5382,36 @@ var normalizeStringArray = (value) => {
5349
5382
  }
5350
5383
  return value.map((item) => String(item || "").trim()).filter(Boolean);
5351
5384
  };
5385
+ var normalizeText = (value) => String(value || "").trim();
5386
+ var normalizePositiveInteger = (value) => {
5387
+ const numericValue = Number(value);
5388
+ if (Number.isSafeInteger(numericValue) && numericValue > 0) {
5389
+ return numericValue;
5390
+ }
5391
+ const raw = normalizeText(value);
5392
+ if (!/^\d+$/.test(raw)) {
5393
+ return 0;
5394
+ }
5395
+ const parsedValue = Number(raw);
5396
+ return Number.isSafeInteger(parsedValue) && parsedValue > 0 ? parsedValue : 0;
5397
+ };
5398
+ var normalizeCloakFingerprintPlatform2 = (value) => {
5399
+ const normalizedFingerprintPlatform = String(value || "").trim().toLowerCase();
5400
+ return SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS2.has(normalizedFingerprintPlatform) ? normalizedFingerprintPlatform : "";
5401
+ };
5402
+ var buildCloakFingerprintPlatformArg = (fingerprintPlatform = DEFAULT_CLOAK_FINGERPRINT_PLATFORM) => `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${fingerprintPlatform}`;
5352
5403
  var resolveCloakFingerprintPlatformArg = (fingerprintPlatform = "", args = []) => {
5353
- const normalizedFingerprintPlatform = String(fingerprintPlatform || "").trim().toLowerCase();
5354
- if (SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS.has(normalizedFingerprintPlatform)) {
5355
- return `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${normalizedFingerprintPlatform}`;
5404
+ const normalizedFingerprintPlatform = normalizeCloakFingerprintPlatform2(fingerprintPlatform);
5405
+ if (normalizedFingerprintPlatform) {
5406
+ return buildCloakFingerprintPlatformArg(normalizedFingerprintPlatform);
5356
5407
  }
5357
- const existingArg = normalizeStringArray(args).find((value) => value.startsWith(CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX));
5358
- if (existingArg) {
5359
- return existingArg;
5408
+ const existingFingerprintPlatform = normalizeCloakFingerprintPlatform2(
5409
+ extractArgValue(args, CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX)
5410
+ );
5411
+ if (existingFingerprintPlatform) {
5412
+ return buildCloakFingerprintPlatformArg(existingFingerprintPlatform);
5360
5413
  }
5361
- return `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${DEFAULT_CLOAK_FINGERPRINT_PLATFORM}`;
5414
+ return buildCloakFingerprintPlatformArg(DEFAULT_CLOAK_FINGERPRINT_PLATFORM);
5362
5415
  };
5363
5416
  var resolveCloakProxy = (proxyConfiguration = {}) => {
5364
5417
  const config = normalizeObject2(proxyConfiguration);
@@ -5381,7 +5434,124 @@ var resolveCloakProxy = (proxyConfiguration = {}) => {
5381
5434
  };
5382
5435
  var extractFingerprintArg = (launchOptions = {}) => {
5383
5436
  const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
5384
- return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
5437
+ return args.find((value) => String(value || "").startsWith(CLOAK_FINGERPRINT_ARG_PREFIX)) || "";
5438
+ };
5439
+ var buildFingerprintArg = (seed) => `${CLOAK_FINGERPRINT_ARG_PREFIX}${seed}`;
5440
+ var extractArgValue = (args = [], prefix = "") => {
5441
+ const matchedArg = normalizeStringArray(args).find((value) => value.startsWith(prefix));
5442
+ if (!matchedArg) {
5443
+ return "";
5444
+ }
5445
+ return normalizeText(matchedArg.slice(prefix.length));
5446
+ };
5447
+ var extractFingerprintSeedFromArgs = (args = []) => normalizePositiveInteger(
5448
+ extractArgValue(args, CLOAK_FINGERPRINT_ARG_PREFIX)
5449
+ );
5450
+ var extractLocaleFromArgs = (args = []) => extractArgValue(args, CLOAK_LANG_ARG_PREFIX) || extractArgValue(args, CLOAK_FINGERPRINT_LOCALE_ARG_PREFIX);
5451
+ var extractTimezoneFromArgs = (args = []) => extractArgValue(args, CLOAK_FINGERPRINT_TIMEZONE_ARG_PREFIX);
5452
+ var hashStringToSeed = (value = "") => {
5453
+ let hash = 2166136261;
5454
+ const text = normalizeText(value);
5455
+ for (let index = 0; index < text.length; index += 1) {
5456
+ hash ^= text.charCodeAt(index);
5457
+ hash = Math.imul(hash, 16777619);
5458
+ }
5459
+ const numericHash = hash >>> 0;
5460
+ const seedRange = DEFAULT_CLOAK_SEED_MAX - DEFAULT_CLOAK_SEED_MIN + 1;
5461
+ return DEFAULT_CLOAK_SEED_MIN + numericHash % seedRange;
5462
+ };
5463
+ var buildCloakSeedIdentity = (runtimeState = {}) => {
5464
+ const normalizedRuntimeState = normalizeObject2(runtimeState);
5465
+ const normalizedEnvId = normalizeText(normalizedRuntimeState.envId);
5466
+ if (normalizedEnvId) {
5467
+ return `env:${normalizedEnvId}`;
5468
+ }
5469
+ const runtimePayload = normalizeObject2(normalizedRuntimeState.runtime);
5470
+ if (Object.keys(runtimePayload).length === 0) {
5471
+ return "";
5472
+ }
5473
+ return JSON.stringify({
5474
+ actor: normalizeText(normalizedRuntimeState.actor),
5475
+ device: normalizeText(normalizedRuntimeState.device),
5476
+ runtime: runtimePayload
5477
+ });
5478
+ };
5479
+ var generateCloakSeed = (runtimeState = {}) => {
5480
+ const identity = buildCloakSeedIdentity(runtimeState);
5481
+ if (identity) {
5482
+ return hashStringToSeed(`cloak:${identity}`);
5483
+ }
5484
+ return (0, import_node_crypto.randomInt)(DEFAULT_CLOAK_SEED_MIN, DEFAULT_CLOAK_SEED_MAX + 1);
5485
+ };
5486
+ var resolveReplayableCloakProfile = (runtimeState, { fingerprintPlatform = "", cloakOptions = {} } = {}) => {
5487
+ const normalizedCloakOptions = normalizeObject2(cloakOptions);
5488
+ const normalizedArgs = normalizeStringArray(normalizedCloakOptions.args);
5489
+ const explicitFingerprintSeed = extractFingerprintSeedFromArgs(normalizedArgs);
5490
+ const explicitFingerprintPlatform = normalizeCloakFingerprintPlatform2(fingerprintPlatform) || normalizeCloakFingerprintPlatform2(
5491
+ extractArgValue(normalizedArgs, CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX)
5492
+ );
5493
+ const explicitTimezone = normalizeText(
5494
+ normalizedCloakOptions.timezone || normalizedCloakOptions.timezoneId || extractTimezoneFromArgs(normalizedArgs)
5495
+ );
5496
+ const explicitLocale = normalizeText(
5497
+ normalizedCloakOptions.locale || extractLocaleFromArgs(normalizedArgs)
5498
+ );
5499
+ if (!runtimeState || !RuntimeEnv.hasLoginState(runtimeState)) {
5500
+ return {
5501
+ runtimeState,
5502
+ browserProfileCore: null,
5503
+ fingerprintSeed: explicitFingerprintSeed,
5504
+ fingerprintPlatform: explicitFingerprintPlatform,
5505
+ locale: explicitLocale,
5506
+ timezone: explicitTimezone,
5507
+ hasExplicitFingerprintSeed: explicitFingerprintSeed > 0,
5508
+ hasExplicitLocale: Boolean(explicitLocale),
5509
+ hasExplicitTimezone: Boolean(explicitTimezone)
5510
+ };
5511
+ }
5512
+ let nextState = RuntimeEnv.rememberState(runtimeState);
5513
+ const currentBrowserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
5514
+ const storedFingerprintSeed = normalizePositiveInteger(currentBrowserProfileCore?.cloak_seed);
5515
+ const storedFingerprintPlatform = normalizeCloakFingerprintPlatform2(
5516
+ currentBrowserProfileCore?.cloak_fingerprint_platform
5517
+ );
5518
+ const storedLocale = normalizeText(currentBrowserProfileCore?.locale);
5519
+ const storedTimezone = normalizeText(currentBrowserProfileCore?.timezone_id);
5520
+ const fingerprintSeed = explicitFingerprintSeed || storedFingerprintSeed || generateCloakSeed(nextState);
5521
+ const resolvedFingerprintPlatform = explicitFingerprintPlatform || storedFingerprintPlatform || DEFAULT_CLOAK_FINGERPRINT_PLATFORM;
5522
+ const locale = explicitLocale || storedLocale;
5523
+ const timezone = explicitTimezone || storedTimezone;
5524
+ const nextBrowserProfileCore = {
5525
+ ...currentBrowserProfileCore,
5526
+ cloak_seed: fingerprintSeed,
5527
+ cloak_fingerprint_platform: resolvedFingerprintPlatform
5528
+ };
5529
+ if (locale) {
5530
+ nextBrowserProfileCore.locale = locale;
5531
+ }
5532
+ if (timezone) {
5533
+ nextBrowserProfileCore.timezone_id = timezone;
5534
+ }
5535
+ const currentCoreRaw = JSON.stringify(currentBrowserProfileCore || {});
5536
+ const nextCoreRaw = JSON.stringify(nextBrowserProfileCore);
5537
+ if (currentCoreRaw !== nextCoreRaw) {
5538
+ nextState = RuntimeEnv.setBrowserProfileCore(nextState, nextBrowserProfileCore);
5539
+ logger9.info(
5540
+ `\u5DF2\u540C\u6B65 Cloak \u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | seed=${fingerprintSeed} | platform=${resolvedFingerprintPlatform} | timezone=${timezone || "-"} | locale=${locale || "-"}`
5541
+ );
5542
+ }
5543
+ const rememberedBrowserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
5544
+ return {
5545
+ runtimeState: nextState,
5546
+ browserProfileCore: rememberedBrowserProfileCore,
5547
+ fingerprintSeed,
5548
+ fingerprintPlatform: resolvedFingerprintPlatform,
5549
+ locale,
5550
+ timezone,
5551
+ hasExplicitFingerprintSeed: explicitFingerprintSeed > 0,
5552
+ hasExplicitLocale: Boolean(explicitLocale),
5553
+ hasExplicitTimezone: Boolean(explicitTimezone)
5554
+ };
5385
5555
  };
5386
5556
  var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
5387
5557
  const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
@@ -5495,6 +5665,7 @@ var CloakLaunch = {
5495
5665
  runInHeadfulMode = false,
5496
5666
  isRunningOnApify = false,
5497
5667
  launcher = null,
5668
+ runtimeState = null,
5498
5669
  fingerprintPlatform = "",
5499
5670
  cloakOptions = {},
5500
5671
  humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
@@ -5509,8 +5680,16 @@ var CloakLaunch = {
5509
5680
  const activeBrowsers = /* @__PURE__ */ new Set();
5510
5681
  const patchedBrowsers = /* @__PURE__ */ new WeakSet();
5511
5682
  const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
5512
- const fingerprintPlatformArg = resolveCloakFingerprintPlatformArg(fingerprintPlatform, normalizedCloakOptions.args);
5683
+ const replayContext = resolveReplayableCloakProfile(runtimeState, {
5684
+ fingerprintPlatform,
5685
+ cloakOptions: normalizedCloakOptions
5686
+ });
5687
+ const fingerprintPlatformArg = resolveCloakFingerprintPlatformArg(
5688
+ replayContext.fingerprintPlatform,
5689
+ normalizedCloakOptions.args
5690
+ );
5513
5691
  const extraArgs = normalizeStringArray(normalizedCloakOptions.args).filter((value) => !value.startsWith(CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX));
5692
+ const replayFingerprintArg = !replayContext.hasExplicitFingerprintSeed && replayContext.fingerprintSeed > 0 ? buildFingerprintArg(replayContext.fingerprintSeed) : "";
5514
5693
  const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
5515
5694
  const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
5516
5695
  const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
@@ -5520,7 +5699,15 @@ var CloakLaunch = {
5520
5699
  ...normalizedCloakOptions,
5521
5700
  headless,
5522
5701
  proxy,
5523
- args: [...defaultArgs, ...extraArgs, fingerprintPlatformArg]
5702
+ ...normalizedCloakOptions.timezoneId && !hasOwn(normalizedCloakOptions, "timezone") ? { timezone: normalizedCloakOptions.timezoneId } : {},
5703
+ ...replayContext.timezone && !replayContext.hasExplicitTimezone ? { timezone: replayContext.timezone } : {},
5704
+ ...replayContext.locale && !replayContext.hasExplicitLocale ? { locale: replayContext.locale } : {},
5705
+ args: [
5706
+ ...defaultArgs,
5707
+ ...replayFingerprintArg ? [replayFingerprintArg] : [],
5708
+ ...extraArgs,
5709
+ fingerprintPlatformArg
5710
+ ]
5524
5711
  };
5525
5712
  const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
5526
5713
  const fingerprintArg = extractFingerprintArg(launchOptions);
@@ -6341,10 +6528,6 @@ var sleep = (ms) => new Promise((resolve) => {
6341
6528
  });
6342
6529
  var getErrorMessage = (error) => String(error?.message || error || "");
6343
6530
  var isTimeoutError = (error) => error?.name === "TimeoutError" || getErrorMessage(error).includes("Timeout");
6344
- var isPageLifecycleError = (error) => {
6345
- const message = getErrorMessage(error);
6346
- return message.includes("Execution context was destroyed") || message.includes("Frame was detached") || message.includes("Target page, context or browser has been closed") || message.includes("Target closed") || message.includes("Most likely the page has been closed");
6347
- };
6348
6531
  function useCaptchaMonitor(page, options) {
6349
6532
  const { domSelector, urlPattern, onDetected } = options;
6350
6533
  if (!domSelector && !urlPattern) {
@@ -6386,8 +6569,8 @@ function useCaptchaMonitor(page, options) {
6386
6569
  });
6387
6570
  } catch (error) {
6388
6571
  if (isStopped) break;
6389
- if (page?.isClosed?.() && isPageLifecycleError(error)) break;
6390
- if (isTimeoutError(error) || isPageLifecycleError(error)) {
6572
+ if (page?.isClosed?.()) break;
6573
+ if (isTimeoutError(error)) {
6391
6574
  await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
6392
6575
  continue;
6393
6576
  }
@@ -6477,7 +6660,7 @@ var Captcha = {
6477
6660
  };
6478
6661
 
6479
6662
  // src/mutation.js
6480
- var import_node_crypto = require("node:crypto");
6663
+ var import_node_crypto2 = require("node:crypto");
6481
6664
  var import_uuid = require("uuid");
6482
6665
  var logger13 = createInternalLogger("Mutation");
6483
6666
  var MUTATION_MONITOR_MODE = Object.freeze({
@@ -6684,9 +6867,9 @@ var Mutation = {
6684
6867
  if (text.length <= max) return text;
6685
6868
  return `${text.slice(0, max)}...`;
6686
6869
  };
6687
- const normalizeText2 = (value) => String(value || "").replace(/\s+/g, " ").trim();
6870
+ const normalizeText3 = (value) => String(value || "").replace(/\s+/g, " ").trim();
6688
6871
  const normalizeHtml = (value) => String(value || "").trim();
6689
- const hashSnapshot = (value) => (0, import_node_crypto.createHash)("sha256").update(String(value || "")).digest("hex");
6872
+ const hashSnapshot = (value) => (0, import_node_crypto2.createHash)("sha256").update(String(value || "")).digest("hex");
6690
6873
  const buildState = async () => {
6691
6874
  const items = [];
6692
6875
  const describeElement = async (elementHandle) => {
@@ -6749,7 +6932,7 @@ var Mutation = {
6749
6932
  if (frame) {
6750
6933
  try {
6751
6934
  const frameSnapshot = await readFrameSnapshot(frame);
6752
- text = normalizeText2(frameSnapshot?.text || "");
6935
+ text = normalizeText3(frameSnapshot?.text || "");
6753
6936
  html = normalizeHtml(frameSnapshot?.html || "");
6754
6937
  frameUrl = String(frameSnapshot?.url || "").trim();
6755
6938
  readyState = String(frameSnapshot?.readyState || "").trim();
@@ -6763,7 +6946,7 @@ var Mutation = {
6763
6946
  } else {
6764
6947
  try {
6765
6948
  const elementSnapshot = await readElementSnapshot(handle);
6766
- text = normalizeText2(elementSnapshot?.text || "");
6949
+ text = normalizeText3(elementSnapshot?.text || "");
6767
6950
  html = normalizeHtml(elementSnapshot?.html || "");
6768
6951
  } catch (error) {
6769
6952
  source = "main-unreadable";
@@ -8025,9 +8208,9 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
8025
8208
  var cachedStripLogoSrcPromise = null;
8026
8209
  var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
8027
8210
  var logger14 = createInternalLogger("Watermarkify");
8028
- var normalizeText = (value) => String(value || "").trim();
8211
+ var normalizeText2 = (value) => String(value || "").trim();
8029
8212
  var toInline = (value, maxLen = 200) => {
8030
- const text = normalizeText(value);
8213
+ const text = normalizeText2(value);
8031
8214
  if (!text) return "";
8032
8215
  return text.replace(/\s+/g, " ").trim().slice(0, maxLen);
8033
8216
  };
@@ -8087,7 +8270,7 @@ var pickHeaderValue = async (response, names = []) => {
8087
8270
  if (!response || typeof response.headerValue !== "function") return "";
8088
8271
  for (const name of names) {
8089
8272
  const value = await response.headerValue(name).catch(() => null);
8090
- const text = normalizeText(value);
8273
+ const text = normalizeText2(value);
8091
8274
  if (text) return text;
8092
8275
  }
8093
8276
  return "";
@@ -8191,7 +8374,7 @@ var fetchAsDataUrl = async (url, timeoutMs = DEFAULT_LOGO_FETCH_TIMEOUT_MS) => {
8191
8374
  if (!response?.ok) {
8192
8375
  return "";
8193
8376
  }
8194
- const contentType = normalizeText(response.headers?.get?.("content-type")) || "image/png";
8377
+ const contentType = normalizeText2(response.headers?.get?.("content-type")) || "image/png";
8195
8378
  if (!/^image\//i.test(contentType)) {
8196
8379
  return "";
8197
8380
  }
@@ -8214,7 +8397,7 @@ var resolveStripLogoSrc = async () => {
8214
8397
  })();
8215
8398
  }
8216
8399
  const resolved = await cachedStripLogoSrcPromise.catch(() => DEFAULT_STRIP_LOGO_URL);
8217
- return normalizeText(resolved) || DEFAULT_STRIP_LOGO_URL;
8400
+ return normalizeText2(resolved) || DEFAULT_STRIP_LOGO_URL;
8218
8401
  };
8219
8402
  var normalizeLayer = (value, defaults) => {
8220
8403
  if (value === false) {
@@ -8564,7 +8747,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
8564
8747
  return null;
8565
8748
  });
8566
8749
  const status = response && typeof response.status === "function" ? response.status() : 0;
8567
- const contentType = normalizeText(await pickHeaderValue(response, ["content-type"]));
8750
+ const contentType = normalizeText2(await pickHeaderValue(response, ["content-type"]));
8568
8751
  let rawText = "";
8569
8752
  if (response && typeof response.text === "function") {
8570
8753
  rawText = String(await withTimeout2(
@@ -8703,8 +8886,8 @@ var estimateTextWidth = (value, fontSize = 16) => {
8703
8886
  return Math.ceil(width);
8704
8887
  };
8705
8888
  var resolvePromptFields = (options = {}, fallbackTitle = "") => {
8706
- const query = normalizeText(options.query);
8707
- const prompt = query || normalizeText(options.prompt) || normalizeText(fallbackTitle) || "\u672A\u63D0\u4F9B Prompt";
8889
+ const query = normalizeText2(options.query);
8890
+ const prompt = query || normalizeText2(options.prompt) || normalizeText2(fallbackTitle) || "\u672A\u63D0\u4F9B Prompt";
8708
8891
  return {
8709
8892
  prompt,
8710
8893
  query: query || prompt
@@ -8758,8 +8941,8 @@ var normalizeScreenshotWatermarkify = (value) => {
8758
8941
  enabled: source.enabled !== false,
8759
8942
  timezoneOffsetHours: Number.isFinite(timezoneOffsetHoursRaw) ? timezoneOffsetHoursRaw : DEFAULT_TIMEZONE_OFFSET,
8760
8943
  response: source.response ?? null,
8761
- ip: normalizeText(source.ip),
8762
- location: normalizeText(source.location),
8944
+ ip: normalizeText2(source.ip),
8945
+ location: normalizeText2(source.location),
8763
8946
  prompt: normalizeWhitespace(source.prompt),
8764
8947
  query: normalizeWhitespace(source.query),
8765
8948
  ipLookup: source.ipLookup !== false,
@@ -8777,8 +8960,8 @@ var normalizeScreenshotWatermarkify = (value) => {
8777
8960
  };
8778
8961
  var resolveScreenshotWatermarkifyMeta = async (page, options = {}) => {
8779
8962
  const timezoneOffsetHours = options.timezoneOffsetHours ?? DEFAULT_TIMEZONE_OFFSET;
8780
- const url = normalizeText(page?.url?.()) || "about:blank";
8781
- const title = normalizeText(await page.title().catch(() => "")) || "\u672A\u547D\u540D\u9875\u9762";
8963
+ const url = normalizeText2(page?.url?.()) || "about:blank";
8964
+ const title = normalizeText2(await page.title().catch(() => "")) || "\u672A\u547D\u540D\u9875\u9762";
8782
8965
  const hostname = getHostname(url);
8783
8966
  const { prompt, query } = resolvePromptFields(options, title);
8784
8967
  const capturedAt = options.capturedAt instanceof Date ? options.capturedAt : new Date(options.capturedAt || Date.now());
@@ -9265,7 +9448,7 @@ var renderMobileStrip = ({ meta, width, baseHeight, fontFamily }) => {
9265
9448
  `;
9266
9449
  };
9267
9450
  var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9268
- const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
9451
+ const hasWatermark = meta?.watermark?.enabled !== false && normalizeText2(meta?.watermarkText);
9269
9452
  const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
9270
9453
  if (!hasWatermark && !hasStrip) {
9271
9454
  return "";
@@ -9276,7 +9459,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9276
9459
  const fontFamily = escapeXml(buildFontFamily());
9277
9460
  const parts = [];
9278
9461
  if (hasWatermark) {
9279
- const stampText = escapeXml(normalizeText(meta.watermarkText));
9462
+ const stampText = escapeXml(normalizeText2(meta.watermarkText));
9280
9463
  const cellWidth = Math.max(680, Number(meta.watermark?.cellWidth) || DEFAULT_WATERMARK_CELL_WIDTH);
9281
9464
  const cellHeight = Math.max(260, Number(meta.watermark?.cellHeight) || DEFAULT_WATERMARK_CELL_HEIGHT);
9282
9465
  const rotateDeg = Number(meta.watermark?.rotateDeg) || DEFAULT_WATERMARK_ROTATE_DEG;
@@ -9443,7 +9626,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9443
9626
  `;
9444
9627
  };
9445
9628
  var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {}) => {
9446
- const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
9629
+ const hasWatermark = meta?.watermark?.enabled !== false && normalizeText2(meta?.watermarkText);
9447
9630
  const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
9448
9631
  if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
9449
9632
  return buffer;