@fanboynz/network-scanner 2.0.11 → 2.0.13

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.
@@ -180,7 +180,7 @@ async function validatePageForInjection(page, currentUrl, forceDebug) {
180
180
  try {
181
181
  if (page.isClosed()) return false;
182
182
  await Promise.race([
183
- page.evaluate(() => document.readyState),
183
+ page.evaluate(() => document.readyState || 'loading'),
184
184
  new Promise((_, reject) => setTimeout(() => reject(new Error('Page unresponsive')), 3000))
185
185
  ]);
186
186
  return true;
@@ -268,6 +268,12 @@ async function applyUserAgentSpoofing(page, siteConfig, forceDebug, currentUrl)
268
268
 
269
269
  if (forceDebug) console.log(`[debug] User agent spoofing: ${siteConfig.userAgent}`);
270
270
 
271
+ // Browser connection check
272
+ try {
273
+ if (!page.browser().isConnected() || page.isClosed()) return;
274
+ if (page.browser().process()?.killed) return;
275
+ } catch { return; }
276
+
271
277
  // Validate page state before injection
272
278
  if (!(await validatePageForInjection(page, currentUrl, forceDebug))) return;
273
279
 
@@ -682,7 +688,11 @@ async function applyUserAgentSpoofing(page, siteConfig, forceDebug, currentUrl)
682
688
  } catch (stealthErr) {
683
689
  if (stealthErr.message.includes('Session closed') ||
684
690
  stealthErr.message.includes('addScriptToEvaluateOnNewDocument timed out') ||
685
- stealthErr.message.includes('Target closed')) {
691
+ stealthErr.message.includes('Target closed') ||
692
+ stealthErr.message.includes('Protocol error') || stealthErr.name === 'ProtocolError' ||
693
+ stealthErr.message.includes('detached Frame') || stealthErr.message.includes('Navigating frame was detached') ||
694
+ stealthErr.message.includes('Cannot find context') ||
695
+ stealthErr.message.includes('Execution context was destroyed')) {
686
696
  if (forceDebug) console.log(`[debug] Page closed during stealth injection: ${currentUrl}`);
687
697
  return;
688
698
  }
@@ -698,24 +708,19 @@ async function applyBraveSpoofing(page, siteConfig, forceDebug, currentUrl) {
698
708
  if (!siteConfig.isBrave) return;
699
709
 
700
710
  if (forceDebug) console.log(`[debug] Brave spoofing enabled for ${currentUrl}`);
711
+
712
+ // Browser connection check
713
+ try {
714
+ if (!page.browser().isConnected() || page.isClosed()) return;
715
+ if (page.browser().process()?.killed) return;
716
+ } catch { return; }
701
717
 
702
718
  // Validate page state before injection
703
719
  if (!(await validatePageForInjection(page, currentUrl, forceDebug))) return;
704
720
 
705
721
  try {
706
722
  await page.evaluateOnNewDocument((debugEnabled) => {
707
- // ... existing Brave spoofing code ...
708
- }, forceDebug);
709
- } catch (braveErr) {
710
- if (braveErr.message.includes('Session closed') ||
711
- braveErr.message.includes('addScriptToEvaluateOnNewDocument timed out') ||
712
- braveErr.message.includes('Target closed')) {
713
- if (forceDebug) console.log(`[debug] Page closed during Brave injection: ${currentUrl}`);
714
- return;
715
- }
716
- if (forceDebug) console.log(`[debug] Brave spoofing failed: ${currentUrl} - ${braveErr.message}`);
717
- }
718
- try {
723
+ try {
719
724
  Object.defineProperty(navigator, 'brave', {
720
725
  get: () => ({
721
726
  isBrave: () => Promise.resolve(true),
@@ -736,6 +741,20 @@ async function applyBraveSpoofing(page, siteConfig, forceDebug, currentUrl) {
736
741
  } catch (err) {
737
742
  if (debugEnabled) console.log(`[fingerprint] Brave spoofing error: ${err.message}`);
738
743
  }
744
+ }, forceDebug);
745
+ } catch (braveErr) {
746
+ if (braveErr.message.includes('Session closed') ||
747
+ braveErr.message.includes('addScriptToEvaluateOnNewDocument timed out') ||
748
+ braveErr.message.includes('Target closed') ||
749
+ braveErr.message.includes('Protocol error') || braveErr.name === 'ProtocolError' ||
750
+ braveErr.message.includes('detached Frame') || braveErr.message.includes('Navigating frame was detached') ||
751
+ braveErr.message.includes('Cannot find context') ||
752
+ braveErr.message.includes('Execution context was destroyed')) {
753
+ if (forceDebug) console.log(`[debug] Page closed during Brave injection: ${currentUrl}`);
754
+ return;
755
+ }
756
+ if (forceDebug) console.log(`[debug] Brave spoofing failed: ${currentUrl} - ${braveErr.message}`);
757
+ }
739
758
  }
740
759
 
741
760
  /**
@@ -747,6 +766,12 @@ async function applyFingerprintProtection(page, siteConfig, forceDebug, currentU
747
766
 
748
767
  if (forceDebug) console.log(`[debug] Fingerprint protection enabled for ${currentUrl}`);
749
768
 
769
+ // Browser connection check
770
+ try {
771
+ if (!page.browser().isConnected() || page.isClosed()) return;
772
+ if (page.browser().process()?.killed) return;
773
+ } catch { return; }
774
+
750
775
  // Validate page state before injection
751
776
  if (!(await validatePageForInjection(page, currentUrl, forceDebug))) return;
752
777
 
@@ -841,7 +866,11 @@ async function applyFingerprintProtection(page, siteConfig, forceDebug, currentU
841
866
  } catch (err) {
842
867
  if (err.message.includes('Session closed') ||
843
868
  err.message.includes('addScriptToEvaluateOnNewDocument timed out') ||
844
- err.message.includes('Target closed')) {
869
+ err.message.includes('Target closed') ||
870
+ err.message.includes('Protocol error') || err.name === 'ProtocolError' ||
871
+ err.message.includes('detached Frame') || err.message.includes('Navigating frame was detached') ||
872
+ err.message.includes('Cannot find context') ||
873
+ err.message.includes('Execution context was destroyed')) {
845
874
  if (forceDebug) console.log(`[debug] Page closed during fingerprint injection: ${currentUrl}`);
846
875
  return;
847
876
  }
package/nwss.js CHANGED
@@ -1,4 +1,4 @@
1
- // === Network scanner script (nwss.js) v2.0.11 ===
1
+ // === Network scanner script (nwss.js) v2.0.13 ===
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
@@ -130,7 +130,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
130
130
  const { monitorBrowserHealth, isBrowserHealthy, isQuicklyResponsive, performGroupWindowCleanup, performRealtimeWindowCleanup, trackPageForRealtime, updatePageUsage, cleanupPageBeforeReload } = require('./lib/browserhealth');
131
131
 
132
132
  // --- Script Configuration & Constants ---
133
- const VERSION = '2.0.11'; // Script version
133
+ const VERSION = '2.0.13'; // Script version
134
134
 
135
135
  // get startTime
136
136
  const startTime = Date.now();
@@ -2025,9 +2025,9 @@ function setupFrameHandling(page, forceDebug) {
2025
2025
  chrome: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
2026
2026
  chrome_mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
2027
2027
  chrome_linux: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
2028
- firefox: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/142.0",
2029
- firefox_mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:142.0) Gecko/20100101 Firefox/142.0",
2030
- firefox_linux: "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/142.0",
2028
+ firefox: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:142.0) Gecko/20100101 Firefox/143.0",
2029
+ firefox_mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:142.0) Gecko/20100101 Firefox/143.0",
2030
+ firefox_linux: "Mozilla/5.0 (X11; Linux x86_64; rv:142.0) Gecko/20100101 Firefox/143.0",
2031
2031
  safari: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.6 Safari/605.1.15"
2032
2032
  };
2033
2033
  curlUserAgent = userAgents[siteConfig.userAgent.toLowerCase()] || '';
@@ -3278,11 +3278,20 @@ function setupFrameHandling(page, forceDebug) {
3278
3278
 
3279
3279
  if (forceDebug) console.log(formatLogMessage('debug', `Standard reload #${i} completed for ${currentUrl}`));
3280
3280
  } catch (standardReloadErr) {
3281
- // Only warn for non-timeout errors
3282
- if (!standardReloadErr.message.includes('timeout')) {
3281
+ // Categorize errors into expected vs unexpected
3282
+ const isExpectedError = standardReloadErr.message.includes('timeout') ||
3283
+ standardReloadErr.message.includes('detached Frame') ||
3284
+ standardReloadErr.message.includes('Attempted to use detached') ||
3285
+ standardReloadErr.message.includes('Navigating frame was detached') ||
3286
+ standardReloadErr.message.includes('document invalid') ||
3287
+ standardReloadErr.message.includes('Page document invalid');
3288
+
3289
+ if (!isExpectedError) {
3290
+ // Only warn for truly unexpected errors
3283
3291
  console.warn(messageColors.warn(`[standard reload #${i} failed] ${currentUrl}: ${standardReloadErr.message}`));
3284
3292
  } else if (forceDebug) {
3285
- console.log(formatLogMessage('debug', `Reload #${i} timed out for ${currentUrl}, continuing anyway`));
3293
+ // Expected errors only shown in debug mode
3294
+ console.log(formatLogMessage('debug', `[reload #${i}] Expected error for ${currentUrl}: ${standardReloadErr.message}`));
3286
3295
  }
3287
3296
 
3288
3297
  // Check if this is a persistent failure that should skip remaining reloads
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanboynz/network-scanner",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
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": {