@skrillex1224/playwright-toolkit 3.0.16 → 3.0.17

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.js CHANGED
@@ -1450,6 +1450,7 @@ var ProxyMeterRuntime = {
1450
1450
 
1451
1451
  // src/runtime-env.js
1452
1452
  var BROWSER_PROFILE_SCHEMA_VERSION = 1;
1453
+ var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
1453
1454
  var rememberedRuntimeState = null;
1454
1455
  var isPlainObject = (value) => value && typeof value === "object" && !Array.isArray(value);
1455
1456
  var normalizeKnownDevice = (value) => {
@@ -1458,6 +1459,22 @@ var normalizeKnownDevice = (value) => {
1458
1459
  if (raw === Device.Desktop) return Device.Desktop;
1459
1460
  return "";
1460
1461
  };
1462
+ var normalizeCloakSeed = (value) => {
1463
+ const numericSeed = Number(value);
1464
+ if (Number.isSafeInteger(numericSeed) && numericSeed > 0) {
1465
+ return numericSeed;
1466
+ }
1467
+ const raw = String(value || "").trim();
1468
+ if (!/^\d+$/.test(raw)) {
1469
+ return 0;
1470
+ }
1471
+ const parsedSeed = Number(raw);
1472
+ return Number.isSafeInteger(parsedSeed) && parsedSeed > 0 ? parsedSeed : 0;
1473
+ };
1474
+ var normalizeCloakFingerprintPlatform = (value) => {
1475
+ const raw = String(value || "").trim().toLowerCase();
1476
+ return SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS.has(raw) ? raw : "";
1477
+ };
1461
1478
  var deepClone = (value) => {
1462
1479
  if (value == null) return value;
1463
1480
  try {
@@ -1828,6 +1845,14 @@ var normalizeBrowserProfileCore = (value) => {
1828
1845
  if (Number.isFinite(browserMajorVersion) && browserMajorVersion > 0) {
1829
1846
  profile.browser_major_version = browserMajorVersion;
1830
1847
  }
1848
+ const cloakSeed = normalizeCloakSeed(source.cloak_seed);
1849
+ if (cloakSeed > 0) {
1850
+ profile.cloak_seed = cloakSeed;
1851
+ }
1852
+ const cloakFingerprintPlatform = normalizeCloakFingerprintPlatform(source.cloak_fingerprint_platform);
1853
+ if (cloakFingerprintPlatform) {
1854
+ profile.cloak_fingerprint_platform = cloakFingerprintPlatform;
1855
+ }
1831
1856
  const schemaVersion = Number(source.schema_version || 0);
1832
1857
  if (Number.isFinite(schemaVersion) && schemaVersion > 0) {
1833
1858
  profile.schema_version = schemaVersion;
@@ -5081,6 +5106,7 @@ var buildReplayableBrowserProfile = (runtimeState, launcher) => {
5081
5106
  const fingerprint = generated.fingerprint;
5082
5107
  const fingerprintBrowserMajorVersion = parseChromeMajorVersion(fingerprint?.fingerprint?.navigator?.userAgent || "");
5083
5108
  browserProfileCore = {
5109
+ ...browserProfileCore,
5084
5110
  fingerprint,
5085
5111
  device,
5086
5112
  timezone_id: timezoneId,
@@ -5274,6 +5300,7 @@ var DefaultLaunch = {
5274
5300
 
5275
5301
  // src/internals/launch/cloak.js
5276
5302
  import { execFile } from "node:child_process";
5303
+ import { randomInt } from "node:crypto";
5277
5304
  import { promisify } from "node:util";
5278
5305
  var logger9 = createInternalLogger("Launch");
5279
5306
  var execFileAsync = promisify(execFile);
@@ -5289,9 +5316,15 @@ var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
5289
5316
  var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
5290
5317
  waitUntil: "commit"
5291
5318
  });
5319
+ var DEFAULT_CLOAK_SEED_MIN = 1e4;
5320
+ var DEFAULT_CLOAK_SEED_MAX = 99999;
5292
5321
  var DEFAULT_CLOAK_FINGERPRINT_PLATFORM = "linux";
5322
+ var CLOAK_FINGERPRINT_ARG_PREFIX = "--fingerprint=";
5293
5323
  var CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX = "--fingerprint-platform=";
5294
- var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
5324
+ var CLOAK_FINGERPRINT_TIMEZONE_ARG_PREFIX = "--fingerprint-timezone=";
5325
+ var CLOAK_FINGERPRINT_LOCALE_ARG_PREFIX = "--fingerprint-locale=";
5326
+ var CLOAK_LANG_ARG_PREFIX = "--lang=";
5327
+ var SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS2 = /* @__PURE__ */ new Set(["linux", "macos", "windows"]);
5295
5328
  var cachedCloakModulePromise = null;
5296
5329
  var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
5297
5330
  var loadCloakModule = async () => {
@@ -5321,16 +5354,36 @@ var normalizeStringArray = (value) => {
5321
5354
  }
5322
5355
  return value.map((item) => String(item || "").trim()).filter(Boolean);
5323
5356
  };
5357
+ var normalizeText = (value) => String(value || "").trim();
5358
+ var normalizePositiveInteger = (value) => {
5359
+ const numericValue = Number(value);
5360
+ if (Number.isSafeInteger(numericValue) && numericValue > 0) {
5361
+ return numericValue;
5362
+ }
5363
+ const raw = normalizeText(value);
5364
+ if (!/^\d+$/.test(raw)) {
5365
+ return 0;
5366
+ }
5367
+ const parsedValue = Number(raw);
5368
+ return Number.isSafeInteger(parsedValue) && parsedValue > 0 ? parsedValue : 0;
5369
+ };
5370
+ var normalizeCloakFingerprintPlatform2 = (value) => {
5371
+ const normalizedFingerprintPlatform = String(value || "").trim().toLowerCase();
5372
+ return SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS2.has(normalizedFingerprintPlatform) ? normalizedFingerprintPlatform : "";
5373
+ };
5374
+ var buildCloakFingerprintPlatformArg = (fingerprintPlatform = DEFAULT_CLOAK_FINGERPRINT_PLATFORM) => `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${fingerprintPlatform}`;
5324
5375
  var resolveCloakFingerprintPlatformArg = (fingerprintPlatform = "", args = []) => {
5325
- const normalizedFingerprintPlatform = String(fingerprintPlatform || "").trim().toLowerCase();
5326
- if (SUPPORTED_CLOAK_FINGERPRINT_PLATFORMS.has(normalizedFingerprintPlatform)) {
5327
- return `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${normalizedFingerprintPlatform}`;
5376
+ const normalizedFingerprintPlatform = normalizeCloakFingerprintPlatform2(fingerprintPlatform);
5377
+ if (normalizedFingerprintPlatform) {
5378
+ return buildCloakFingerprintPlatformArg(normalizedFingerprintPlatform);
5328
5379
  }
5329
- const existingArg = normalizeStringArray(args).find((value) => value.startsWith(CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX));
5330
- if (existingArg) {
5331
- return existingArg;
5380
+ const existingFingerprintPlatform = normalizeCloakFingerprintPlatform2(
5381
+ extractArgValue(args, CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX)
5382
+ );
5383
+ if (existingFingerprintPlatform) {
5384
+ return buildCloakFingerprintPlatformArg(existingFingerprintPlatform);
5332
5385
  }
5333
- return `${CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX}${DEFAULT_CLOAK_FINGERPRINT_PLATFORM}`;
5386
+ return buildCloakFingerprintPlatformArg(DEFAULT_CLOAK_FINGERPRINT_PLATFORM);
5334
5387
  };
5335
5388
  var resolveCloakProxy = (proxyConfiguration = {}) => {
5336
5389
  const config = normalizeObject2(proxyConfiguration);
@@ -5353,7 +5406,124 @@ var resolveCloakProxy = (proxyConfiguration = {}) => {
5353
5406
  };
5354
5407
  var extractFingerprintArg = (launchOptions = {}) => {
5355
5408
  const args = Array.isArray(launchOptions?.args) ? launchOptions.args : [];
5356
- return args.find((value) => String(value || "").startsWith("--fingerprint=")) || "";
5409
+ return args.find((value) => String(value || "").startsWith(CLOAK_FINGERPRINT_ARG_PREFIX)) || "";
5410
+ };
5411
+ var buildFingerprintArg = (seed) => `${CLOAK_FINGERPRINT_ARG_PREFIX}${seed}`;
5412
+ var extractArgValue = (args = [], prefix = "") => {
5413
+ const matchedArg = normalizeStringArray(args).find((value) => value.startsWith(prefix));
5414
+ if (!matchedArg) {
5415
+ return "";
5416
+ }
5417
+ return normalizeText(matchedArg.slice(prefix.length));
5418
+ };
5419
+ var extractFingerprintSeedFromArgs = (args = []) => normalizePositiveInteger(
5420
+ extractArgValue(args, CLOAK_FINGERPRINT_ARG_PREFIX)
5421
+ );
5422
+ var extractLocaleFromArgs = (args = []) => extractArgValue(args, CLOAK_LANG_ARG_PREFIX) || extractArgValue(args, CLOAK_FINGERPRINT_LOCALE_ARG_PREFIX);
5423
+ var extractTimezoneFromArgs = (args = []) => extractArgValue(args, CLOAK_FINGERPRINT_TIMEZONE_ARG_PREFIX);
5424
+ var hashStringToSeed = (value = "") => {
5425
+ let hash = 2166136261;
5426
+ const text = normalizeText(value);
5427
+ for (let index = 0; index < text.length; index += 1) {
5428
+ hash ^= text.charCodeAt(index);
5429
+ hash = Math.imul(hash, 16777619);
5430
+ }
5431
+ const numericHash = hash >>> 0;
5432
+ const seedRange = DEFAULT_CLOAK_SEED_MAX - DEFAULT_CLOAK_SEED_MIN + 1;
5433
+ return DEFAULT_CLOAK_SEED_MIN + numericHash % seedRange;
5434
+ };
5435
+ var buildCloakSeedIdentity = (runtimeState = {}) => {
5436
+ const normalizedRuntimeState = normalizeObject2(runtimeState);
5437
+ const normalizedEnvId = normalizeText(normalizedRuntimeState.envId);
5438
+ if (normalizedEnvId) {
5439
+ return `env:${normalizedEnvId}`;
5440
+ }
5441
+ const runtimePayload = normalizeObject2(normalizedRuntimeState.runtime);
5442
+ if (Object.keys(runtimePayload).length === 0) {
5443
+ return "";
5444
+ }
5445
+ return JSON.stringify({
5446
+ actor: normalizeText(normalizedRuntimeState.actor),
5447
+ device: normalizeText(normalizedRuntimeState.device),
5448
+ runtime: runtimePayload
5449
+ });
5450
+ };
5451
+ var generateCloakSeed = (runtimeState = {}) => {
5452
+ const identity = buildCloakSeedIdentity(runtimeState);
5453
+ if (identity) {
5454
+ return hashStringToSeed(`cloak:${identity}`);
5455
+ }
5456
+ return randomInt(DEFAULT_CLOAK_SEED_MIN, DEFAULT_CLOAK_SEED_MAX + 1);
5457
+ };
5458
+ var resolveReplayableCloakProfile = (runtimeState, { fingerprintPlatform = "", cloakOptions = {} } = {}) => {
5459
+ const normalizedCloakOptions = normalizeObject2(cloakOptions);
5460
+ const normalizedArgs = normalizeStringArray(normalizedCloakOptions.args);
5461
+ const explicitFingerprintSeed = extractFingerprintSeedFromArgs(normalizedArgs);
5462
+ const explicitFingerprintPlatform = normalizeCloakFingerprintPlatform2(fingerprintPlatform) || normalizeCloakFingerprintPlatform2(
5463
+ extractArgValue(normalizedArgs, CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX)
5464
+ );
5465
+ const explicitTimezone = normalizeText(
5466
+ normalizedCloakOptions.timezone || normalizedCloakOptions.timezoneId || extractTimezoneFromArgs(normalizedArgs)
5467
+ );
5468
+ const explicitLocale = normalizeText(
5469
+ normalizedCloakOptions.locale || extractLocaleFromArgs(normalizedArgs)
5470
+ );
5471
+ if (!runtimeState || !RuntimeEnv.hasLoginState(runtimeState)) {
5472
+ return {
5473
+ runtimeState,
5474
+ browserProfileCore: null,
5475
+ fingerprintSeed: explicitFingerprintSeed,
5476
+ fingerprintPlatform: explicitFingerprintPlatform,
5477
+ locale: explicitLocale,
5478
+ timezone: explicitTimezone,
5479
+ hasExplicitFingerprintSeed: explicitFingerprintSeed > 0,
5480
+ hasExplicitLocale: Boolean(explicitLocale),
5481
+ hasExplicitTimezone: Boolean(explicitTimezone)
5482
+ };
5483
+ }
5484
+ let nextState = RuntimeEnv.rememberState(runtimeState);
5485
+ const currentBrowserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
5486
+ const storedFingerprintSeed = normalizePositiveInteger(currentBrowserProfileCore?.cloak_seed);
5487
+ const storedFingerprintPlatform = normalizeCloakFingerprintPlatform2(
5488
+ currentBrowserProfileCore?.cloak_fingerprint_platform
5489
+ );
5490
+ const storedLocale = normalizeText(currentBrowserProfileCore?.locale);
5491
+ const storedTimezone = normalizeText(currentBrowserProfileCore?.timezone_id);
5492
+ const fingerprintSeed = explicitFingerprintSeed || storedFingerprintSeed || generateCloakSeed(nextState);
5493
+ const resolvedFingerprintPlatform = explicitFingerprintPlatform || storedFingerprintPlatform || DEFAULT_CLOAK_FINGERPRINT_PLATFORM;
5494
+ const locale = explicitLocale || storedLocale;
5495
+ const timezone = explicitTimezone || storedTimezone;
5496
+ const nextBrowserProfileCore = {
5497
+ ...currentBrowserProfileCore,
5498
+ cloak_seed: fingerprintSeed,
5499
+ cloak_fingerprint_platform: resolvedFingerprintPlatform
5500
+ };
5501
+ if (locale) {
5502
+ nextBrowserProfileCore.locale = locale;
5503
+ }
5504
+ if (timezone) {
5505
+ nextBrowserProfileCore.timezone_id = timezone;
5506
+ }
5507
+ const currentCoreRaw = JSON.stringify(currentBrowserProfileCore || {});
5508
+ const nextCoreRaw = JSON.stringify(nextBrowserProfileCore);
5509
+ if (currentCoreRaw !== nextCoreRaw) {
5510
+ nextState = RuntimeEnv.setBrowserProfileCore(nextState, nextBrowserProfileCore);
5511
+ logger9.info(
5512
+ `\u5DF2\u540C\u6B65 Cloak \u6307\u7EB9\u771F\u6E90 | env=${String(nextState.envId || "-")} | seed=${fingerprintSeed} | platform=${resolvedFingerprintPlatform} | timezone=${timezone || "-"} | locale=${locale || "-"}`
5513
+ );
5514
+ }
5515
+ const rememberedBrowserProfileCore = RuntimeEnv.getBrowserProfileCore(nextState);
5516
+ return {
5517
+ runtimeState: nextState,
5518
+ browserProfileCore: rememberedBrowserProfileCore,
5519
+ fingerprintSeed,
5520
+ fingerprintPlatform: resolvedFingerprintPlatform,
5521
+ locale,
5522
+ timezone,
5523
+ hasExplicitFingerprintSeed: explicitFingerprintSeed > 0,
5524
+ hasExplicitLocale: Boolean(explicitLocale),
5525
+ hasExplicitTimezone: Boolean(explicitTimezone)
5526
+ };
5357
5527
  };
5358
5528
  var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS) => {
5359
5529
  const normalizedRecommendedGotoOptions = normalizeObject2(recommendedGotoOptions);
@@ -5467,6 +5637,7 @@ var CloakLaunch = {
5467
5637
  runInHeadfulMode = false,
5468
5638
  isRunningOnApify = false,
5469
5639
  launcher = null,
5640
+ runtimeState = null,
5470
5641
  fingerprintPlatform = "",
5471
5642
  cloakOptions = {},
5472
5643
  humanizeOptions = DEFAULT_CLOAK_HUMANIZE_OPTIONS,
@@ -5481,8 +5652,16 @@ var CloakLaunch = {
5481
5652
  const activeBrowsers = /* @__PURE__ */ new Set();
5482
5653
  const patchedBrowsers = /* @__PURE__ */ new WeakSet();
5483
5654
  const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
5484
- const fingerprintPlatformArg = resolveCloakFingerprintPlatformArg(fingerprintPlatform, normalizedCloakOptions.args);
5655
+ const replayContext = resolveReplayableCloakProfile(runtimeState, {
5656
+ fingerprintPlatform,
5657
+ cloakOptions: normalizedCloakOptions
5658
+ });
5659
+ const fingerprintPlatformArg = resolveCloakFingerprintPlatformArg(
5660
+ replayContext.fingerprintPlatform,
5661
+ normalizedCloakOptions.args
5662
+ );
5485
5663
  const extraArgs = normalizeStringArray(normalizedCloakOptions.args).filter((value) => !value.startsWith(CLOAK_FINGERPRINT_PLATFORM_ARG_PREFIX));
5664
+ const replayFingerprintArg = !replayContext.hasExplicitFingerprintSeed && replayContext.fingerprintSeed > 0 ? buildFingerprintArg(replayContext.fingerprintSeed) : "";
5486
5665
  const hasExplicitProxy = hasOwn(normalizedCloakOptions, "proxy");
5487
5666
  const proxyLaunchState = hasExplicitProxy ? resolveLaunchTraffic({ proxyConfiguration, debugMode, useMeter: false }) : resolveLaunchTraffic({ proxyConfiguration, debugMode });
5488
5667
  const proxy = hasExplicitProxy ? normalizedCloakOptions.proxy : proxyLaunchState.launchProxy;
@@ -5492,7 +5671,15 @@ var CloakLaunch = {
5492
5671
  ...normalizedCloakOptions,
5493
5672
  headless,
5494
5673
  proxy,
5495
- args: [...defaultArgs, ...extraArgs, fingerprintPlatformArg]
5674
+ ...normalizedCloakOptions.timezoneId && !hasOwn(normalizedCloakOptions, "timezone") ? { timezone: normalizedCloakOptions.timezoneId } : {},
5675
+ ...replayContext.timezone && !replayContext.hasExplicitTimezone ? { timezone: replayContext.timezone } : {},
5676
+ ...replayContext.locale && !replayContext.hasExplicitLocale ? { locale: replayContext.locale } : {},
5677
+ args: [
5678
+ ...defaultArgs,
5679
+ ...replayFingerprintArg ? [replayFingerprintArg] : [],
5680
+ ...extraArgs,
5681
+ fingerprintPlatformArg
5682
+ ]
5496
5683
  };
5497
5684
  const launchOptions = await buildCloakLaunchOptions(mergedCloakOptions);
5498
5685
  const fingerprintArg = extractFingerprintArg(launchOptions);
@@ -6313,10 +6500,6 @@ var sleep = (ms) => new Promise((resolve) => {
6313
6500
  });
6314
6501
  var getErrorMessage = (error) => String(error?.message || error || "");
6315
6502
  var isTimeoutError = (error) => error?.name === "TimeoutError" || getErrorMessage(error).includes("Timeout");
6316
- var isPageLifecycleError = (error) => {
6317
- const message = getErrorMessage(error);
6318
- 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");
6319
- };
6320
6503
  function useCaptchaMonitor(page, options) {
6321
6504
  const { domSelector, urlPattern, onDetected } = options;
6322
6505
  if (!domSelector && !urlPattern) {
@@ -6358,8 +6541,8 @@ function useCaptchaMonitor(page, options) {
6358
6541
  });
6359
6542
  } catch (error) {
6360
6543
  if (isStopped) break;
6361
- if (page?.isClosed?.() && isPageLifecycleError(error)) break;
6362
- if (isTimeoutError(error) || isPageLifecycleError(error)) {
6544
+ if (page?.isClosed?.()) break;
6545
+ if (isTimeoutError(error)) {
6363
6546
  await sleep(DOM_MONITOR_RECOVERY_WAIT_MS);
6364
6547
  continue;
6365
6548
  }
@@ -6656,7 +6839,7 @@ var Mutation = {
6656
6839
  if (text.length <= max) return text;
6657
6840
  return `${text.slice(0, max)}...`;
6658
6841
  };
6659
- const normalizeText2 = (value) => String(value || "").replace(/\s+/g, " ").trim();
6842
+ const normalizeText3 = (value) => String(value || "").replace(/\s+/g, " ").trim();
6660
6843
  const normalizeHtml = (value) => String(value || "").trim();
6661
6844
  const hashSnapshot = (value) => createHash("sha256").update(String(value || "")).digest("hex");
6662
6845
  const buildState = async () => {
@@ -6721,7 +6904,7 @@ var Mutation = {
6721
6904
  if (frame) {
6722
6905
  try {
6723
6906
  const frameSnapshot = await readFrameSnapshot(frame);
6724
- text = normalizeText2(frameSnapshot?.text || "");
6907
+ text = normalizeText3(frameSnapshot?.text || "");
6725
6908
  html = normalizeHtml(frameSnapshot?.html || "");
6726
6909
  frameUrl = String(frameSnapshot?.url || "").trim();
6727
6910
  readyState = String(frameSnapshot?.readyState || "").trim();
@@ -6735,7 +6918,7 @@ var Mutation = {
6735
6918
  } else {
6736
6919
  try {
6737
6920
  const elementSnapshot = await readElementSnapshot(handle);
6738
- text = normalizeText2(elementSnapshot?.text || "");
6921
+ text = normalizeText3(elementSnapshot?.text || "");
6739
6922
  html = normalizeHtml(elementSnapshot?.html || "");
6740
6923
  } catch (error) {
6741
6924
  source = "main-unreadable";
@@ -7997,9 +8180,9 @@ var LOCATION_NETWORK_SUFFIX_PATTERNS = [
7997
8180
  var cachedStripLogoSrcPromise = null;
7998
8181
  var cachedEnrichmentByContext = /* @__PURE__ */ new WeakMap();
7999
8182
  var logger14 = createInternalLogger("Watermarkify");
8000
- var normalizeText = (value) => String(value || "").trim();
8183
+ var normalizeText2 = (value) => String(value || "").trim();
8001
8184
  var toInline = (value, maxLen = 200) => {
8002
- const text = normalizeText(value);
8185
+ const text = normalizeText2(value);
8003
8186
  if (!text) return "";
8004
8187
  return text.replace(/\s+/g, " ").trim().slice(0, maxLen);
8005
8188
  };
@@ -8059,7 +8242,7 @@ var pickHeaderValue = async (response, names = []) => {
8059
8242
  if (!response || typeof response.headerValue !== "function") return "";
8060
8243
  for (const name of names) {
8061
8244
  const value = await response.headerValue(name).catch(() => null);
8062
- const text = normalizeText(value);
8245
+ const text = normalizeText2(value);
8063
8246
  if (text) return text;
8064
8247
  }
8065
8248
  return "";
@@ -8163,7 +8346,7 @@ var fetchAsDataUrl = async (url, timeoutMs = DEFAULT_LOGO_FETCH_TIMEOUT_MS) => {
8163
8346
  if (!response?.ok) {
8164
8347
  return "";
8165
8348
  }
8166
- const contentType = normalizeText(response.headers?.get?.("content-type")) || "image/png";
8349
+ const contentType = normalizeText2(response.headers?.get?.("content-type")) || "image/png";
8167
8350
  if (!/^image\//i.test(contentType)) {
8168
8351
  return "";
8169
8352
  }
@@ -8186,7 +8369,7 @@ var resolveStripLogoSrc = async () => {
8186
8369
  })();
8187
8370
  }
8188
8371
  const resolved = await cachedStripLogoSrcPromise.catch(() => DEFAULT_STRIP_LOGO_URL);
8189
- return normalizeText(resolved) || DEFAULT_STRIP_LOGO_URL;
8372
+ return normalizeText2(resolved) || DEFAULT_STRIP_LOGO_URL;
8190
8373
  };
8191
8374
  var normalizeLayer = (value, defaults) => {
8192
8375
  if (value === false) {
@@ -8536,7 +8719,7 @@ var resolveWithIpLookup = async (page, options = {}) => {
8536
8719
  return null;
8537
8720
  });
8538
8721
  const status = response && typeof response.status === "function" ? response.status() : 0;
8539
- const contentType = normalizeText(await pickHeaderValue(response, ["content-type"]));
8722
+ const contentType = normalizeText2(await pickHeaderValue(response, ["content-type"]));
8540
8723
  let rawText = "";
8541
8724
  if (response && typeof response.text === "function") {
8542
8725
  rawText = String(await withTimeout2(
@@ -8675,8 +8858,8 @@ var estimateTextWidth = (value, fontSize = 16) => {
8675
8858
  return Math.ceil(width);
8676
8859
  };
8677
8860
  var resolvePromptFields = (options = {}, fallbackTitle = "") => {
8678
- const query = normalizeText(options.query);
8679
- const prompt = query || normalizeText(options.prompt) || normalizeText(fallbackTitle) || "\u672A\u63D0\u4F9B Prompt";
8861
+ const query = normalizeText2(options.query);
8862
+ const prompt = query || normalizeText2(options.prompt) || normalizeText2(fallbackTitle) || "\u672A\u63D0\u4F9B Prompt";
8680
8863
  return {
8681
8864
  prompt,
8682
8865
  query: query || prompt
@@ -8730,8 +8913,8 @@ var normalizeScreenshotWatermarkify = (value) => {
8730
8913
  enabled: source.enabled !== false,
8731
8914
  timezoneOffsetHours: Number.isFinite(timezoneOffsetHoursRaw) ? timezoneOffsetHoursRaw : DEFAULT_TIMEZONE_OFFSET,
8732
8915
  response: source.response ?? null,
8733
- ip: normalizeText(source.ip),
8734
- location: normalizeText(source.location),
8916
+ ip: normalizeText2(source.ip),
8917
+ location: normalizeText2(source.location),
8735
8918
  prompt: normalizeWhitespace(source.prompt),
8736
8919
  query: normalizeWhitespace(source.query),
8737
8920
  ipLookup: source.ipLookup !== false,
@@ -8749,8 +8932,8 @@ var normalizeScreenshotWatermarkify = (value) => {
8749
8932
  };
8750
8933
  var resolveScreenshotWatermarkifyMeta = async (page, options = {}) => {
8751
8934
  const timezoneOffsetHours = options.timezoneOffsetHours ?? DEFAULT_TIMEZONE_OFFSET;
8752
- const url = normalizeText(page?.url?.()) || "about:blank";
8753
- const title = normalizeText(await page.title().catch(() => "")) || "\u672A\u547D\u540D\u9875\u9762";
8935
+ const url = normalizeText2(page?.url?.()) || "about:blank";
8936
+ const title = normalizeText2(await page.title().catch(() => "")) || "\u672A\u547D\u540D\u9875\u9762";
8754
8937
  const hostname = getHostname(url);
8755
8938
  const { prompt, query } = resolvePromptFields(options, title);
8756
8939
  const capturedAt = options.capturedAt instanceof Date ? options.capturedAt : new Date(options.capturedAt || Date.now());
@@ -9237,7 +9420,7 @@ var renderMobileStrip = ({ meta, width, baseHeight, fontFamily }) => {
9237
9420
  `;
9238
9421
  };
9239
9422
  var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9240
- const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
9423
+ const hasWatermark = meta?.watermark?.enabled !== false && normalizeText2(meta?.watermarkText);
9241
9424
  const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
9242
9425
  if (!hasWatermark && !hasStrip) {
9243
9426
  return "";
@@ -9248,7 +9431,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9248
9431
  const fontFamily = escapeXml(buildFontFamily());
9249
9432
  const parts = [];
9250
9433
  if (hasWatermark) {
9251
- const stampText = escapeXml(normalizeText(meta.watermarkText));
9434
+ const stampText = escapeXml(normalizeText2(meta.watermarkText));
9252
9435
  const cellWidth = Math.max(680, Number(meta.watermark?.cellWidth) || DEFAULT_WATERMARK_CELL_WIDTH);
9253
9436
  const cellHeight = Math.max(260, Number(meta.watermark?.cellHeight) || DEFAULT_WATERMARK_CELL_HEIGHT);
9254
9437
  const rotateDeg = Number(meta.watermark?.rotateDeg) || DEFAULT_WATERMARK_ROTATE_DEG;
@@ -9415,7 +9598,7 @@ var buildWatermarkifySvg = (meta, imageWidth, imageHeight) => {
9415
9598
  `;
9416
9599
  };
9417
9600
  var watermarkifyScreenshotBuffer = async (buffer, meta, page = null, options = {}) => {
9418
- const hasWatermark = meta?.watermark?.enabled !== false && normalizeText(meta?.watermarkText);
9601
+ const hasWatermark = meta?.watermark?.enabled !== false && normalizeText2(meta?.watermarkText);
9419
9602
  const hasStrip = meta?.strip?.enabled !== false && Array.isArray(meta?.stripSegments) && meta.stripSegments.length > 0;
9420
9603
  if (!Buffer.isBuffer(buffer) || !meta || !hasWatermark && !hasStrip) {
9421
9604
  return buffer;