codebot-ai 1.1.1 → 1.1.2
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/dist/tools/browser.js +13 -5
- package/package.json +1 -1
package/dist/tools/browser.js
CHANGED
|
@@ -43,24 +43,32 @@ const fs = __importStar(require("fs"));
|
|
|
43
43
|
let client = null;
|
|
44
44
|
let debugPort = 9222;
|
|
45
45
|
const CHROME_DATA_DIR = path.join(os.homedir(), '.codebot', 'chrome-profile');
|
|
46
|
-
/** Kill any Chrome using our debug port or data dir */
|
|
46
|
+
/** Kill any Chrome using our debug port or data dir (but NEVER kill ourselves) */
|
|
47
47
|
function killExistingChrome() {
|
|
48
|
+
// Close our own CDP connection first so we don't hold the port
|
|
49
|
+
if (client) {
|
|
50
|
+
try {
|
|
51
|
+
client.close();
|
|
52
|
+
}
|
|
53
|
+
catch { /* ignore */ }
|
|
54
|
+
client = null;
|
|
55
|
+
}
|
|
48
56
|
const { execSync } = require('child_process');
|
|
57
|
+
const myPid = process.pid;
|
|
49
58
|
try {
|
|
50
59
|
if (process.platform === 'win32') {
|
|
51
60
|
execSync(`for /f "tokens=5" %a in ('netstat -aon ^| findstr :${debugPort}') do taskkill /F /PID %a`, { stdio: 'ignore' });
|
|
52
61
|
}
|
|
53
62
|
else {
|
|
54
|
-
// Kill
|
|
55
|
-
execSync(`lsof -ti:${debugPort} | xargs kill -9 2>/dev/null || true`, { stdio: 'ignore' });
|
|
63
|
+
// Kill Chrome/Chromium processes on our debug port — exclude our own PID
|
|
64
|
+
execSync(`lsof -ti:${debugPort} | grep -v "^${myPid}$" | xargs kill -9 2>/dev/null || true`, { stdio: 'ignore' });
|
|
56
65
|
// Also kill any Chrome using our data dir
|
|
57
|
-
execSync(`pkill -f "
|
|
66
|
+
execSync(`pkill -9 -f "chrome.*--user-data-dir=${CHROME_DATA_DIR}" 2>/dev/null || true`, { stdio: 'ignore' });
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
catch {
|
|
61
70
|
// ignore — nothing to kill
|
|
62
71
|
}
|
|
63
|
-
// Give OS time to release the port
|
|
64
72
|
}
|
|
65
73
|
async function ensureConnected() {
|
|
66
74
|
if (client?.isConnected())
|
package/package.json
CHANGED