@skrillex1224/playwright-toolkit 2.1.200 → 2.1.202

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
@@ -599,31 +599,9 @@ var logger2 = createInternalLogger("ProxyMeter");
599
599
  var MAX_TOP_DOMAINS = 20;
600
600
  var FLUSH_INTERVAL_MS = 2e3;
601
601
  var DEFAULT_DEBUG_MAX_EVENTS = 400;
602
- var PROXY_METER_READY_TIMEOUT_MS = 5e3;
603
- var PROXY_METER_STABLE_WINDOW_MS = 2e3;
604
- var PROXY_METER_POLL_INTERVAL_MS = 100;
605
- var PROXY_METER_CONNECT_TIMEOUT_MS = 500;
606
602
  var runtime = null;
607
603
  var cleanupInstalled = false;
608
604
  var observedDomainResourceTypes = /* @__PURE__ */ new Map();
609
- var sleepSignal = new Int32Array(new SharedArrayBuffer(4));
610
- var portProbeScript = [
611
- 'const net = require("net");',
612
- "const port = Number(process.argv[1] || 0);",
613
- "const timeout = Number(process.argv[2] || 200);",
614
- "if (!Number.isFinite(port) || port <= 0) process.exit(2);",
615
- 'const socket = net.connect({ host: "127.0.0.1", port });',
616
- "let done = false;",
617
- "const finish = (code) => {",
618
- " if (done) return;",
619
- " done = true;",
620
- " try { socket.destroy(); } catch {}",
621
- " process.exit(code);",
622
- "};",
623
- 'socket.once("connect", () => finish(0));',
624
- 'socket.once("error", () => finish(1));',
625
- "socket.setTimeout(timeout, () => finish(1));"
626
- ].join("");
627
605
  var toSafeInt = (value) => {
628
606
  const num = Number(value);
629
607
  if (!Number.isFinite(num) || num <= 0) return 0;
@@ -722,17 +700,6 @@ var ensureLogPath = () => {
722
700
  const label = runId ? `proxy-meter-${runId}-${suffix}.json` : `proxy-meter-${process.pid}-${suffix}.json`;
723
701
  return import_path.default.join(baseDir, label);
724
702
  };
725
- var ensureStatePath = () => {
726
- const baseDir = resolveLogDir();
727
- if (!(0, import_fs.existsSync)(baseDir)) {
728
- try {
729
- (0, import_fs.mkdirSync)(baseDir, { recursive: true });
730
- } catch {
731
- }
732
- }
733
- const suffix = `${Date.now()}-${Math.floor(Math.random() * 1e6)}`;
734
- return import_path.default.join(baseDir, `proxy-meter-state-${process.pid}-${suffix}.json`);
735
- };
736
703
  var readSnapshot = (logPath) => {
737
704
  if (!logPath || !(0, import_fs.existsSync)(logPath)) return null;
738
705
  try {
@@ -743,83 +710,6 @@ var readSnapshot = (logPath) => {
743
710
  return null;
744
711
  }
745
712
  };
746
- var readState = (statePath) => {
747
- if (!statePath || !(0, import_fs.existsSync)(statePath)) return null;
748
- try {
749
- const raw = (0, import_fs.readFileSync)(statePath, "utf8");
750
- if (!raw) return null;
751
- return JSON.parse(raw);
752
- } catch {
753
- return null;
754
- }
755
- };
756
- var sleepSync = (durationMs) => {
757
- const timeout = Math.max(0, Number(durationMs) || 0);
758
- if (timeout <= 0) return;
759
- Atomics.wait(sleepSignal, 0, 0, timeout);
760
- };
761
- var canConnectToPort = (port, timeoutMs = PROXY_METER_CONNECT_TIMEOUT_MS) => {
762
- const result = (0, import_child_process.spawnSync)(process.execPath, ["-e", portProbeScript, String(port), String(timeoutMs)], {
763
- stdio: "ignore",
764
- timeout: timeoutMs + 100
765
- });
766
- return result.status === 0;
767
- };
768
- var waitForProxyMeterReady = ({ port, statePath }) => {
769
- const startedAt = Date.now();
770
- const listenDeadline = startedAt + PROXY_METER_READY_TIMEOUT_MS;
771
- let firstConnectAt = 0;
772
- while (Date.now() < listenDeadline) {
773
- const lifecycle = readState(statePath);
774
- if (lifecycle?.status === "exited") {
775
- return {
776
- ok: false,
777
- reason: "child_exit_before_ready",
778
- childExitCode: lifecycle.exitCode,
779
- latencyMs: Date.now() - startedAt
780
- };
781
- }
782
- if (canConnectToPort(port)) {
783
- firstConnectAt = Date.now();
784
- break;
785
- }
786
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
787
- }
788
- if (!firstConnectAt) {
789
- return {
790
- ok: false,
791
- reason: "listen_timeout",
792
- childExitCode: readState(statePath)?.exitCode ?? null,
793
- latencyMs: Date.now() - startedAt
794
- };
795
- }
796
- const stableDeadline = firstConnectAt + PROXY_METER_STABLE_WINDOW_MS;
797
- while (Date.now() < stableDeadline) {
798
- const lifecycle = readState(statePath);
799
- if (lifecycle?.status === "exited") {
800
- return {
801
- ok: false,
802
- reason: "child_exit_before_ready",
803
- childExitCode: lifecycle.exitCode,
804
- latencyMs: Date.now() - startedAt
805
- };
806
- }
807
- canConnectToPort(port);
808
- sleepSync(PROXY_METER_POLL_INTERVAL_MS);
809
- }
810
- if (!canConnectToPort(port)) {
811
- return {
812
- ok: false,
813
- reason: "stabilize_timeout",
814
- childExitCode: readState(statePath)?.exitCode ?? null,
815
- latencyMs: Date.now() - startedAt
816
- };
817
- }
818
- return {
819
- ok: true,
820
- latencyMs: Date.now() - startedAt
821
- };
822
- };
823
713
  var normalizeDomainRows = (hosts) => {
824
714
  const rows = [];
825
715
  let requestCount = 0;
@@ -968,23 +858,15 @@ var startProxyMeter = (options = {}) => {
968
858
  const upstreamUrl = String(options.proxyUrl || "").trim();
969
859
  if (!upstreamUrl) return null;
970
860
  if (runtime && runtime.proc) {
971
- const previousStatePath = runtime.statePath;
972
861
  try {
973
862
  runtime.proc.kill("SIGTERM");
974
863
  } catch {
975
864
  }
976
865
  runtime = null;
977
- if (previousStatePath) {
978
- try {
979
- (0, import_fs.rmSync)(previousStatePath, { force: true });
980
- } catch {
981
- }
982
- }
983
866
  }
984
867
  observedDomainResourceTypes = /* @__PURE__ */ new Map();
985
868
  const port = pickFreePort();
986
869
  const logPath = ensureLogPath();
987
- const statePath = ensureStatePath();
988
870
  const scriptPath = resolveScriptPath();
989
871
  const debugMode = Boolean(options.debugMode);
990
872
  const debugMaxEvents = Math.max(10, toSafeInt(options.debugMaxEvents) || DEFAULT_DEBUG_MAX_EVENTS);
@@ -995,8 +877,7 @@ var startProxyMeter = (options = {}) => {
995
877
  PROXY_METER_UPSTREAM: upstreamUrl,
996
878
  PROXY_METER_FLUSH_MS: String(FLUSH_INTERVAL_MS),
997
879
  PROXY_METER_DEBUG: debugMode ? "1" : "0",
998
- PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents),
999
- PROXY_METER_STATE: statePath
880
+ PROXY_METER_DEBUG_MAX_EVENTS: String(debugMaxEvents)
1000
881
  };
1001
882
  const child = (0, import_child_process.spawn)(process.execPath, [scriptPath], {
1002
883
  env,
@@ -1011,27 +892,8 @@ var startProxyMeter = (options = {}) => {
1011
892
  proc: child,
1012
893
  port,
1013
894
  logPath,
1014
- statePath,
1015
895
  startedAt: Date.now()
1016
896
  };
1017
- const readiness = waitForProxyMeterReady({ port, statePath });
1018
- if (!readiness.ok) {
1019
- logger2.warn(
1020
- `[proxy-meter] startup failed reason=${readiness.reason} latency_ms=${readiness.latencyMs} exit_code=${readiness.childExitCode ?? "unknown"}`
1021
- );
1022
- try {
1023
- child.kill("SIGTERM");
1024
- } catch {
1025
- }
1026
- runtime = null;
1027
- try {
1028
- (0, import_fs.rmSync)(statePath, { force: true });
1029
- } catch {
1030
- }
1031
- throw new Error(`proxy-meter startup failed: ${readiness.reason}`);
1032
- }
1033
- runtime.startedAt = Date.now() - readiness.latencyMs;
1034
- logger2.info(`[proxy-meter] ready latency_ms=${readiness.latencyMs} stable_window_ms=${PROXY_METER_STABLE_WINDOW_MS}`);
1035
897
  registerCleanup();
1036
898
  return { server: `http://127.0.0.1:${port}` };
1037
899
  };
@@ -1043,15 +905,9 @@ var recordProxyMeterResourceType = (requestUrl, resourceType) => {
1043
905
  };
1044
906
  var stopProxyMeter = async () => {
1045
907
  if (!runtime) return null;
1046
- const { proc, logPath, statePath } = runtime;
908
+ const { proc, logPath } = runtime;
1047
909
  if (!proc || proc.killed) {
1048
910
  runtime = null;
1049
- if (statePath) {
1050
- try {
1051
- (0, import_fs.rmSync)(statePath, { force: true });
1052
- } catch {
1053
- }
1054
- }
1055
911
  return logPath || null;
1056
912
  }
1057
913
  await new Promise((resolve) => {
@@ -1073,12 +929,6 @@ var stopProxyMeter = async () => {
1073
929
  }
1074
930
  });
1075
931
  runtime = null;
1076
- if (statePath) {
1077
- try {
1078
- (0, import_fs.rmSync)(statePath, { force: true });
1079
- } catch {
1080
- }
1081
- }
1082
932
  return logPath || null;
1083
933
  };
1084
934
  var getProxyMeterSnapshot = async (options = {}) => {