/** * Unpacked extensions for the Jarvis Chromium window. * Playwright starts with --disable-extensions, so these are loaded explicitly. */ import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; export const BROWSER_EXTENSIONS = [ { id: 'ublock-origin-lite', name: 'uBlock Origin Lite' }, { id: 'dark-reader', name: 'Dark Reader' }, ]; export function extensionRoot(env = process.env) { const override = String(env.JARVIS_BROWSER_EXTENSIONS || '').trim(); if (override) return override; const state = env.XDG_STATE_HOME || path.join(os.homedir(), '.local/state'); return path.join(state, 'jarvis', 'browser', 'extensions'); } export function installedExtensionDirs(root = extensionRoot()) { const dirs = []; for (const ext of BROWSER_EXTENSIONS) { const dir = path.join(root, ext.id); try { if (fs.existsSync(path.join(dir, 'manifest.json'))) dirs.push(dir); } catch { // A missing or unreadable extension is skipped so the browser still starts. } } return dirs; } export function extensionLaunch(dirs = installedExtensionDirs()) { const list = (Array.isArray(dirs) ? dirs : []).filter(Boolean); if (!list.length) return { args: [], ignoreDefaultArgs: undefined, extensions: [] }; const joined = list.join(','); return { args: [ `--disable-extensions-except=${joined}`, `--load-extension=${joined}`, ], ignoreDefaultArgs: ['--disable-extensions'], extensions: list.map((dir) => path.basename(dir)), }; }