@skrillex1224/playwright-toolkit 2.1.199 → 2.1.201

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
@@ -571,31 +571,9 @@ var logger2 = createInternalLogger("ProxyMeter");
571
571
  var MAX_TOP_DOMAINS = 20;
572
572
  var FLUSH_INTERVAL_MS = 2e3;
573
573
  var DEFAULT_DEBUG_MAX_EVENTS = 400;
574
- var PROXY_METER_READY_TIMEOUT_MS = 5e3;
575
- var PROXY_METER_STABLE_WINDOW_MS = 2e3;
576
- var PROXY_METER_POLL_INTERVAL_MS = 100;
577
- var PROXY_METER_CONNECT_TIMEOUT_MS = 200;
578
574
  var runtime = null;
579
575
  var cleanupInstalled = false;
580
576
  var observedDomainResourceTypes = /* @__PURE__ */ new Map();
581
- var sleepSignal = new Int32Array(new SharedArrayBuffer(4));
582
- var portProbeScript = [
583
- 'const net = require("net");',
584
- "const port = Number(process.argv[1] || 0);",
585
- "const timeout = Number(process.argv[2] || 200);",
586
- "if (!Number.isFinite(port) || port <= 0) process.exit(2);",
587
- 'const socket = net.connect({ host: "127.0.0.1", port });',
588
- "let done = false;",
589
- "const finish = (code) => {",
590
- " if (done) return;",
591
- " done = true;",
592
- " try { socket.destroy(); } catch {}",
593
- " process.exit(code);",
594
- "};",
595
- 'socket.once("connect", () => finish(0));',
596
- 'socket.once("error", () => finish(1));',
597
- "socket.setTimeout(timeout, () => finish(1));"
598
- ].join("");
599
577
  var toSafeInt = (value) => {
600
578
  const num = Number(value);
601
579
  if (!Number.isFinite(num) || num <= 0) return 0;
@@ -694,17 +672,6 @@ var ensureLogPath = () => {
694
672
  const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
695
673
  return path.join(baseDir, label);
696
674
  };
697
- var ensureStatePath = () => {
698
- const baseDir = resolveLogDir();
699
- if (!existsSync(baseDir)) {
700
- try {
701
- mkdirSync(baseDir, { recursive: true });
702
- } catch {
703
- }
704
- }
705
- const suffix = `${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
706
- return path.join(baseDir, `proxy-meter-state-${process.pid}-${suffix}.json`);
707
- };
708
675
  var readSnapshot = (logPath) => {
709
676
  if (!logPath || !existsSync(logPath)) return null;
710
677
  try {
@@ -715,86 +682,6 @@ var readSnapshot = (logPath) => {
715
682
  return null;
716
683
  }
717
684
  };
718
- var readState = (statePath) => {
719
- if (!statePath || !existsSync(statePath)) return null;
720
- try {
721
- const raw = readFileSync(statePath, "utf8");
722
- if (!raw) return null;
723
- return JSON.parse(raw);
724
- } catch {
725
- return null;
726
- }
727
- };
728
- var sleepSync = (durationMs) => {
729
- const timeout = Math.max(0, Number(durationMs) || 0);
730
- if (timeout <= 0) return;
731
- Atomics.wait(sleepSignal, 0, 0, timeout);
732
- };
733
- var canConnectToPort = (port, timeoutMs = PROXY_METER_CONNECT_TIMEOUT_MS) => {
734
- const result = spawnSync(process.execPath, ["-e", portProbeScript, String(port), String(timeoutMs)], {
735
- stdio: "ignore",
736
- timeout: timeoutMs + 100
737
- });
738
- return result.status === 0;
739
- };
740
- var waitForProxyMeterReady = ({ port, statePath }) => {
741
- const startedAt = Date.now();
742
- const listenDeadline = startedAt + PROXY_METER_READY_TIMEOUT_MS;
743
- let firstConnectAt = 0;
744
- let stableHealthy = true;
745
- while (Date.now() < listenDeadline) {
746
- const lifecycle = readState(statePath);
747
- if (lifecycle?.status === "exited") {
748
- return {
749
- ok: false,
750
- reason: "child_exit_before_ready",
751
- childExitCode: lifecycle.exitCode,
752
- latencyMs: Date.now() - startedAt
753
- };
754
- }
755
- if (canConnectToPort(port)) {
756
- firstConnectAt = Date.now();
757
- break;
758
- }
759
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
760
- }
761
- if (!firstConnectAt) {
762
- return {
763
- ok: false,
764
- reason: "listen_timeout",
765
- childExitCode: readState(statePath)?.exitCode ?? null,
766
- latencyMs: Date.now() - startedAt
767
- };
768
- }
769
- const stableDeadline = firstConnectAt + PROXY_METER_STABLE_WINDOW_MS;
770
- while (Date.now() < stableDeadline) {
771
- const lifecycle = readState(statePath);
772
- if (lifecycle?.status === "exited") {
773
- return {
774
- ok: false,
775
- reason: "stabilize_timeout",
776
- childExitCode: lifecycle.exitCode,
777
- latencyMs: Date.now() - startedAt
778
- };
779
- }
780
- if (!canConnectToPort(port)) {
781
- stableHealthy = false;
782
- }
783
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
784
- }
785
- if (!stableHealthy || !canConnectToPort(port)) {
786
- return {
787
- ok: false,
788
- reason: "stabilize_timeout",
789
- childExitCode: readState(statePath)?.exitCode ?? null,
790
- latencyMs: Date.now() - startedAt
791
- };
792
- }
793
- return {
794
- ok: true,
795
- latencyMs: Date.now() - startedAt
796
- };
797
- };
798
685
  var normalizeDomainRows = (hosts) => {
799
686
  const rows = [];
800
687
  let requestCount = 0;
@@ -943,23 +830,15 @@ var startProxyMeter = (options = {}) => {
943
830
  const upstreamUrl = String(options.proxyUrl || "").trim();
944
831
  if (!upstreamUrl) return null;
945
832
  if (runtime && runtime.proc) {
946
- const previousStatePath = runtime.statePath;
947
833
  try {
948
834
  runtime.proc.kill("SIGTERM");
949
835
  } catch {
950
836
  }
951
837
  runtime = null;
952
- if (previousStatePath) {
953
- try {
954
- rmSync(previousStatePath, { force: true });
955
- } catch {
956
- }
957
- }
958
838
  }
959
839
  observedDomainResourceTypes = /* @__PURE__ */ new Map();
960
840
  const port = pickFreePort();
961
841
  const logPath = ensureLogPath();
962
- const statePath = ensureStatePath();
963
842
  const scriptPath = resolveScriptPath();
964
843
  const debugMode = Boolean(options.debugMode);
965
844
  const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
@@ -970,8 +849,7 @@ var startProxyMeter = (options = {}) => {
970
849
  PROXY_METER_UPSTREAM: upstreamUrl,
971
850
  PROXY_METER_FLUSH_MS: String(FLUSH_INTERVAL_MS),
972
851
  PROXY_METER_DEBUG: debugMode ? "1" : "0",
973
- PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents),
974
- PROXY_METER_STATE: statePath
852
+ PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
975
853
  };
976
854
  const child = spawn(process.execPath, [scriptPath], {
977
855
  env,
@@ -986,27 +864,8 @@ var startProxyMeter = (options = {}) => {
986
864
  proc: child,
987
865
  port,
988
866
  logPath,
989
- statePath,
990
867
  startedAt: Date.now()
991
868
  };
992
- const readiness = waitForProxyMeterReady({ port, statePath });
993
- if (!readiness.ok) {
994
- logger2.warn(
995
- `[proxy-meter] startup failed reason=${readiness.reason} latency_ms=${readiness.latencyMs} exit_code=${readiness.childExitCode ?? "unknown"}`
996
- );
997
- try {
998
- child.kill("SIGTERM");
999
- } catch {
1000
- }
1001
- runtime = null;
1002
- try {
1003
- rmSync(statePath, { force: true });
1004
- } catch {
1005
- }
1006
- throw new Error(`proxy-meter startup failed: ${readiness.reason}`);
1007
- }
1008
- runtime.startedAt = Date.now() - readiness.latencyMs;
1009
- logger2.info(`[proxy-meter] ready latency_ms=${readiness.latencyMs} stable_window_ms=${PROXY_METER_STABLE_WINDOW_MS}`);
1010
869
  registerCleanup();
1011
870
  return { server: `http://127.0.0.1:${port}` };
1012
871
  };
@@ -1018,15 +877,9 @@ var recordProxyMeterResourceType = (requestUrl, resourceType) => {
1018
877
  };
1019
878
  var stopProxyMeter = async () => {
1020
879
  if (!runtime) return null;
1021
- const { proc, logPath, statePath } = runtime;
880
+ const { proc, logPath } = runtime;
1022
881
  if (!proc || proc.killed) {
1023
882
  runtime = null;
1024
- if (statePath) {
1025
- try {
1026
- rmSync(statePath, { force: true });
1027
- } catch {
1028
- }
1029
- }
1030
883
  return logPath || null;
1031
884
  }
1032
885
  await new Promise((resolve) => {
@@ -1048,12 +901,6 @@ var stopProxyMeter = async () => {
1048
901
  }
1049
902
  });
1050
903
  runtime = null;
1051
- if (statePath) {
1052
- try {
1053
- rmSync(statePath, { force: true });
1054
- } catch {
1055
- }
1056
- }
1057
904
  return logPath || null;
1058
905
  };
1059
906
  var getProxyMeterSnapshot = async (options = {}) => {