Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: use real Chrome instead of Playwright Chromium for browser

Adam Eivyfb4d288116f9
diff --git a/.changelog/v0.11.17.md b/.changelog/v0.11.17.md
index 82c6bfc625..2b830a6497 100644
--- a/.changelog/v0.11.17.md
+++ b/.changelog/v0.11.17.md
@@ -221,6 +221,8 @@ This release focuses on security improvements, bug fixes for the AI runner syste
- **Persistent browser profile**: Auth cookies, localStorage, and sessions now persist across restarts via `--user-data-dir` pointing to `data/browser-profile`
- **Config-driven launch**: The browser process reads its configuration from the shared config file on startup instead of hardcoding `headless: true`
- **Live mode display**: Sidebar shows whether the running browser is in headed or headless mode, with a restart hint after config changes
+- **Real Chrome instead of Playwright Chromium**: Browser process now spawns system Chrome directly (`/Applications/Google Chrome.app`) instead of Playwright's bundled Chromium, enabling Google sign-in and other auth flows that reject automation browsers
+- **Removed Playwright dependency**: Browser process uses `child_process.spawn()` and CDP HTTP endpoints, no longer depends on the playwright npm package
### Architecture Documentation Update
- **Updated system diagram**: Expanded the architecture diagram to include portos-browser and portos-autofixer as PM2-managed satellite services alongside Chief of Staff
diff --git a/browser/package.json b/browser/package.json
index 277ddf687a..6ecbbd46d6 100644
--- a/browser/package.json
+++ b/browser/package.json
@@ -2,12 +2,10 @@
"name": "portos-browser",
"version": "1.0.0",
"private": true,
- "description": "Persistent browser for PortOS CoS and sub-agents",
+ "description": "Persistent Chrome browser for PortOS with CDP",
"type": "module",
"scripts": {
"start": "node server.js"
},
- "dependencies": {
- "playwright": "^1.49.0"
- }
+ "dependencies": {}
}
diff --git a/browser/server.js b/browser/server.js
index 74b9f3c10d..187851bc6b 100644
--- a/browser/server.js
+++ b/browser/server.js
@@ -1,8 +1,9 @@
-import { chromium } from 'playwright';
+import { spawn } from 'child_process';
import { createServer } from 'http';
import { readFile, mkdir } from 'fs/promises';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
+import { platform } from 'os';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PROJECT_ROOT = resolve(__dirname, '..');
@@ -11,60 +12,80 @@ const DEFAULT_PROFILE_DIR = resolve(PROJECT_ROOT, 'data', 'browser-profile');
const CDP_PORT = parseInt(process.env.CDP_PORT || '5556', 10);
const HEALTH_PORT = parseInt(process.env.PORT || '5557', 10);
-// Security: CDP binds to localhost only - remote access should go through
-// portos-server which can proxy connections with proper authentication
const CDP_HOST = process.env.CDP_HOST || '127.0.0.1';
-let context = null;
+let chromeProcess = null;
let headlessMode = true;
+function getChromePath() {
+ const os = platform();
+ if (os === 'darwin') return '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
+ if (os === 'win32') return 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
+ return 'google-chrome';
+}
+
async function loadConfig() {
const raw = await readFile(CONFIG_FILE, 'utf-8').catch(() => null);
return raw ? JSON.parse(raw) : {};
}
-function isConnected() {
- return context?.browser()?.isConnected() ?? false;
+async function checkCdp() {
+ const controller = new AbortController();
+ const timeout = setTimeout(() => controller.abort(), 2000);
+ const res = await fetch(`http://${CDP_HOST}:${CDP_PORT}/json/version`, { signal: controller.signal }).catch(() => null);
+ clearTimeout(timeout);
+ return res?.ok ?? false;
}
async function launchBrowser() {
const config = await loadConfig();
headlessMode = config.headless !== false;
const profileDir = config.userDataDir || DEFAULT_PROFILE_DIR;
+ const chromePath = getChromePath();
await mkdir(profileDir, { recursive: true });
- console.log(`🌐 Launching browser (headless=${headlessMode}, profile=${profileDir}) CDP on ${CDP_HOST}:${CDP_PORT}`);
-
- context = await chromium.launchPersistentContext(profileDir, {
- headless: headlessMode,
- args: [
- `--remote-debugging-port=${CDP_PORT}`,
- `--remote-debugging-address=${CDP_HOST}`,
- '--no-first-run',
- '--no-default-browser-check',
- '--disable-background-networking',
- '--disable-sync',
- '--disable-translate',
- '--disable-extensions',
- '--disable-infobars',
- '--disable-notifications'
- ]
- });
+ const args = [
+ `--remote-debugging-port=${CDP_PORT}`,
+ `--remote-debugging-address=${CDP_HOST}`,
+ `--user-data-dir=${profileDir}`,
+ '--no-first-run',
+ '--no-default-browser-check',
+ '--disable-background-timer-throttling',
+ '--disable-backgrounding-occluded-windows',
+ '--disable-renderer-backgrounding',
+ '--disable-ipc-flooding-protection'
+ ];
+
+ if (headlessMode) {
+ args.push('--headless=new');
+ }
- context.browser()?.on('disconnected', () => {
- console.log('⚠️ Browser disconnected, restarting...');
- context = null;
- setTimeout(launchBrowser, 1000);
+ console.log(`🌐 Launching Chrome (headless=${headlessMode}, profile=${profileDir}) CDP on ${CDP_HOST}:${CDP_PORT}`);
+
+ chromeProcess = spawn(chromePath, args, { stdio: 'ignore' });
+
+ chromeProcess.on('exit', (code) => {
+ console.log(`⚠️ Chrome exited with code ${code}`);
+ chromeProcess = null;
});
- console.log(`✅ Browser launched, CDP available at ws://${CDP_HOST}:${CDP_PORT}`);
+ // Wait for CDP to become available
+ for (let i = 0; i < 20; i++) {
+ await new Promise(r => setTimeout(r, 500));
+ if (await checkCdp()) {
+ console.log(`✅ Chrome launched, CDP available at ws://${CDP_HOST}:${CDP_PORT}`);
+ return;
+ }
+ }
+
+ console.error('❌ Chrome launched but CDP not reachable after 10s');
}
-// Simple health check server
-const healthServer = createServer((req, res) => {
+// Health check server
+const healthServer = createServer(async (req, res) => {
if (req.url === '/health') {
- const connected = isConnected();
+ const connected = chromeProcess && !chromeProcess.killed && await checkCdp();
const status = connected ? 'healthy' : 'unhealthy';
res.writeHead(connected ? 200 : 503, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({
@@ -92,10 +113,10 @@ const healthServer = createServer((req, res) => {
}
});
-async function shutdown() {
+function shutdown() {
console.log('🛑 Shutting down browser...');
- if (context) {
- await context.close().catch(() => {});
+ if (chromeProcess && !chromeProcess.killed) {
+ chromeProcess.kill('SIGTERM');
}
healthServer.close();
process.exit(0);