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(browser): add download support with CDP download behavior configuration

Adam Eivy494558e1b5eb
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 925f92fcd9..0794201358 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -14,6 +14,9 @@
- Pipeline UI: tabbed prompt viewer shows each stage's full prompt with stage name tabs
- MortalLoom export now includes goals, reads actual custom drink/nicotine presets, and parallelizes all I/O
- MeatSpace Settings tab with import/export functionality
+- Browser download support via CDP `Browser.setDownloadBehavior` — downloads now land in `data/browser-downloads/`
+- Downloads section on Browser page showing file list with size and date
+- `/api/browser/downloads` endpoint for listing downloaded files
## Changed
diff --git a/browser/server.js b/browser/server.js
index 4c9d9fadff..56b66ecb0b 100644
--- a/browser/server.js
+++ b/browser/server.js
@@ -9,6 +9,7 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const PROJECT_ROOT = resolve(__dirname, '..');
const CONFIG_FILE = resolve(PROJECT_ROOT, 'data', 'browser-config.json');
const DEFAULT_PROFILE_DIR = resolve(PROJECT_ROOT, 'data', 'browser-profile');
+const DEFAULT_DOWNLOAD_DIR = resolve(PROJECT_ROOT, 'data', 'browser-downloads');
const CDP_PORT = parseInt(process.env.CDP_PORT || '5556', 10);
const HEALTH_PORT = parseInt(process.env.PORT || '5557', 10);
@@ -34,22 +35,57 @@ async function checkCdp() {
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;
+ if (!res?.ok) return null;
+ return res.json();
+}
+
+async function configureDownloadBehavior(downloadDir) {
+ const version = await checkCdp();
+ const wsUrl = version?.webSocketDebuggerUrl;
+ if (!wsUrl) return;
+
+ // CDP requires explicit Browser.setDownloadBehavior — without it headless Chrome silently drops downloads
+ await new Promise((resolve) => {
+ const ws = new WebSocket(wsUrl);
+ const timer = setTimeout(() => { ws.close(); resolve(); }, 5000);
+ ws.addEventListener('open', () => {
+ ws.send(JSON.stringify({
+ id: 1,
+ method: 'Browser.setDownloadBehavior',
+ params: { behavior: 'allow', downloadPath: downloadDir }
+ }));
+ });
+ ws.addEventListener('message', (event) => {
+ const msg = JSON.parse(event.data);
+ if (msg.id === 1) {
+ console.log(`📥 Downloads configured → ${downloadDir}`);
+ clearTimeout(timer);
+ ws.close();
+ resolve();
+ }
+ });
+ ws.addEventListener('error', () => { clearTimeout(timer); resolve(); });
+ });
}
async function launchBrowser() {
+ const config = await loadConfig();
+ const downloadDir = config.downloadDir || DEFAULT_DOWNLOAD_DIR;
+
// Reuse existing Chrome if CDP is already reachable (e.g. after PM2 restart)
if (await checkCdp()) {
console.log(`♻️ Existing Chrome CDP found at ${CDP_HOST}:${CDP_PORT}, reusing`);
+ await mkdir(downloadDir, { recursive: true });
+ await configureDownloadBehavior(downloadDir);
return;
}
- const config = await loadConfig();
headlessMode = config.headless !== false;
const profileDir = config.userDataDir || DEFAULT_PROFILE_DIR;
const chromePath = getChromePath();
await mkdir(profileDir, { recursive: true });
+ await mkdir(downloadDir, { recursive: true });
const args = [
`--remote-debugging-port=${CDP_PORT}`,
@@ -81,6 +117,7 @@ async function launchBrowser() {
await new Promise(r => setTimeout(r, 500));
if (await checkCdp()) {
console.log(`✅ Chrome launched, CDP available at ws://${CDP_HOST}:${CDP_PORT}`);
+ await configureDownloadBehavior(downloadDir);
return;
}
}
diff --git a/client/src/pages/Browser.jsx b/client/src/pages/Browser.jsx
index 5b19999f0c..5277c6752b 100644
--- a/client/src/pages/Browser.jsx
+++ b/client/src/pages/Browser.jsx
@@ -3,7 +3,7 @@ import {
Globe, Play, Square, RefreshCw, Settings, Activity,
Monitor, Wifi, WifiOff, Clock, Cpu, MemoryStick,
FileText, ChevronDown, ChevronRight, ExternalLink,
- Mail, MessageSquare
+ Mail, MessageSquare, Download, FolderOpen
} from 'lucide-react';
import {
getBrowserStatus, getBrowserConfig, updateBrowserConfig,
@@ -50,6 +50,7 @@ export default function BrowserPage() {
const [config, setConfig] = useState(null);
const [configDraft, setConfigDraft] = useState(null);
const [navUrl, setNavUrl] = useState('');
+ const [showDownloads, setShowDownloads] = useState(true);
const fetchStatus = useCallback(async () => {
const data = await getBrowserStatus().catch(() => null);
@@ -503,6 +504,53 @@ export default function BrowserPage() {
</div>
)}
</div>
+
+ {/* Downloads */}
+ <div className="bg-port-card border border-port-border rounded-xl overflow-hidden">
+ <button
+ onClick={() => setShowDownloads(s => !s)}
+ className="w-full flex items-center justify-between p-4 text-left hover:bg-port-border/30 transition-colors"
+ >
+ <h3 className="text-lg font-semibold text-white flex items-center gap-2">
+ <Download size={20} className="text-port-accent" />
+ Downloads
+ {status?.downloads?.files?.length > 0 && (
+ <span className="ml-2 px-2 py-0.5 text-xs rounded-full bg-port-accent/20 text-port-accent">
+ {status.downloads.files.length}
+ </span>
+ )}
+ </h3>
+ {showDownloads ? <ChevronDown size={18} className="text-gray-400" /> : <ChevronRight size={18} className="text-gray-400" />}
+ </button>
+ {showDownloads && (
+ <div className="border-t border-port-border">
+ {status?.downloads?.downloadDir && (
+ <div className="px-4 py-2 bg-port-bg/50 border-b border-port-border flex items-center gap-2 text-xs text-gray-500">
+ <FolderOpen size={12} />
+ <span className="font-mono truncate">{status.downloads.downloadDir}</span>
+ </div>
+ )}
+ {!status?.downloads?.files || status.downloads.files.length === 0 ? (
+ <div className="p-4 text-sm text-gray-500">No downloads</div>
+ ) : (
+ <div className="divide-y divide-port-border">
+ {status.downloads.files.map(file => (
+ <div key={file.name} className="p-3 hover:bg-port-border/20 transition-colors">
+ <div className="flex items-start justify-between gap-2">
+ <div className="min-w-0">
+ <div className="text-sm font-medium text-white truncate">{file.name}</div>
+ <div className="text-xs text-gray-500 mt-0.5">
+ {formatBytes(file.size)} &middot; {new Date(file.modified).toLocaleString()}
+ </div>
+ </div>
+ </div>
+ </div>
+ ))}
+ </div>
+ )}
+ </div>
+ )}
+ </div>
</div>
{/* Sidebar */}
@@ -531,6 +579,10 @@ export default function BrowserPage() {
{status?.config?.autoConnect ? 'Yes' : 'No'}
</span>
</div>
+ <div className="flex items-center justify-between">
+ <span className="text-gray-400 text-sm">Downloads</span>
+ <span className="text-sm font-medium text-port-success">{status?.downloads?.files?.length ?? 0} files</span>
+ </div>
</div>
</div>
diff --git a/client/src/services/api.js b/client/src/services/api.js
index b3d03374c2..9036e67930 100644
--- a/client/src/services/api.js
+++ b/client/src/services/api.js
@@ -1668,6 +1668,7 @@ export const getBrowserProcess = () => request('/browser/process');
export const getBrowserPages = () => request('/browser/pages');
export const getBrowserVersion = () => request('/browser/version');
export const getBrowserLogs = (lines = 50) => request(`/browser/logs?lines=${lines}`);
+export const getBrowserDownloads = () => request('/browser/downloads');
export const navigateBrowser = (url) => request('/browser/navigate', {
method: 'POST',
body: JSON.stringify({ url })
diff --git a/server/lib/fileUtils.js b/server/lib/fileUtils.js
index dd2ec86204..a1f4d58874 100644
--- a/server/lib/fileUtils.js
+++ b/server/lib/fileUtils.js
@@ -39,6 +39,7 @@ export const PATHS = {
worktrees: join(__lib_dirname, '../../data/cos/worktrees'),
repos: join(__lib_dirname, '../../data/repos'),
browserProfile: join(__lib_dirname, '../../data/browser-profile'),
+ browserDownloads: join(__lib_dirname, '../../data/browser-downloads'),
digests: join(__lib_dirname, '../../data/cos/digests'),
promptSkills: join(__lib_dirname, '../../data/prompts/skills'),
promptSkillsJobs: join(__lib_dirname, '../../data/prompts/skills/jobs'),
diff --git a/server/routes/browser.js b/server/routes/browser.js
index 6485927f8a..02e854c276 100644
--- a/server/routes/browser.js
+++ b/server/routes/browser.js
@@ -16,7 +16,8 @@ const updateConfigSchema = z.object({
healthPort: z.number().int().min(1024).max(65535).optional(),
autoConnect: z.boolean().optional(),
headless: z.boolean().optional(),
- userDataDir: z.string().optional()
+ userDataDir: z.string().optional(),
+ downloadDir: z.string().optional()
});
// GET /api/browser - Full browser status
@@ -101,4 +102,10 @@ router.get('/logs', asyncHandler(async (req, res) => {
res.json(logs);
}));
+// GET /api/browser/downloads - List downloaded files
+router.get('/downloads', asyncHandler(async (req, res) => {
+ const downloads = await browserService.getDownloads();
+ res.json(downloads);
+}));
+
export default router;
diff --git a/server/services/browserService.js b/server/services/browserService.js
index d20c026e89..5ff981871a 100644
--- a/server/services/browserService.js
+++ b/server/services/browserService.js
@@ -4,7 +4,7 @@
* Stores config in data/browser-config.json
*/
-import { readFile, writeFile } from 'fs/promises';
+import { readFile, writeFile, readdir, stat } from 'fs/promises';
import { join } from 'path';
import { EventEmitter } from 'events';
import { ensureDir, safeJSONParse, PATHS } from '../lib/fileUtils.js';
@@ -15,6 +15,7 @@ const ECOSYSTEM_FILE = join(PATHS.root, 'ecosystem.config.cjs');
export const browserEvents = new EventEmitter();
const DEFAULT_PROFILE_DIR = PATHS.browserProfile;
+const DEFAULT_DOWNLOAD_DIR = PATHS.browserDownloads;
const DEFAULT_CONFIG = {
cdpPort: 5556,
@@ -22,7 +23,8 @@ const DEFAULT_CONFIG = {
healthPort: 5557,
autoConnect: true,
headless: true,
- userDataDir: DEFAULT_PROFILE_DIR
+ userDataDir: DEFAULT_PROFILE_DIR,
+ downloadDir: DEFAULT_DOWNLOAD_DIR
};
let cachedConfig = null;
@@ -233,15 +235,42 @@ export async function getCdpVersion() {
return response.json();
}
+// ---------- Downloads ----------
+
+export async function getDownloads() {
+ const config = await loadConfig();
+ const downloadDir = config.downloadDir || DEFAULT_DOWNLOAD_DIR;
+ const entries = await readdir(downloadDir).catch(() => []);
+ // Filter out hidden files and .crdownload (partial Chrome downloads)
+ const files = [];
+ for (const name of entries) {
+ if (name.startsWith('.') || name.endsWith('.crdownload')) continue;
+ const filePath = join(downloadDir, name);
+ const info = await stat(filePath).catch(() => null);
+ if (info?.isFile()) {
+ files.push({
+ name,
+ size: info.size,
+ modified: info.mtime.toISOString(),
+ path: filePath
+ });
+ }
+ }
+ // Most recent first
+ files.sort((a, b) => b.modified.localeCompare(a.modified));
+ return { downloadDir, files };
+}
+
// ---------- Full combined status ----------
export async function getFullStatus() {
- const [health, process, pages, version, config] = await Promise.all([
+ const [health, process, pages, version, config, downloads] = await Promise.all([
getHealthStatus(),
getProcessStatus(),
getOpenPages().catch(() => []),
getCdpVersion().catch(() => null),
- getConfig()
+ getConfig(),
+ getDownloads().catch(() => ({ downloadDir: DEFAULT_DOWNLOAD_DIR, files: [] }))
]);
return {
@@ -250,6 +279,7 @@ export async function getFullStatus() {
pages,
pageCount: pages.length,
version,
- config
+ config,
+ downloads
};
}