mirror of
https://github.com/browseros-ai/BrowserOS.git
synced 2026-05-13 23:53:25 +00:00
Compare commits
1 Commits
fix/cache-
...
feat/impro
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b03bad80e1 |
@@ -6,9 +6,11 @@
|
||||
* Use setup.ts:ensureBrowserOS() for the full test environment.
|
||||
*/
|
||||
import type { ChildProcess } from 'node:child_process'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { spawn, spawnSync } from 'node:child_process'
|
||||
import { rmSync } from 'node:fs'
|
||||
|
||||
const TEST_USER_DATA_PREFIX = 'browseros-test-'
|
||||
|
||||
export interface BrowserConfig {
|
||||
cdpPort: number
|
||||
serverPort: number
|
||||
@@ -58,6 +60,16 @@ export function getBrowserState(): BrowserState | null {
|
||||
return browserState
|
||||
}
|
||||
|
||||
function killOrphanedTestBrowsers(): void {
|
||||
// Matches only BrowserOS processes launched with a test user-data-dir
|
||||
// (e.g., /var/folders/.../browseros-test-XXXX). Never matches a dev
|
||||
// BrowserOS run from ~/Library/Application Support/BrowserOS.
|
||||
const result = spawnSync('pkill', ['-9', '-f', TEST_USER_DATA_PREFIX])
|
||||
if (result.status === 0) {
|
||||
console.log('Killed orphaned test browsers from a previous run')
|
||||
}
|
||||
}
|
||||
|
||||
export async function spawnBrowser(
|
||||
config: BrowserConfig,
|
||||
): Promise<BrowserState> {
|
||||
@@ -73,6 +85,8 @@ export async function spawnBrowser(
|
||||
await killBrowser()
|
||||
}
|
||||
|
||||
killOrphanedTestBrowsers()
|
||||
|
||||
console.log(`Starting BrowserOS on CDP port ${config.cdpPort}...`)
|
||||
const browserProcess = spawn(
|
||||
config.binaryPath,
|
||||
|
||||
@@ -20,6 +20,14 @@ for port in $CDP_PORT $SERVER_PORT $EXTENSION_PORT; do
|
||||
fi
|
||||
done
|
||||
|
||||
# Kill orphaned test browser processes (matches only BrowserOS launched with
|
||||
# a test user-data-dir — never the user's dev BrowserOS)
|
||||
orphan_pids=$(pgrep -f 'browseros-test-' 2>/dev/null || true)
|
||||
if [ -n "$orphan_pids" ]; then
|
||||
echo " Killing orphaned test browser processes: $(echo "$orphan_pids" | tr '\n' ' ')"
|
||||
echo "$orphan_pids" | xargs kill -9 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Clean up orphaned temp directories (created by browser.ts)
|
||||
# Uses $TMPDIR which matches Node's os.tmpdir()
|
||||
TEMP_DIR="${TMPDIR:-/tmp}"
|
||||
|
||||
Reference in New Issue
Block a user