@fanboynz/network-scanner 1.0.36 → 1.0.37

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.
@@ -17,7 +17,8 @@ async function checkBrowserHealth(browserInstance, timeout = 5000) {
17
17
  pageCount: 0,
18
18
  error: null,
19
19
  responseTime: 0,
20
- recommendations: []
20
+ recommendations: [],
21
+ criticalError: false
21
22
  };
22
23
 
23
24
  const startTime = Date.now();
@@ -27,6 +28,7 @@ async function checkBrowserHealth(browserInstance, timeout = 5000) {
27
28
  if (!browserInstance || browserInstance.process() === null) {
28
29
  healthResult.error = 'Browser process not running';
29
30
  healthResult.recommendations.push('Create new browser instance');
31
+ healthResult.criticalError = true;
30
32
  return healthResult;
31
33
  }
32
34
 
@@ -71,7 +73,12 @@ async function checkBrowserHealth(browserInstance, timeout = 5000) {
71
73
  try { await testPage.close(); } catch (e) { /* ignore */ }
72
74
  }
73
75
  healthResult.error = `Page creation/navigation failed: ${pageTestError.message}`;
74
- healthResult.recommendations.push('Browser restart recommended');
76
+ if (isCriticalProtocolError(pageTestError)) {
77
+ healthResult.recommendations.push('Browser restart required - critical protocol error');
78
+ healthResult.criticalError = true;
79
+ } else {
80
+ healthResult.recommendations.push('Browser restart recommended');
81
+ }
75
82
  return healthResult;
76
83
  }
77
84
 
