arn-browser 0.1.3 → 0.1.4

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.3",
3
+ "version": "0.1.4",
4
4
  "description": "A lightweight, browser autmation helper.",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -114,7 +114,7 @@ export interface ProxyServerController {
114
114
  getProxyStats: () => Record<string, TrafficStats>;
115
115
 
116
116
  /** Returns formatted statistics for hostnames per proxy channel */
117
- getHostStats: () => Record<string, Record<string, number>>;
117
+ getHostStats: () => Record<string, Record<string, TrafficStats>>;
118
118
  }
119
119
 
120
120
  /**
@@ -182,7 +182,7 @@ export async function startProxyServer({
182
182
  }) {
183
183
  // 1. Matchers
184
184
  const matchers = {
185
- noProxy: createHostMatcher([...NO_PROXY_HOSTS, "brave.com", "gvt1.com"]),
185
+ noProxy: createHostMatcher([...NO_PROXY_HOSTS, "%brave.com%", "%gvt1.com%"]),
186
186
  proxy1: createHostMatcher([...PROXY_1_HOSTS, "proxy.multilogin.com", "multilogin.com"]),
187
187
  proxy2: createHostMatcher([...PROXY_2_HOSTS, "proxy.multilogin.com", "multilogin.com"]),
188
188
  };
@@ -284,11 +284,14 @@ export async function startProxyServer({
284
284
  }
285
285
 
286
286
  // Record Stats
287
- connectionMap[connectionId] = { type: proxyType };
287
+ connectionMap[connectionId] = { type: proxyType, hostname: hostname };
288
288
  if (host_stats && hostname) {
289
289
  // Ensure the type exists in map (it should, but safety first)
290
290
  if (!hostStatsMap[proxyType]) hostStatsMap[proxyType] = {};
291
- hostStatsMap[proxyType][hostname] = (hostStatsMap[proxyType][hostname] || 0) + 1;
291
+ if (!hostStatsMap[proxyType][hostname]) {
292
+ hostStatsMap[proxyType][hostname] = { req: 0, Tx: 0, Rx: 0 };
293
+ }
294
+ hostStatsMap[proxyType][hostname].req++;
292
295
  }
293
296
 
294
297
  // Return Decision
@@ -305,13 +308,18 @@ export async function startProxyServer({
305
308
 
306
309
  server.on("connectionClosed", ({ connectionId, stats: connStats }) => {
307
310
  const connectionInfo = connectionMap[connectionId];
308
- if (connectionInfo && proxy_stats) {
309
- const { type } = connectionInfo;
310
- if (stats[type]) {
311
+ if (connectionInfo) {
312
+ const { type, hostname } = connectionInfo;
313
+ if (proxy_stats && stats[type]) {
311
314
  stats[type].request++;
312
315
  stats[type].Tx += connStats.srcTxBytes;
313
316
  stats[type].Rx += connStats.srcRxBytes;
314
317
  }
318
+ // Update host stats with Tx/Rx on connection close
319
+ if (host_stats && hostname && hostStatsMap[type] && hostStatsMap[type][hostname]) {
320
+ hostStatsMap[type][hostname].Tx += connStats.srcTxBytes;
321
+ hostStatsMap[type][hostname].Rx += connStats.srcRxBytes;
322
+ }
315
323
  }
316
324
  delete connectionMap[connectionId];
317
325
  });
@@ -344,9 +352,13 @@ export async function startProxyServer({
344
352
  // Iterate over each proxy category
345
353
  for (const [type, hosts] of Object.entries(hostStatsMap)) {
346
354
  const sortedHosts = Object.entries(hosts)
347
- .sort((a, b) => b[1] - a[1]) // Sort by count descending
348
- .reduce((acc, [host, count]) => {
349
- acc[host] = count;
355
+ .sort((a, b) => b[1].req - a[1].req) // Sort by request count descending
356
+ .reduce((acc, [host, hostData]) => {
357
+ acc[host] = {
358
+ req: hostData.req,
359
+ Tx: formatBytes(hostData.Tx) + " MB",
360
+ Rx: formatBytes(hostData.Rx) + " MB",
361
+ };
350
362
  return acc;
351
363
  }, {});
352
364