cdp-saw 1.0.2 → 1.1.5
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/index.js +35 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -7,6 +7,19 @@ const WebSocket = require('ws');
|
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const net = require('net');
|
|
9
9
|
|
|
10
|
+
// --- DETACH LOGIC ---
|
|
11
|
+
if (process.argv.includes('--detach')) {
|
|
12
|
+
const args = process.argv.slice(2).filter(a => a !== '--detach');
|
|
13
|
+
const child = spawn(process.execPath, [process.argv[1], ...args], {
|
|
14
|
+
detached: true,
|
|
15
|
+
stdio: 'ignore'
|
|
16
|
+
});
|
|
17
|
+
child.unref();
|
|
18
|
+
console.log(`[cdp] 🚀 Process detached to background (PID: ${child.pid})`);
|
|
19
|
+
process.exit(0);
|
|
20
|
+
}
|
|
21
|
+
// --- END DETACH LOGIC ---
|
|
22
|
+
|
|
10
23
|
const LOCK_PORT = 19191;
|
|
11
24
|
let CDP_PORT = 0;
|
|
12
25
|
|
|
@@ -52,9 +65,29 @@ function selectBestKey(isHighCost) {
|
|
|
52
65
|
return bestKey;
|
|
53
66
|
}
|
|
54
67
|
|
|
68
|
+
function findTestpadPath() {
|
|
69
|
+
const commonPaths = [
|
|
70
|
+
process.env.LOCALAPPDATA ? path.join(process.env.LOCALAPPDATA, 'Programs', 'testpad', 'testpad.exe') : null,
|
|
71
|
+
process.env.ProgramFiles ? path.join(process.env.ProgramFiles, 'testpad', 'testpad.exe') : null,
|
|
72
|
+
process.env['ProgramFiles(x86)'] ? path.join(process.env['ProgramFiles(x86)'], 'testpad', 'testpad.exe') : null,
|
|
73
|
+
'C:\\Program Files\\testpad\\testpad.exe',
|
|
74
|
+
'C:\\Program Files (x86)\\testpad\\testpad.exe'
|
|
75
|
+
];
|
|
76
|
+
for (const p of commonPaths) {
|
|
77
|
+
if (p && fs.existsSync(p)) return p;
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const TESTPAD_PATH = findTestpadPath();
|
|
83
|
+
if (!TESTPAD_PATH) {
|
|
84
|
+
console.error('[cdp] ❌ ERROR: testpad.exe not found in common locations!');
|
|
85
|
+
console.error('[cdp] Please ensure Testpad is installed or provide the path manually.');
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
55
89
|
function launchBrowser() {
|
|
56
|
-
const
|
|
57
|
-
const p = path.join(userProfile, "AppData\\Local\\Programs\\testpad\\testpad.exe");
|
|
90
|
+
const p = TESTPAD_PATH;
|
|
58
91
|
if (fs.existsSync(p)) {
|
|
59
92
|
console.log(`[cdp] 🚀 Launching: ${p}`);
|
|
60
93
|
cleanupProcesses();
|