@fanboynz/network-scanner 1.0.62 → 1.0.63
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/interaction.js +101 -1
- package/nwss.js +2 -2
- package/package.json +1 -1
package/lib/interaction.js
CHANGED
|
@@ -471,6 +471,25 @@ async function interactWithElements(page, options = {}) {
|
|
|
471
471
|
} = options;
|
|
472
472
|
|
|
473
473
|
try {
|
|
474
|
+
// Ensure page is in valid state for element interaction
|
|
475
|
+
try {
|
|
476
|
+
// Check if page is closed before attempting interaction
|
|
477
|
+
if (page.isClosed()) {
|
|
478
|
+
if (options.forceDebug) {
|
|
479
|
+
console.log(`[interaction] Page is closed, skipping element interaction`);
|
|
480
|
+
}
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// Shorter timeout for element interaction since body should already exist
|
|
485
|
+
await page.waitForSelector('body', { timeout: 2000 });
|
|
486
|
+
} catch (bodyWaitErr) {
|
|
487
|
+
if (options.forceDebug) {
|
|
488
|
+
console.log(`[interaction] Page not ready for element interaction: ${bodyWaitErr.message}`);
|
|
489
|
+
}
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
474
493
|
// Get viewport dimensions for coordinate bounds
|
|
475
494
|
const viewport = await page.viewport();
|
|
476
495
|
const maxX = viewport ? viewport.width : DEFAULT_VIEWPORT.WIDTH;
|
|
@@ -589,6 +608,13 @@ async function simulateTyping(page, text, options = {}) {
|
|
|
589
608
|
} = options;
|
|
590
609
|
|
|
591
610
|
try {
|
|
611
|
+
// Ensure page is ready for typing
|
|
612
|
+
try {
|
|
613
|
+
await page.waitForSelector('body', { timeout: 1000 });
|
|
614
|
+
} catch (bodyWaitErr) {
|
|
615
|
+
return; // Silently skip typing if page not ready
|
|
616
|
+
}
|
|
617
|
+
|
|
592
618
|
for (let i = 0; i < text.length; i++) {
|
|
593
619
|
const char = text[i];
|
|
594
620
|
|
|
@@ -683,6 +709,42 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
683
709
|
} = options;
|
|
684
710
|
|
|
685
711
|
try {
|
|
712
|
+
// Validate page state before starting interaction
|
|
713
|
+
try {
|
|
714
|
+
// Use site-specific timeout based on configuration
|
|
715
|
+
// Sites with longer configured timeouts get more time for body detection
|
|
716
|
+
const siteTimeout = options.siteTimeout || 30000; // From site config
|
|
717
|
+
const bodyTimeout = Math.min(Math.max(siteTimeout / 6, 3000), 8000); // 3-8 seconds
|
|
718
|
+
|
|
719
|
+
await page.waitForSelector('body', { timeout: bodyTimeout });
|
|
720
|
+
|
|
721
|
+
// Additional check: ensure page is not closed/crashed
|
|
722
|
+
if (page.isClosed()) {
|
|
723
|
+
if (forceDebug) {
|
|
724
|
+
console.log(`[interaction] Page is closed for ${currentUrl}, skipping interaction`);
|
|
725
|
+
}
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
const bodyExists = await page.$('body');
|
|
730
|
+
if (!bodyExists) {
|
|
731
|
+
if (forceDebug) {
|
|
732
|
+
console.log(`[interaction] Body element not found for ${currentUrl}, skipping interaction`);
|
|
733
|
+
}
|
|
734
|
+
return;
|
|
735
|
+
}
|
|
736
|
+
} catch (bodyCheckErr) {
|
|
737
|
+
if (forceDebug) {
|
|
738
|
+
console.log(`[interaction] Page not ready for interaction on ${currentUrl} (waited ${bodyTimeout}ms): ${bodyCheckErr.message}`);
|
|
739
|
+
// For very slow sites, we might want to try a minimal interaction anyway
|
|
740
|
+
if (bodyTimeout >= 6000 && !bodyCheckErr.message.includes('closed')) {
|
|
741
|
+
console.log(`[interaction] Attempting minimal mouse movement only for slow-loading ${currentUrl}`);
|
|
742
|
+
return await performMinimalInteraction(page, currentUrl, options, forceDebug);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
|
|
686
748
|
// Get viewport dimensions
|
|
687
749
|
const viewport = await page.viewport();
|
|
688
750
|
const maxX = viewport ? viewport.width : DEFAULT_VIEWPORT.WIDTH;
|
|
@@ -753,7 +815,16 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
753
815
|
// Final hover position
|
|
754
816
|
const finalPos = generateRandomCoordinates(maxX, maxY);
|
|
755
817
|
await humanLikeMouseMove(page, currentPos.x, currentPos.y, finalPos.x, finalPos.y);
|
|
756
|
-
|
|
818
|
+
|
|
819
|
+
// Safe hover with validation
|
|
820
|
+
try {
|
|
821
|
+
const bodyElement = await page.$('body');
|
|
822
|
+
if (bodyElement) {
|
|
823
|
+
await page.hover('body');
|
|
824
|
+
}
|
|
825
|
+
} catch (hoverErr) {
|
|
826
|
+
// Silently handle hover failures - not critical
|
|
827
|
+
}
|
|
757
828
|
|
|
758
829
|
const elapsedTime = Date.now() - startTime;
|
|
759
830
|
if (forceDebug) {
|
|
@@ -768,6 +839,35 @@ async function performPageInteraction(page, currentUrl, options = {}, forceDebug
|
|
|
768
839
|
}
|
|
769
840
|
}
|
|
770
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Performs minimal interaction for very slow or problematic pages
|
|
844
|
+
* Only does basic mouse movement without body validation
|
|
845
|
+
*/
|
|
846
|
+
async function performMinimalInteraction(page, currentUrl, options = {}, forceDebug = false) {
|
|
847
|
+
try {
|
|
848
|
+
if (page.isClosed()) return;
|
|
849
|
+
|
|
850
|
+
const viewport = await page.viewport();
|
|
851
|
+
const maxX = viewport ? viewport.width : DEFAULT_VIEWPORT.WIDTH;
|
|
852
|
+
const maxY = viewport ? viewport.height : DEFAULT_VIEWPORT.HEIGHT;
|
|
853
|
+
|
|
854
|
+
if (forceDebug) {
|
|
855
|
+
console.log(`[interaction] Performing minimal interaction for slow page: ${new URL(currentUrl).hostname}`);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Just do basic mouse movement without body-dependent operations
|
|
859
|
+
const startPos = generateRandomCoordinates(maxX, maxY);
|
|
860
|
+
const endPos = generateRandomCoordinates(maxX, maxY);
|
|
861
|
+
|
|
862
|
+
await page.mouse.move(startPos.x, startPos.y);
|
|
863
|
+
await fastTimeout(500);
|
|
864
|
+
await humanLikeMouseMove(page, startPos.x, startPos.y, endPos.x, endPos.y);
|
|
865
|
+
|
|
866
|
+
} catch (minimalErr) {
|
|
867
|
+
// Even minimal interaction failed - page is truly broken
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
|
|
771
871
|
/**
|
|
772
872
|
* Creates an optimized interaction configuration based on site characteristics
|
|
773
873
|
*
|
package/nwss.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// === Network scanner script (nwss.js) v1.0.
|
|
1
|
+
// === Network scanner script (nwss.js) v1.0.63 ===
|
|
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
|
|
@@ -48,7 +48,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
|
|
|
48
48
|
const { monitorBrowserHealth, isBrowserHealthy } = require('./lib/browserhealth');
|
|
49
49
|
|
|
50
50
|
// --- Script Configuration & Constants ---
|
|
51
|
-
const VERSION = '1.0.
|
|
51
|
+
const VERSION = '1.0.63'; // Script version
|
|
52
52
|
|
|
53
53
|
// get startTime
|
|
54
54
|
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.63",
|
|
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": {
|