@skrillex1224/playwright-toolkit 2.1.200 → 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 = 500;
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,83 +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
- while (Date.now() < listenDeadline) {
745
- const lifecycle = readState(statePath);
746
- if (lifecycle?.status === "exited") {
747
- return {
748
- ok: false,
749
- reason: "child_exit_before_ready",
750
- childExitCode: lifecycle.exitCode,
751
- latencyMs: Date.now() - startedAt
752
- };
753
- }
754
- if (canConnectToPort(port)) {
755
- firstConnectAt = Date.now();
756
- break;
757
- }
758
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
759
- }
760
- if (!firstConnectAt) {
761
- return {
762
- ok: false,
763
- reason: "listen_timeout",
764
- childExitCode: readState(statePath)?.exitCode ?? null,
765
- latencyMs: Date.now() - startedAt
766
- };
767
- }
768
- const stableDeadline = firstConnectAt + PROXY_METER_STABLE_WINDOW_MS;
769
- while (Date.now() < stableDeadline) {
770
- const lifecycle = readState(statePath);
771
- if (lifecycle?.status === "exited") {
772
- return {
773
- ok: false,
774
- reason: "child_exit_before_ready",
775
- childExitCode: lifecycle.exitCode,
776
- latencyMs: Date.now() - startedAt
777
- };
778
- }
779
- canConnectToPort(port);
780
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
781
- }
782
- if (!canConnectToPort(port)) {
783
- return {
784
- ok: false,
785
- reason: "stabilize_timeout",
786
- childExitCode: readState(statePath)?.exitCode ?? null,
787
- latencyMs: Date.now() - startedAt
788
- };
789
- }
790
- return {
791
- ok: true,
792
- latencyMs: Date.now() - startedAt
793
- };
794
- };
795
685
  var normalizeDomainRows = (hosts) => {
796
686
  const rows = [];
797
687
  let requestCount = 0;
@@ -940,23 +830,15 @@ var startProxyMeter = (options = {}) => {
940
830
  const upstreamUrl = String(options.proxyUrl || "").trim();
941
831
  if (!upstreamUrl) return null;
942
832
  if (runtime && runtime.proc) {
943
- const previousStatePath = runtime.statePath;
944
833
  try {
945
834
  runtime.proc.kill("SIGTERM");
946
835
  } catch {
947
836
  }
948
837
  runtime = null;
949
- if (previousStatePath) {
950
- try {
951
- rmSync(previousStatePath, { force: true });
952
- } catch {
953
- }
954
- }
955
838
  }
956
839
  observedDomainResourceTypes = /* @__PURE__ */ new Map();
957
840
  const port = pickFreePort();
958
841
  const logPath = ensureLogPath();
959
- const statePath = ensureStatePath();
960
842
  const scriptPath = resolveScriptPath();
961
843
  const debugMode = Boolean(options.debugMode);
962
844
  const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
@@ -967,8 +849,7 @@ var startProxyMeter = (options = {}) => {
967
849
  PROXY_METER_UPSTREAM: upstreamUrl,
968
850
  PROXY_METER_FLUSH_MS: String(FLUSH_INTERVAL_MS),
969
851
  PROXY_METER_DEBUG: debugMode ? "1" : "0",
970
- PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents),
971
- PROXY_METER_STATE: statePath
852
+ PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
972
853
  };
973
854
  const child = spawn(process.execPath, [scriptPath], {
974
855
  env,
@@ -983,27 +864,8 @@ var startProxyMeter = (options = {}) => {
983
864
  proc: child,
984
865
  port,
985
866
  logPath,
986
- statePath,
987
867
  startedAt: Date.now()
988
868
  };
989
- const readiness = waitForProxyMeterReady({ port, statePath });
990
- if (!readiness.ok) {
991
- logger2.warn(
992
- `[proxy-meter] startup failed reason=${readiness.reason} latency_ms=${readiness.latencyMs} exit_code=${readiness.childExitCode ?? "unknown"}`
993
- );
994
- try {
995
- child.kill("SIGTERM");
996
- } catch {
997
- }
998
- runtime = null;
999
- try {
1000
- rmSync(statePath, { force: true });
1001
- } catch {
1002
- }
1003
- throw new Error(`proxy-meter startup failed: ${readiness.reason}`);
1004
- }
1005
- runtime.startedAt = Date.now() - readiness.latencyMs;
1006
- logger2.info(`[proxy-meter] ready latency_ms=${readiness.latencyMs} stable_window_ms=${PROXY_METER_STABLE_WINDOW_MS}`);
1007
869
  registerCleanup();
1008
870
  return { server: `http://127.0.0.1:${port}` };
1009
871
  };
@@ -1015,15 +877,9 @@ var recordProxyMeterResourceType = (requestUrl, resourceType) => {
1015
877
  };
1016
878
  var stopProxyMeter = async () => {
1017
879
  if (!runtime) return null;
1018
- const { proc, logPath, statePath } = runtime;
880
+ const { proc, logPath } = runtime;
1019
881
  if (!proc || proc.killed) {
1020
882
  runtime = null;
1021
- if (statePath) {
1022
- try {
1023
- rmSync(statePath, { force: true });
1024
- } catch {
1025
- }
1026
- }
1027
883
  return logPath || null;
1028
884
  }
1029
885
  await new Promise((resolve) => {
@@ -1045,12 +901,6 @@ var stopProxyMeter = async () => {
1045
901
  }
1046
902
  });
1047
903
  runtime = null;
1048
- if (statePath) {
1049
- try {
1050
- rmSync(statePath, { force: true });
1051
- } catch {
1052
- }
1053
- }
1054
904
  return logPath || null;
1055
905
  };
1056
906
  var getProxyMeterSnapshot = async (options = {}) => {