@fanboynz/network-scanner 1.0.64 → 1.0.66
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/lib/fingerprint.js +654 -1818
- package/lib/interaction.js +89 -21
- package/nwss.js +2 -2
- package/package.json +1 -1
package/lib/interaction.js
CHANGED
|
@@ -164,6 +164,38 @@ const PROBABILITIES = {
|
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
|
|
167
|
+
// === PERFORMANCE OPTIMIZATION VARIABLES ===
|
|
168
|
+
// Viewport caching to reduce repeated page.viewport() calls
|
|
169
|
+
let cachedViewport = null;
|
|
170
|
+
let lastViewportCheck = 0;
|
|
171
|
+
const VIEWPORT_CACHE_DURATION = 30000; // 30 seconds
|
|
172
|
+
let interactionMemoryCleanupCounter = 0;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Gets viewport dimensions with caching for performance
|
|
176
|
+
* Caches viewport for 30 seconds to avoid repeated queries
|
|
177
|
+
*
|
|
178
|
+
* @param {import('puppeteer').Page} page - Puppeteer page object
|
|
179
|
+
* @returns {Promise<object>} Viewport dimensions {width, height}
|
|
180
|
+
*/
|
|
181
|
+
async function getCachedViewport(page) {
|
|
182
|
+
const now = Date.now();
|
|
183
|
+
|
|
184
|
+
// Return cached viewport if still valid
|
|
185
|
+
if (cachedViewport && (now - lastViewportCheck) < VIEWPORT_CACHE_DURATION) {
|
|
186
|
+
return cachedViewport;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
cachedViewport = await page.viewport();
|
|
191
|
+
lastViewportCheck = now;
|
|
192
|
+
return cachedViewport || { width: DEFAULT_VIEWPORT.WIDTH, height: DEFAULT_VIEWPORT.HEIGHT };
|
|
193
|
+
} catch (viewportErr) {
|
|
194
|
+
// Return defaults if viewport query fails
|
|
195
|
+
return { width: DEFAULT_VIEWPORT.WIDTH, height: DEFAULT_VIEWPORT.HEIGHT };
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
167
199
|
/**
|
|
168
200
|
* Generates random coordinates within viewport bounds with intelligent placement
|
|
169
201
|
*
|
|
@@ -481,8 +513,8 @@ async function interactWithElements(page, options = {}) {
|
|
|
481
513
|
return;
|
|
482
514
|
}
|
|
483
515
|
|
|
484
|
-
//
|
|
485
|
-
await page.waitForSelector('body', { timeout:
|
|
516
|
+
// Very short timeout since page should already be loaded
|
|
517
|
+
await page.waitForSelector('body', { timeout: 1000 });
|
|
486
518
|
} catch (bodyWaitErr) {
|
|
487
519
|
if (options.forceDebug) {
|
|
488
520
|
console.log(`[interaction] Page not ready for element interaction: ${bodyWaitErr.message}`);
|
|
@@ -490,10 +522,10 @@ async function interactWithElements(page, options = {}) {
|
|
|
490
522
|
return;
|
|
491
523
|
}
|
|
492
524
|
|
|
493
|
-
//
|
|
494
|
-
const viewport = await page
|
|
495
|
-
const maxX = viewport
|
|
496
|
-
const maxY = viewport
|
|
525
|
+
// Use cached viewport for better performance
|
|
526
|
+
const viewport = await getCachedViewport(page);
|
|
527
|
+
const maxX = viewport.width;
|
|
528
|
+
const maxY = viewport.height;
|
|
497
529
|
|
|
498
530
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
499
531
|
try {
|
|
@@ -638,6 +670,33 @@ async function simulateTyping(page, text, options = {}) {
|
|
|
638
670
|
}
|
|
639
671
|
}
|
|
640
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Cleans up interaction-related memory and cached data
|
|
675
|
+
* Should be called periodically in long-running sessions
|
|
676
|
+
*
|
|
677
|
+
* @param {boolean} force - Force cleanup regardless of timing
|
|
678
|
+
*/
|
|
679
|
+
function cleanupInteractionMemory(force = false) {
|
|
680
|
+
interactionMemoryCleanupCounter++;
|
|
681
|
+
|
|
682
|
+
// Only cleanup every 10 calls unless forced
|
|
683
|
+
if (!force && interactionMemoryCleanupCounter % 10 !== 0) {
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Clear cached viewport if it's older than cache duration
|
|
688
|
+
const now = Date.now();
|
|
689
|
+
if (cachedViewport && (now - lastViewportCheck) > VIEWPORT_CACHE_DURATION) {
|
|
690
|
+
cachedViewport = null;
|
|
691
|
+
lastViewportCheck = 0;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// Force garbage collection if available (helps with memory pressure)
|
|
695
|
+
if (global.gc) {
|
|
696
|
+
global.gc();
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
641
700
|
/**
|
|
642
701
|
* Performs comprehensive page interaction simulation - MAIN ENTRY POINT
|
|
643
702
|
*
|
|
@@ -711,10 +770,9 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
711
770
|
try {
|
|
712
771
|
// Validate page state before starting interaction
|
|
713
772
|
try {
|
|
714
|
-
//
|
|
715
|
-
|
|
716
|
-
const
|
|
717
|
-
const bodyTimeout = Math.min(Math.max(siteTimeout / 6, 3000), 8000); // 3-8 seconds
|
|
773
|
+
// Optimized timeout calculation - shorter for better performance
|
|
774
|
+
const siteTimeout = options.siteTimeout || 20000; // Reduced default
|
|
775
|
+
const bodyTimeout = Math.min(Math.max(siteTimeout / 8, 2000), 5000); // 2-5 seconds (reduced)
|
|
718
776
|
|
|
719
777
|
await page.waitForSelector('body', { timeout: bodyTimeout });
|
|
720
778
|
|
|
@@ -735,9 +793,9 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
735
793
|
}
|
|
736
794
|
} catch (bodyCheckErr) {
|
|
737
795
|
if (forceDebug) {
|
|
738
|
-
console.log(`[interaction] Page not ready for interaction on ${currentUrl} (waited ${
|
|
796
|
+
console.log(`[interaction] Page not ready for interaction on ${currentUrl} (waited ${Math.min(Math.max((options.siteTimeout || 20000) / 8, 2000), 5000)}ms): ${bodyCheckErr.message}`);
|
|
739
797
|
// For very slow sites, we might want to try a minimal interaction anyway
|
|
740
|
-
if (
|
|
798
|
+
if (Math.min(Math.max((options.siteTimeout || 20000) / 8, 2000), 5000) >= 4000 && !bodyCheckErr.message.includes('closed')) {
|
|
741
799
|
console.log(`[interaction] Attempting minimal mouse movement only for slow-loading ${currentUrl}`);
|
|
742
800
|
return await performMinimalInteraction(page, currentUrl, options, forceDebug);
|
|
743
801
|
}
|
|
@@ -745,10 +803,10 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
745
803
|
return;
|
|
746
804
|
}
|
|
747
805
|
|
|
748
|
-
//
|
|
749
|
-
const viewport = await page
|
|
750
|
-
const maxX = viewport
|
|
751
|
-
const maxY = viewport
|
|
806
|
+
// Use cached viewport for better performance
|
|
807
|
+
const viewport = await getCachedViewport(page);
|
|
808
|
+
const maxX = viewport.width;
|
|
809
|
+
const maxY = viewport.height;
|
|
752
810
|
|
|
753
811
|
if (forceDebug) {
|
|
754
812
|
console.log(`[interaction] Starting enhanced interaction simulation for ${new URL(currentUrl).hostname} (${intensity} intensity)`);
|
|
@@ -760,7 +818,13 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
760
818
|
|
|
761
819
|
// Start with random position
|
|
762
820
|
let currentPos = generateRandomCoordinates(maxX, maxY, { preferEdges: true });
|
|
821
|
+
|
|
822
|
+
// Batch mouse move operations for better performance
|
|
823
|
+
try {
|
|
763
824
|
await page.mouse.move(currentPos.x, currentPos.y);
|
|
825
|
+
} catch (mouseMoveErr) {
|
|
826
|
+
return; // Exit gracefully if mouse operations fail
|
|
827
|
+
}
|
|
764
828
|
|
|
765
829
|
const startTime = Date.now();
|
|
766
830
|
const totalDuration = duration * settings.pauseMultiplier;
|
|
@@ -812,6 +876,9 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
812
876
|
});
|
|
813
877
|
}
|
|
814
878
|
|
|
879
|
+
// Periodic memory cleanup during interaction
|
|
880
|
+
cleanupInteractionMemory();
|
|
881
|
+
|
|
815
882
|
// Final hover position
|
|
816
883
|
const finalPos = generateRandomCoordinates(maxX, maxY);
|
|
817
884
|
await humanLikeMouseMove(page, currentPos.x, currentPos.y, finalPos.x, finalPos.y);
|
|
@@ -847,9 +914,9 @@ async function performMinimalInteraction(page, currentUrl, options = {}, forceDe
|
|
|
847
914
|
try {
|
|
848
915
|
if (page.isClosed()) return;
|
|
849
916
|
|
|
850
|
-
const viewport = await page
|
|
851
|
-
const maxX = viewport
|
|
852
|
-
const maxY = viewport
|
|
917
|
+
const viewport = await getCachedViewport(page);
|
|
918
|
+
const maxX = viewport.width;
|
|
919
|
+
const maxY = viewport.height;
|
|
853
920
|
|
|
854
921
|
if (forceDebug) {
|
|
855
922
|
console.log(`[interaction] Performing minimal interaction for slow page: ${new URL(currentUrl).hostname}`);
|
|
@@ -860,7 +927,7 @@ async function performMinimalInteraction(page, currentUrl, options = {}, forceDe
|
|
|
860
927
|
const endPos = generateRandomCoordinates(maxX, maxY);
|
|
861
928
|
|
|
862
929
|
await page.mouse.move(startPos.x, startPos.y);
|
|
863
|
-
await fastTimeout(
|
|
930
|
+
await fastTimeout(200);
|
|
864
931
|
await humanLikeMouseMove(page, startPos.x, startPos.y, endPos.x, endPos.y);
|
|
865
932
|
|
|
866
933
|
} catch (minimalErr) {
|
|
@@ -1016,7 +1083,8 @@ module.exports = {
|
|
|
1016
1083
|
// Main interaction functions
|
|
1017
1084
|
performPageInteraction,
|
|
1018
1085
|
createInteractionConfig,
|
|
1019
|
-
|
|
1086
|
+
getCachedViewport,
|
|
1087
|
+
cleanupInteractionMemory,
|
|
1020
1088
|
// Component functions for custom implementations
|
|
1021
1089
|
humanLikeMouseMove,
|
|
1022
1090
|
simulateScrolling,
|
package/nwss.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// === Network scanner script (nwss.js) v1.0.
|
|
1
|
+
// === Network scanner script (nwss.js) v1.0.66 ===
|
|
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
|
|
@@ -85,7 +85,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
|
|
|
85
85
|
const { monitorBrowserHealth, isBrowserHealthy } = require('./lib/browserhealth');
|
|
86
86
|
|
|
87
87
|
// --- Script Configuration & Constants ---
|
|
88
|
-
const VERSION = '1.0.
|
|
88
|
+
const VERSION = '1.0.66'; // Script version
|
|
89
89
|
|
|
90
90
|
// get startTime
|
|
91
91
|
const startTime = Date.now();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fanboynz/network-scanner",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.66",
|
|
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": {
|