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

fix(browser): launch Chrome via LaunchServices on macOS so download-UI shell handoffs work

[._.]/ Adam Eivyb88254bcd1ad
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index a519cfd1fa..1108eceed0 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -1019,6 +1019,25 @@
## Fixed
+- **Browser download-UI shell handoffs dead on macOS (Show in Finder / Open file silently no-op).**
+ `browser/server.js` spawned Chrome as a direct child of `node`/PM2, which
+ made PM2 the TCC "responsible app" for Chrome's AppleEvent +
+ LaunchServices calls on macOS Sequoia. PM2 hasn't been granted Automation
+ or Files-and-Folders access, so every shell handoff from Chrome's download
+ UI ("Show in Finder", "Open file", chrome://downloads row click) silently
+ no-op'd. Downloads themselves landed correctly because Chrome's own
+ sandboxed writes don't go through TCC. Fix: on macOS headed mode, launch
+ via `/usr/bin/open -na "Google Chrome.app" --args …` so launchd is the
+ responsible launcher and Chrome runs with its own TCC identity (Chrome's
+ parent PID is now `launchd` instead of `node`). Headless mode keeps the
+ direct `spawn` (no UI to click), and Linux/Windows are unaffected (no TCC).
+ Trade-off: `open` returns immediately, so we lose the direct PID handle;
+ shutdown now sends CDP `Browser.close` (with a 2s safety timeout + WS
+ fallback) instead of SIGTERM on macOS headed mode. **Files:**
+ `browser/server.js` — `MAC_CHROME_APP` constant, platform-split launch
+ branch in `launchBrowser`, new `closeBrowserViaCdp` helper, `shutdown`
+ promoted to async.
+
- **Stale-build cache — buildId now invalidates when `client/dist/index.html` changes.**
The boot-time cache in `server/lib/buildId.js` was load-once: once captured,
the server kept serving the *original* stamped index.html — referencing the
diff --git a/browser/server.js b/browser/server.js
index f76e31ba44..2643f18421 100644
--- a/browser/server.js
+++ b/browser/server.js
@@ -33,6 +33,8 @@ function getChromePath() {
return 'google-chrome';
}
+const MAC_CHROME_APP = '/Applications/Google Chrome.app';
+
async function loadConfig() {
const raw = await readFile(CONFIG_FILE, 'utf-8').catch(() => null);
return raw ? JSON.parse(raw) : {};
@@ -176,16 +178,36 @@ async function launchBrowser() {
console.log(`🌐 Launching Chrome (headless=${headlessMode}, profile=${profileDir}) CDP on ${CDP_HOST}:${CDP_PORT}`);
- chromeProcess = spawn(chromePath, args, { stdio: 'ignore', windowsHide: true });
-
- chromeProcess.on('exit', (code) => {
- console.log(`⚠️ Chrome exited with code ${code}`);
- chromeProcess = null;
- if (downloadWs) {
- try { downloadWs.close(); } catch {}
- downloadWs = null;
- }
- });
+ // macOS headed mode: launch via LaunchServices (`open -na`) so Chrome owns
+ // its own TCC identity. As a direct subprocess of node/PM2, Chrome inherits
+ // PM2's responsibility for AppleEvents + LaunchServices calls — every shell
+ // handoff from the download UI ("Show in Finder", "Open file", chrome://
+ // downloads row click) silently no-ops because PM2 isn't granted Automation
+ // / Files-and-Folders access. `open -na` makes launchd the responsible
+ // launcher, so tccd resolves Chrome's requests against the user's existing
+ // Chrome.app grants. Trade-off: `open` returns immediately, so we lose the
+ // direct PID — shutdown uses CDP `Browser.close` instead of SIGTERM.
+ // Headless mode skips this (no UI to click) and non-darwin platforms don't
+ // have the TCC-responsibility problem at all.
+ if (platform() === 'darwin' && !headlessMode) {
+ chromeProcess = spawn('/usr/bin/open', ['-na', MAC_CHROME_APP, '--args', ...args], { stdio: 'ignore' });
+ chromeProcess.on('exit', () => {
+ // `open` returns ~immediately once Chrome is handed off to launchd; that
+ // exit is not Chrome's death. Chrome-exit detection happens via the
+ // download keep-alive WS close event + reconnect loop instead.
+ chromeProcess = null;
+ });
+ } else {
+ chromeProcess = spawn(chromePath, args, { stdio: 'ignore', windowsHide: true });
+ chromeProcess.on('exit', (code) => {
+ console.log(`⚠️ Chrome exited with code ${code}`);
+ chromeProcess = null;
+ if (downloadWs) {
+ try { downloadWs.close(); } catch {}
+ downloadWs = null;
+ }
+ });
+ }
// Wait for CDP to become available
for (let i = 0; i < 20; i++) {
@@ -231,20 +253,42 @@ const healthServer = createServer(async (req, res) => {
}
});
-function shutdown() {
+async function closeBrowserViaCdp() {
+ if (typeof WebSocket === 'undefined') return;
+ const version = await checkCdp();
+ const wsUrl = version?.webSocketDebuggerUrl;
+ if (!wsUrl) return;
+ await new Promise((resolve) => {
+ const ws = new WebSocket(wsUrl);
+ const done = () => { try { ws.close(); } catch {} resolve(); };
+ const safety = setTimeout(done, 2000);
+ ws.addEventListener('open', () => {
+ try { ws.send(JSON.stringify({ id: 999, method: 'Browser.close' })); } catch {}
+ // Give Chrome a moment to tear down before we exit the supervisor
+ setTimeout(() => { clearTimeout(safety); done(); }, 500);
+ });
+ ws.addEventListener('error', () => { clearTimeout(safety); done(); });
+ });
+}
+
+async function shutdown() {
console.log('🛑 Shutting down browser...');
shuttingDown = true;
if (downloadWsReconnectTimer) {
clearTimeout(downloadWsReconnectTimer);
downloadWsReconnectTimer = null;
}
+ // macOS headed mode: we launched via `open` which exited immediately, so
+ // SIGTERM on `chromeProcess` is a no-op. Send CDP Browser.close instead.
+ if (platform() === 'darwin' && !headlessMode) {
+ await closeBrowserViaCdp().catch(() => {});
+ } else if (chromeProcess && !chromeProcess.killed) {
+ chromeProcess.kill('SIGTERM');
+ }
if (downloadWs) {
try { downloadWs.close(); } catch {}
downloadWs = null;
}
- if (chromeProcess && !chromeProcess.killed) {
- chromeProcess.kill('SIGTERM');
- }
healthServer.close();
process.exit(0);
}