Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

fix(daemon): a folder in config.json may start with ~\ on Windows; one expandHome instead of three

Shahriar709c986d1aa5
diff --git a/src/daemon/agent/skills.ts b/src/daemon/agent/skills.ts
index 157f287..efcb1b9 100644
--- a/src/daemon/agent/skills.ts
+++ b/src/daemon/agent/skills.ts
@@ -1,6 +1,6 @@
import { existsSync, readFileSync, readdirSync } from 'node:fs';
import { homedir } from 'node:os';
-import { dirname, isAbsolute, join } from 'node:path';
+import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { RunContext } from '@/lib/actions/protocol';
import {
@@ -13,6 +13,7 @@ import {
} from '@/lib/skills/format';
import { stateDir } from '../lockfile';
import { log } from '../log';
+import { expandHome } from '../paths';
import { readAgentConfig } from './config';
export type SkillSource = 'bundled' | 'user' | 'uploaded';
@@ -38,12 +39,6 @@ export function uploadedSkillsDir(): string {
return join(homedir(), 'browsentic', 'skills');
}
-function expandHome(p: string): string {
- if (p === '~') return homedir();
- if (p.startsWith('~/')) return join(homedir(), p.slice(2));
- return isAbsolute(p) ? p : join(homedir(), p);
-}
-
function skillDirs(): { dir: string; source: SkillSource }[] {
return [
{ dir: bundledDir, source: 'bundled' },
diff --git a/src/daemon/downloads.ts b/src/daemon/downloads.ts
index a8bcf97..3250246 100644
--- a/src/daemon/downloads.ts
+++ b/src/daemon/downloads.ts
@@ -12,7 +12,7 @@ import {
writeFileSync,
} from 'node:fs';
import { homedir } from 'node:os';
-import { basename, isAbsolute, join } from 'node:path';
+import { basename, join } from 'node:path';
import {
DOWNLOAD_TTL_DAYS,
MAX_ATTACH_BYTES,
@@ -25,6 +25,7 @@ import { failure, success, type ActionResult } from '@/lib/actions/protocol';
import { hostAllowed } from './guardrails';
import { readAgentConfig } from './agent/config';
import { stateDir } from './lockfile';
+import { expandHome } from './paths';
import { log } from './log';
/**
@@ -68,12 +69,6 @@ export function downloadDir(): string {
return join(homedir(), 'browsentic', 'download');
}
-function expandHome(p: string): string {
- if (p === '~') return homedir();
- if (p.startsWith('~/')) return join(homedir(), p.slice(2));
- return isAbsolute(p) ? p : join(homedir(), p);
-}
-
function readIndex(): DownloadRecord[] {
try {
const parsed = JSON.parse(readFileSync(indexPath, 'utf8')) as unknown;
diff --git a/src/daemon/paths.ts b/src/daemon/paths.ts
index bcf1acb..67b9990 100644
--- a/src/daemon/paths.ts
+++ b/src/daemon/paths.ts
@@ -1,6 +1,6 @@
import { existsSync } from 'node:fs';
import { homedir } from 'node:os';
-import { dirname, join } from 'node:path';
+import { dirname, isAbsolute, join } from 'node:path';
import { fileURLToPath } from 'node:url';
/**
@@ -15,6 +15,16 @@ export const stateDir = process.env.BROWSENTIC_HOME ?? join(homedir(), '.browsen
*/
export const userDir = join(homedir(), 'browsentic');
+/**
+ * A folder named in config.json. `~` is the home folder, and so is the start of `~/…`, or of `~\…` on
+ * Windows, where that is how a path is written; a relative path starts there too.
+ */
+export function expandHome(path: string, platform: NodeJS.Platform = process.platform): string {
+ if (path === '~') return homedir();
+ if (path.startsWith('~/') || (platform === 'win32' && path.startsWith('~\\'))) return join(homedir(), path.slice(2));
+ return isAbsolute(path) ? path : join(homedir(), path);
+}
+
/**
* Where `browsentic setup` installs the extension for the browser to load.
*
diff --git a/src/daemon/screenshots.test.ts b/src/daemon/screenshots.test.ts
index 3a00127..e835c58 100644
--- a/src/daemon/screenshots.test.ts
+++ b/src/daemon/screenshots.test.ts
@@ -4,6 +4,7 @@ import { basename, dirname, join } from 'node:path';
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';
import { configPath } from './agent/config';
import { uploadedSkillsDir } from './agent/skills';
+import { expandHome } from './paths';
import { saveScreenshot, screenshotDir } from './screenshots';
import { bits, modeOf } from './test/modes';
@@ -79,6 +80,13 @@ describe('where screenshots go', () => {
expect(dirs).toEqual([join(homedir(), 'Pictures', 'Browsentic'), join(homedir(), 'Pictures', 'Browsentic'), '/Volumes/Shots', homedir()]);
});
+ test('on Windows a folder may start with ~\\ as well', () => {
+ expect([expandHome('~\\Pictures', 'win32'), expandHome('~\\Pictures', 'darwin')]).toEqual([
+ join(homedir(), 'Pictures'),
+ join(homedir(), '~\\Pictures'),
+ ]);
+ });
+
test('a blank setting is the default', () => {
configure({ screenshotDir: ' ' });
expect(screenshotDir()).toBe(defaultDir);
diff --git a/src/daemon/screenshots.ts b/src/daemon/screenshots.ts
index c88f143..2e213ab 100644
--- a/src/daemon/screenshots.ts
+++ b/src/daemon/screenshots.ts
@@ -1,9 +1,10 @@
import { randomBytes } from 'node:crypto';
import { chmodSync, mkdirSync, writeFileSync } from 'node:fs';
import { homedir } from 'node:os';
-import { basename, isAbsolute, join, resolve, sep } from 'node:path';
+import { basename, join, resolve, sep } from 'node:path';
import { readAgentConfig } from './agent/config';
import { uploadedSkillsDir } from './agent/skills';
+import { expandHome } from './paths';
export function saveScreenshot(dataUrl: string, opts: { filename?: string; dir?: string } = {}): string {
const { mime, bytes } = parseDataUrl(dataUrl);
@@ -33,12 +34,6 @@ export function screenshotDir(): string {
return join(homedir(), 'browsentic', 'screenshot');
}
-function expandHome(p: string): string {
- if (p === '~') return homedir();
- if (p.startsWith('~/')) return join(homedir(), p.slice(2));
- return isAbsolute(p) ? p : join(homedir(), p);
-}
-
function parseDataUrl(dataUrl: string): { mime: string; bytes: Buffer } {
const match = /^data:([^;,]+);base64,(.*)$/s.exec(dataUrl);
if (!match) throw new Error('screenshot result was not a base64 data URL');