@fanboynz/network-scanner 2.0.35 → 2.0.36
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/browserexit.js +15 -20
- package/package.json +1 -1
package/lib/browserexit.js
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Provides graceful and forced browser closure functionality with comprehensive temp file cleanup
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const { execSync } = require('child_process');
|
|
9
|
+
|
|
6
10
|
// Constants for temp file cleanup
|
|
7
11
|
const CHROME_TEMP_PATHS = [
|
|
8
12
|
'/tmp',
|
|
@@ -13,8 +17,7 @@ const CHROME_TEMP_PATHS = [
|
|
|
13
17
|
const CHROME_TEMP_PATTERNS = [
|
|
14
18
|
'.com.google.Chrome.*', // Google Chrome temp files
|
|
15
19
|
'.org.chromium.Chromium.*',
|
|
16
|
-
'puppeteer-*'
|
|
17
|
-
'.com.google.Chrome.*' // Ensure Google Chrome pattern is included
|
|
20
|
+
'puppeteer-*'
|
|
18
21
|
];
|
|
19
22
|
|
|
20
23
|
/**
|
|
@@ -33,7 +36,6 @@ async function cleanupChromeTempFiles(options = {}) {
|
|
|
33
36
|
} = options;
|
|
34
37
|
|
|
35
38
|
try {
|
|
36
|
-
const { execSync } = require('child_process');
|
|
37
39
|
|
|
38
40
|
// Base cleanup commands for standard temp directories
|
|
39
41
|
const cleanupCommands = [
|
|
@@ -56,17 +58,17 @@ async function cleanupChromeTempFiles(options = {}) {
|
|
|
56
58
|
|
|
57
59
|
for (const command of cleanupCommands) {
|
|
58
60
|
try {
|
|
59
|
-
//
|
|
60
|
-
const
|
|
61
|
-
|
|
61
|
+
// Extract glob pattern and count matches before deletion
|
|
62
|
+
const globPattern = command.match(/rm -rf ([^ ]+)/)?.[1];
|
|
63
|
+
if (!globPattern) continue;
|
|
64
|
+
const fileCount = parseInt(execSync(`ls -1d ${globPattern} 2>/dev/null | wc -l || echo 0`, { stdio: 'pipe' }).toString().trim()) || 0;
|
|
62
65
|
|
|
63
66
|
if (fileCount > 0) {
|
|
64
67
|
execSync(command, { stdio: 'ignore' });
|
|
65
68
|
totalCleaned += fileCount;
|
|
66
69
|
|
|
67
70
|
if (forceDebug) {
|
|
68
|
-
|
|
69
|
-
console.log(`[debug] [temp-cleanup] Cleaned ${fileCount} items from ${pathPattern}`);
|
|
71
|
+
console.log(`[debug] [temp-cleanup] Cleaned ${fileCount} items from ${globPattern}`);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
} catch (cmdErr) {
|
|
@@ -102,7 +104,6 @@ async function comprehensiveChromeTempCleanup(options = {}) {
|
|
|
102
104
|
const { forceDebug = false, verbose = false } = options;
|
|
103
105
|
|
|
104
106
|
try {
|
|
105
|
-
const { execSync } = require('child_process');
|
|
106
107
|
let totalCleaned = 0;
|
|
107
108
|
|
|
108
109
|
if (verbose && !forceDebug) {
|
|
@@ -112,8 +113,7 @@ async function comprehensiveChromeTempCleanup(options = {}) {
|
|
|
112
113
|
for (const basePath of CHROME_TEMP_PATHS) {
|
|
113
114
|
// Check if the base path exists before trying to clean it
|
|
114
115
|
try {
|
|
115
|
-
const pathExists =
|
|
116
|
-
.toString().trim() === 'exists';
|
|
116
|
+
const pathExists = fs.existsSync(basePath);
|
|
117
117
|
|
|
118
118
|
if (!pathExists) {
|
|
119
119
|
if (forceDebug) {
|
|
@@ -149,7 +149,7 @@ async function comprehensiveChromeTempCleanup(options = {}) {
|
|
|
149
149
|
if (verbose && totalCleaned > 0) {
|
|
150
150
|
console.log(`[temp-cleanup] ? Removed ${totalCleaned} temporary file(s)/folder(s)`);
|
|
151
151
|
} else if (verbose && totalCleaned === 0) {
|
|
152
|
-
console.log(`[temp-cleanup]
|
|
152
|
+
console.log(`[temp-cleanup] ? Clean - no remaining temporary files`);
|
|
153
153
|
} else if (forceDebug) {
|
|
154
154
|
console.log(`[debug] [temp-cleanup] Comprehensive cleanup completed (${totalCleaned} items)`);
|
|
155
155
|
}
|
|
@@ -179,7 +179,6 @@ async function cleanupUserDataDir(userDataDir, forceDebug = false) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
try {
|
|
182
|
-
const fs = require('fs');
|
|
183
182
|
|
|
184
183
|
if (!fs.existsSync(userDataDir)) {
|
|
185
184
|
if (forceDebug) {
|
|
@@ -281,9 +280,7 @@ async function forceBrowserKill(browser, forceDebug = false) {
|
|
|
281
280
|
const mainPid = browserProcess.pid;
|
|
282
281
|
if (forceDebug) console.log(`[debug] [browser] Main Chrome PID: ${mainPid}`);
|
|
283
282
|
|
|
284
|
-
// Find and kill ALL related Chrome processes
|
|
285
|
-
const { execSync } = require('child_process');
|
|
286
|
-
|
|
283
|
+
// Find and kill ALL related Chrome processes
|
|
287
284
|
|
|
288
285
|
try {
|
|
289
286
|
// Find all Chrome processes with puppeteer in command line
|
|
@@ -390,9 +387,7 @@ async function forceBrowserKill(browser, forceDebug = false) {
|
|
|
390
387
|
* @returns {Promise<void>}
|
|
391
388
|
*/
|
|
392
389
|
async function killAllPuppeteerChrome(forceDebug = false) {
|
|
393
|
-
try {
|
|
394
|
-
const { execSync } = require('child_process');
|
|
395
|
-
|
|
390
|
+
try {
|
|
396
391
|
if (forceDebug) console.log(`[debug] [browser] Nuclear option: killing all puppeteer Chrome processes...`);
|
|
397
392
|
|
|
398
393
|
try {
|
|
@@ -439,7 +434,7 @@ async function handleBrowserExit(browser, options = {}) {
|
|
|
439
434
|
|
|
440
435
|
const results = {
|
|
441
436
|
browserClosed: false,
|
|
442
|
-
|
|
437
|
+
tempFilesCleanedCount: 0,
|
|
443
438
|
userDataCleaned: false,
|
|
444
439
|
success: false,
|
|
445
440
|
errors: []
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fanboynz/network-scanner",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.36",
|
|
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": {
|