arn-browser 0.1.20 → 0.1.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arn-browser",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "A lightweight, browser autmation helper.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -365,10 +365,10 @@ export async function startProxyServer({
365
365
  for (const [key, val] of Object.entries(stats)) {
366
366
  formatted[key] = {
367
367
  req: val.request,
368
- srcTx: formatBytes(val.srcTx),
369
- srcRx: formatBytes(val.srcRx),
370
- trgTx: formatBytes(val.trgTx),
371
- trgRx: formatBytes(val.trgRx),
368
+ sTx: formatBytes(val.srcTx),
369
+ sRx: formatBytes(val.srcRx),
370
+ tTx: formatBytes(val.trgTx),
371
+ tRx: formatBytes(val.trgRx),
372
372
  };
373
373
  }
374
374
  return formatted;
@@ -382,10 +382,10 @@ export async function startProxyServer({
382
382
  .reduce((acc, [host, hostData]) => {
383
383
  acc[host] = {
384
384
  req: hostData.req,
385
- srcTx: formatBytes(hostData.srcTx),
386
- srcRx: formatBytes(hostData.srcRx),
387
- trgTx: formatBytes(hostData.trgTx),
388
- trgRx: formatBytes(hostData.trgRx),
385
+ sTx: formatBytes(hostData.srcTx),
386
+ sRx: formatBytes(hostData.srcRx),
387
+ tTx: formatBytes(hostData.trgTx),
388
+ tRx: formatBytes(hostData.trgRx),
389
389
  };
390
390
  return acc;
391
391
  }, {});
@@ -421,11 +421,19 @@ export async function startProxyServer({
421
421
  isServerRunning: () => serverRunning,
422
422
 
423
423
  closeServer: async () => {
424
- // Close the server — triggers connectionClosed events which accumulate byte stats
424
+ // Close the server — triggers socket destroys
425
425
  await server.close(true);
426
426
  serverRunning = false;
427
427
 
428
- // Log stats AFTER close so all connectionClosed events have fired
428
+ // Wait up to 2000ms (2 seconds) for all async 'connectionClosed' events to fire
429
+ // When sockets are destroyed, their 'close' events happen asynchronously
430
+ let maxWait = 200; // 200 * 10ms = 2000ms
431
+ while (Object.keys(connectionMap).length > 0 && maxWait > 0) {
432
+ await new Promise((resolve) => setTimeout(resolve, 10));
433
+ maxWait--;
434
+ }
435
+
436
+ // Log stats AFTER close so all connectionClosed events have accumulated bytes
429
437
  if (proxy_stats) {
430
438
  console.log("░░ Proxy Stats:", getProxyStatsFormatted());
431
439
  }