@fanboynz/network-scanner 1.0.95 → 1.0.96
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/cdp.js +39 -2
- package/nwss.js +8 -13
- package/package.json +1 -1
package/lib/cdp.js
CHANGED
|
@@ -27,6 +27,36 @@
|
|
|
27
27
|
|
|
28
28
|
const { formatLogMessage } = require('./colorize');
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new page with timeout protection to prevent CDP hangs
|
|
32
|
+
* @param {import('puppeteer').Browser} browser - Browser instance
|
|
33
|
+
* @param {number} timeout - Timeout in milliseconds (default: 30000)
|
|
34
|
+
* @returns {Promise<import('puppeteer').Page>} Page instance
|
|
35
|
+
*/
|
|
36
|
+
async function createPageWithTimeout(browser, timeout = 30000) {
|
|
37
|
+
return Promise.race([
|
|
38
|
+
browser.newPage(),
|
|
39
|
+
new Promise((_, reject) =>
|
|
40
|
+
setTimeout(() => reject(new Error('Page creation timeout - browser may be unresponsive')), timeout)
|
|
41
|
+
)
|
|
42
|
+
]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Sets request interception with timeout protection
|
|
47
|
+
* @param {import('puppeteer').Page} page - Page instance
|
|
48
|
+
* @param {number} timeout - Timeout in milliseconds (default: 15000)
|
|
49
|
+
* @returns {Promise<void>}
|
|
50
|
+
*/
|
|
51
|
+
async function setRequestInterceptionWithTimeout(page, timeout = 15000) {
|
|
52
|
+
return Promise.race([
|
|
53
|
+
page.setRequestInterception(true),
|
|
54
|
+
new Promise((_, reject) =>
|
|
55
|
+
setTimeout(() => reject(new Error('Request interception setup timeout')), timeout)
|
|
56
|
+
)
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
|
|
30
60
|
/**
|
|
31
61
|
* Creates and manages a CDP session for network monitoring
|
|
32
62
|
*
|
|
@@ -88,8 +118,13 @@ async function createCDPSession(page, currentUrl, options = {}) {
|
|
|
88
118
|
|
|
89
119
|
try {
|
|
90
120
|
// Create CDP session using modern Puppeteer 20+ API
|
|
91
|
-
//
|
|
92
|
-
cdpSession = await
|
|
121
|
+
// Add timeout protection for CDP session creation
|
|
122
|
+
cdpSession = await Promise.race([
|
|
123
|
+
page.createCDPSession(),
|
|
124
|
+
new Promise((_, reject) =>
|
|
125
|
+
setTimeout(() => reject(new Error('CDP session creation timeout')), 20000)
|
|
126
|
+
)
|
|
127
|
+
]);
|
|
93
128
|
|
|
94
129
|
// Enable network domain - required for network event monitoring
|
|
95
130
|
await cdpSession.send('Network.enable');
|
|
@@ -302,6 +337,8 @@ async function createEnhancedCDPSession(page, currentUrl, options = {}) {
|
|
|
302
337
|
// - Some features may not work in --no-sandbox mode
|
|
303
338
|
module.exports = {
|
|
304
339
|
createCDPSession,
|
|
340
|
+
createPageWithTimeout,
|
|
341
|
+
setRequestInterceptionWithTimeout,
|
|
305
342
|
validateCDPConfig,
|
|
306
343
|
createEnhancedCDPSession
|
|
307
344
|
};
|
package/nwss.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// === Network scanner script (nwss.js) v1.0.
|
|
1
|
+
// === Network scanner script (nwss.js) v1.0.96 ===
|
|
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 { createNetToolsHandler, createEnhancedDryRunCallback, validateWhoisAvaila
|
|
|
33
33
|
// File compare
|
|
34
34
|
const { loadComparisonRules, filterUniqueRules } = require('./lib/compare');
|
|
35
35
|
// CDP functionality
|
|
36
|
-
const { createCDPSession } = require('./lib/cdp');
|
|
36
|
+
const { createCDPSession, createPageWithTimeout, setRequestInterceptionWithTimeout } = require('./lib/cdp');
|
|
37
37
|
// Post-processing cleanup
|
|
38
38
|
const { processResults } = require('./lib/post-processing');
|
|
39
39
|
// Colorize various text when used
|
|
@@ -125,7 +125,7 @@ const { navigateWithRedirectHandling, handleRedirectTimeout } = require('./lib/r
|
|
|
125
125
|
const { monitorBrowserHealth, isBrowserHealthy, isQuicklyResponsive } = require('./lib/browserhealth');
|
|
126
126
|
|
|
127
127
|
// --- Script Configuration & Constants ---
|
|
128
|
-
const VERSION = '1.0.
|
|
128
|
+
const VERSION = '1.0.96'; // Script version
|
|
129
129
|
|
|
130
130
|
// get startTime
|
|
131
131
|
const startTime = Date.now();
|
|
@@ -1465,7 +1465,7 @@ function setupFrameHandling(page, forceDebug) {
|
|
|
1465
1465
|
if (browserInstance.process() && browserInstance.process().killed) {
|
|
1466
1466
|
throw new Error('Browser process was killed - restart required');
|
|
1467
1467
|
}
|
|
1468
|
-
page = await browserInstance
|
|
1468
|
+
page = await createPageWithTimeout(browserInstance, 30000);
|
|
1469
1469
|
|
|
1470
1470
|
// Enhanced page validation for Puppeteer 23.x
|
|
1471
1471
|
if (!page || page.isClosed()) {
|
|
@@ -1779,13 +1779,8 @@ function setupFrameHandling(page, forceDebug) {
|
|
|
1779
1779
|
|
|
1780
1780
|
// Protected request interception setup with timeout
|
|
1781
1781
|
try {
|
|
1782
|
-
//
|
|
1783
|
-
await
|
|
1784
|
-
page.setRequestInterception(true),
|
|
1785
|
-
new Promise((_, reject) =>
|
|
1786
|
-
setTimeout(() => reject(new Error('Network.enable timeout')), 10000)
|
|
1787
|
-
)
|
|
1788
|
-
]);
|
|
1782
|
+
// Use timeout-protected request interception setup
|
|
1783
|
+
await setRequestInterceptionWithTimeout(page, 15000);
|
|
1789
1784
|
|
|
1790
1785
|
if (forceDebug) {
|
|
1791
1786
|
console.log(formatLogMessage('debug', `Request interception enabled successfully for ${currentUrl}`));
|
|
@@ -1794,13 +1789,13 @@ function setupFrameHandling(page, forceDebug) {
|
|
|
1794
1789
|
if (networkErr.message.includes('timed out') ||
|
|
1795
1790
|
networkErr.message.includes('Network.enable') ||
|
|
1796
1791
|
networkErr.message.includes('timeout')) {
|
|
1797
|
-
console.warn(formatLogMessage('warn', `
|
|
1792
|
+
console.warn(formatLogMessage('warn', `Request interception setup failed for ${currentUrl}: ${networkErr.message} - triggering browser restart`));
|
|
1798
1793
|
return {
|
|
1799
1794
|
url: currentUrl,
|
|
1800
1795
|
rules: [],
|
|
1801
1796
|
success: false,
|
|
1802
1797
|
needsImmediateRestart: true,
|
|
1803
|
-
error: '
|
|
1798
|
+
error: 'Request interception timeout - browser restart required'
|
|
1804
1799
|
};
|
|
1805
1800
|
}
|
|
1806
1801
|
throw networkErr; // Re-throw other errors
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fanboynz/network-scanner",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.96",
|
|
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": {
|