@@ -88,10 +95,14 @@ async function checkBrowserHealth(browserInstance, timeout = 5000) {
88
95
  healthResult.responseTime = Date.now() - startTime;
89
96
 
90
97
  // Categorize error types for better recommendations
91
- if (error.message.includes('timeout') || error.message.includes('unresponsive')) {
98
+ if (error.message.includes('Runtime.callFunctionOn timed out') ||
99
+ error.message.includes('Protocol error') ||
100
+ error.message.includes('Target closed')) {
101
+ healthResult.recommendations.push('Browser restart required - critical protocol error');
102
+ healthResult.criticalError = true;
103
+ } else if (error.message.includes('timeout') || error.message.includes('unresponsive')) {
92
104
  healthResult.recommendations.push('Browser restart required - unresponsive');
93
- } else if (error.message.includes('Protocol error') || error.message.includes('Target closed')) {
94
- healthResult.recommendations.push('Browser restart required - protocol error');
105
+ healthResult.criticalError = true;
95
106
  } else {
96
107
  healthResult.recommendations.push('Browser restart recommended - unknown error');
97
108
  }
@@ -152,6 +163,27 @@ async function checkBrowserMemory(browserInstance) {
152
163
  return memoryResult;
153
164
  }
154
165
 
166
+ /**
167
+ * Detects critical protocol errors that require immediate browser restart
168
+ */
169
+ function isCriticalProtocolError(error) {
170
+ if (!error || !error.message) return false;
171
+
172
+ const criticalErrors = [
173
+ 'Runtime.callFunctionOn timed out',
174
+ 'Protocol error',
175
+ 'Target closed',
176
+ 'Session closed',
177
+ 'Connection closed',
178
+ 'Browser has been closed',
179
+ 'Runtime.evaluate timed out'
180
+ ];
181
+
182
+ return criticalErrors.some(criticalError =>
183
+ error.message.includes(criticalError)
184
+ );
185
+ }
186
+
155
187
  /**
156
188
  * Performs comprehensive browser health assessment
157
189
  * @param {import('puppeteer').Browser} browserInstance - Puppeteer browser instance
@@ -196,6 +228,9 @@ async function performHealthAssessment(browserInstance, options = {}) {
196
228
  if (!assessment.browser.healthy) {
197
229
  assessment.overall = 'unhealthy';
198
230
  assessment.needsRestart = true;
231
+ } else if (assessment.browser.criticalError) {
232
+ assessment.overall = 'critical';
233
+ assessment.needsRestart = true;
199
234
  } else if (assessment.recommendations.length > 0) {
200
235
  assessment.overall = 'degraded';
201
236
  assessment.needsRestart = assessment.recommendations.some(rec =>
@@ -252,7 +287,10 @@ async function monitorBrowserHealth(browserInstance, context = {}, options = {})
252
287
  result.assessment = assessment;
253
288
 
254
289
  // Decision logic for restart
255
- if (assessment.needsRestart) {
290
+ if (assessment.browser.criticalError) {
291
+ result.shouldRestart = true;
292
+ result.reason = `Critical protocol error detected - immediate restart required`;
293
+ } else if (assessment.needsRestart) {
256
294
  result.shouldRestart = true;
257
295
  result.reason = `Browser health: ${assessment.overall} - ${assessment.recommendations[0] || 'restart needed'}`;
258
296
  } else if (urlsSinceCleanup >= cleanupInterval) {
@@ -304,5 +342,6 @@ module.exports = {
304
342
  checkBrowserMemory,
305
343
  performHealthAssessment,
306
344
  monitorBrowserHealth,
307
- isBrowserHealthy
345
+ isBrowserHealthy,
346
+ isCriticalProtocolError
308
347
  };
package/nwss.js CHANGED
@@ -1,4 +1,4 @@
1
- // === Network scanner script (nwss.js) v1.0.36 ===
1
+ // === Network scanner script (nwss.js) v1.0.37 ===
2
2
 
3
3
  // puppeteer for browser automation, fs for file system operations, psl for domain parsing.
4
4
  // const pLimit = require('p-limit'); // Will be dynamically imported
@@ -33,7 +33,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
33
33
  const { monitorBrowserHealth, isBrowserHealthy } = require('./lib/browserhealth');
34
34
 
35
35
  // --- Script Configuration & Constants ---
36
- const VERSION = '1.0.36'; // Script version
36
+ const VERSION = '1.0.37'; // Script version
37
37
  const MAX_CONCURRENT_SITES = 5;
38
38
  const RESOURCE_CLEANUP_INTERVAL = 80; // Close browser and restart every N sites to free resources
39
39
 
@@ -936,7 +936,7 @@ function setupFrameHandling(page, forceDebug) {
936
936
  '--disable-image-animation-resync'
937
937
  ],
938
938
  headless: launchHeadless ? 'shell' : false,
939
- protocolTimeout: 500000
939
+ protocolTimeout: 60000 // 60 seconds
940
940
  });
941
941
 
942
942
  // Store the user data directory on the browser object for cleanup
@@ -2091,7 +2091,21 @@ function setupFrameHandling(page, forceDebug) {
2091
2091
  }
2092
2092
 
2093
2093
  } catch (err) {
2094
- // Enhanced error handling with rule preservation for partial matches
2094
+ // Enhanced error handling with rule preservation for partial matches
2095
+ if (err.message.includes('Runtime.callFunctionOn timed out') ||
2096
+ err.message.includes('Protocol error') ||
2097
+ err.message.includes('Target closed') ||
2098
+ err.message.includes('Browser has been closed')) {
2099
+ console.error(formatLogMessage('error', `Critical browser protocol error on ${currentUrl}: ${err.message}`));
2100
+ return {
2101
+ url: currentUrl,
2102
+ rules: [],
2103
+ success: false,
2104
+ needsImmediateRestart: true,
2105
+ error: `Critical protocol error: ${err.message}`
2106
+ };
2107
+ }
2108
+
2095
2109
  if (err.message.includes('Protocol error') ||
2096
2110
  err.message.includes('Target closed') ||
2097
2111
  err.message.includes('Browser process was killed') ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanboynz/network-scanner",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "A Puppeteer-based network scanner for analyzing web traffic, generating adblock filter rules, and identifying third-party requests. Features include fingerprint spoofing, Cloudflare bypass, content analysis with curl/grep, and multiple output formats.",
5
5
  "main": "nwss.js",
6
6
  "scripts": {