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): let the unpacked extension wake the daemon on Windows before it has ever paired, naming it as Chrome does there — the SHA-256 of the UTF-16 path with its drive letter raised

Shahriar72fee07d43ab
diff --git a/src/daemon/native-host.test.ts b/src/daemon/native-host.test.ts
index 356e336..d905e37 100644
--- a/src/daemon/native-host.test.ts
+++ b/src/daemon/native-host.test.ts
@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
NATIVE_HOST_NAME,
STOPPED_REPLY,
+ allowedOrigins,
answerNativeMessage,
decodeNativeMessage,
encodeNativeMessage,
@@ -22,10 +23,26 @@ import { bits, modeOf } from './test/modes';
describe('unpackedExtensionOrigin', () => {
it('names the folder the way Chrome does', () => {
- expect(unpackedExtensionOrigin('/Users/shahriar/browsentic/extension/chrome-mv3')).toBe(
+ expect(unpackedExtensionOrigin('/Users/shahriar/browsentic/extension/chrome-mv3', 'darwin')).toBe(
'chrome-extension://pplbfkdfiimmogofmehpibbmldcefgpc/',
);
});
+
+ it('hashes a Windows path as UTF-16, whichever case the drive letter was typed in', () => {
+ const upper = unpackedExtensionOrigin('C:\\Users\\me\\browsentic\\extension\\chrome-mv3', 'win32');
+
+ expect(unpackedExtensionOrigin('c:\\Users\\me\\browsentic\\extension\\chrome-mv3', 'win32')).toBe(upper);
+ expect(unpackedExtensionOrigin('C:\\Users\\me\\browsentic\\extension\\chrome-mv3', 'linux')).not.toBe(upper);
+ expect(unpackedExtensionOrigin('C:\\Users\\Me\\browsentic\\extension\\chrome-mv3', 'win32')).not.toBe(upper);
+ });
+});
+
+describe('allowedOrigins', () => {
+ it('lets the unpacked extension start the daemon before it has ever paired, on Windows too', () => {
+ for (const platform of ['darwin', 'linux', 'win32'] as const) {
+ expect(allowedOrigins(platform)).toContain(unpackedExtensionOrigin(extensionDir(), platform));
+ }
+ });
});
describe('hostTargets', () => {
@@ -126,7 +143,7 @@ describe('registering the host', () => {
expect(modeOf(installed.launcher)).toBe(bits(0o755));
expect(JSON.parse(readFileSync(manifest, 'utf8'))).toMatchObject({
path: installed.launcher,
- allowed_origins: [unpackedExtensionOrigin(extensionDir())],
+ allowed_origins: [unpackedExtensionOrigin(extensionDir(), 'linux')],
});
expect(registeredBrowsers('linux')).toEqual(['Chrome']);
});
diff --git a/src/daemon/native-host.ts b/src/daemon/native-host.ts
index 81e1a5c..6a9c032 100644
--- a/src/daemon/native-host.ts
+++ b/src/daemon/native-host.ts
@@ -87,9 +87,15 @@ export function hostTargets(platform: NodeJS.Platform = process.platform, home =
}));
}
-/** Chrome names an unpacked extension after its folder: the SHA-256 of the path, spelled in a–p. */
-export function unpackedExtensionOrigin(dir: string): string {
- const hex = createHash('sha256').update(dir).digest('hex').slice(0, 32);
+/**
+ * Chrome names an unpacked extension after its folder: the SHA-256 of the path, spelled in a–p.
+ * On Windows it hashes the path as UTF-16, with a lower-case drive letter raised first
+ * (`crx_file::id_util::MaybeNormalizePath`).
+ */
+export function unpackedExtensionOrigin(dir: string, platform: NodeJS.Platform = process.platform): string {
+ const path =
+ platform === 'win32' ? Buffer.from(dir.replace(/^[a-z](?=:)/, (drive) => drive.toUpperCase()), 'utf16le') : dir;
+ const hex = createHash('sha256').update(path).digest('hex').slice(0, 32);
const id = [...hex].map((digit) => String.fromCharCode(97 + parseInt(digit, 16))).join('');
return `chrome-extension://${id}/`;
}
@@ -100,8 +106,8 @@ export function allowedOrigins(platform: NodeJS.Platform = process.platform): st
const paired = listSessions()
.map((session) => session.origin)
.filter((origin) => origin.startsWith('chrome-extension://'));
- const unpacked = platform === 'win32' ? [] : [unpackedExtensionOrigin(extensionDir(readAgentConfig().extensionDir))];
- return [...new Set([...unpacked, ...paired].map(asOrigin))].sort();
+ const unpacked = unpackedExtensionOrigin(extensionDir(readAgentConfig().extensionDir), platform);
+ return [...new Set([unpacked, ...paired].map(asOrigin))].sort();
}
export function hostManifest(family: Family, launcher: string, origins: readonly string[]): Record<string, unknown> {