refactor: delete exports and knobs that nothing calls isInternalUrl, SPECIAL_KEYS, andThen and mapErr had no callers in src or test. BrowserState.remoteBrowserId was parsed on restore and never written — the field that is actually read lives on DaemonStatus. IpcServer.disconnectClient and IpcServer.clients() were unreachable, as was EventRouter.allClients and a write-only lineCount counter. DAEMON_STALE_SOCKET_CLEANUP was a hardcoded true with an if around it, so the unlink now runs unconditionally. CdpBridge.isAlive and getSessionOwner look equally dead from src/ alone, but test/manual/bridge-test.ts drives both — they are the only seams that suite has, so they stay. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@@ -46,13 +46,6 @@ readonly namespace: string;
readonly remoteBrowserId?: string; }; -const INTERNAL_PREFIXES: ReadonlyArray<string> = [ - "chrome://", "chrome-untrusted://", "devtools://", "chrome-extension://", "about:", -]; - -export const isInternalUrl = (url: string): boolean => - INTERNAL_PREFIXES.some((p) => url.startsWith(p)); - export const isCdpRawMessage = (v: unknown): v is CdpRawMessage => { if (!isRecord(v)) return false; const id = v["id"];
@@ -17,8 +17,6 @@ start(): Promise<void>;
stop(): Promise<void>; handleRequest(req: WireRequest, clientId: string, send: SendToClient): Promise<void>; isAlive(): boolean; - recordSession(clientId: string, sessionId: string): void; - releaseSession(sessionId: string): void; getSessionOwner(sessionId: string): string | undefined; removeClient(clientId: string): void; onEvent(handler: EventHandler): void;@@ -96,10 +94,6 @@ if (event.sessionId) {
const owner = this.owners.get(event.sessionId); return owner ? [owner] : []; } - return [...this.clientSessions.keys()]; - } - - allClients(): string[] { return [...this.clientSessions.keys()]; } }@@ -357,8 +351,6 @@ start,
stop, handleRequest, isAlive: () => ws !== null && ws.readyState === WebSocket.OPEN, - recordSession: (cid, sid) => router.record(cid, sid), - releaseSession: (sid) => router.release(sid), getSessionOwner: (sid) => router.getOwner(sid), removeClient: (cid) => { mux.clearClient(cid); router.removeClient(cid); }, onEvent: (h) => { eventHandler = h; },
@@ -105,8 +105,6 @@ export const DAEMON_IDLE_TIMEOUT_MS = 30 * 60 * 1000;
export const DAEMON_MAX_CLIENTS = 16; -export const DAEMON_STALE_SOCKET_CLEANUP = true; - export const CDP_CONNECT_TIMEOUT_MS = 10_000; export const CDP_COMMAND_TIMEOUT_MS = 10_000;
@@ -7,7 +7,6 @@ type WireControl,
isWireMessage, DAEMON_SOCKET_PATH, DAEMON_MAX_CLIENTS, - DAEMON_STALE_SOCKET_CLEANUP, } from "./protocol"; export type ClientSocket = {@@ -29,8 +28,6 @@ onConnect(handler: ConnectionHandler): void;
onDisconnect(handler: ConnectionHandler): void; send(clientId: string, msg: WireMessage): void; broadcast(msg: WireMessage): void; - disconnectClient(clientId: string): void; - clients(): ReadonlyMap<string, ClientSocket>; clientCount(): number; };@@ -45,11 +42,9 @@ let nextTempId = 1;
const start = (): Promise<void> => new Promise((resolve, reject) => { - if (DAEMON_STALE_SOCKET_CLEANUP) { - try { - unlinkSync(DAEMON_SOCKET_PATH); - } catch {} - } + try { + unlinkSync(DAEMON_SOCKET_PATH); + } catch {} server = createServer({ pauseOnConnect: false }, (socket: Socket) => { if (clients.size >= DAEMON_MAX_CLIENTS) {@@ -63,10 +58,7 @@ let currentClient: ClientSocket = { id: tempId, socket, rl, registered: false };
sockets.set(tempId, currentClient); - let lineCount = 0; - rl.on("line", (line: string) => { - lineCount++; let msg: WireMessage | null; try { const parsed: unknown = JSON.parse(line);@@ -178,12 +170,6 @@ for (const [clientId] of clients) {
this.send(clientId, msg); } }, - disconnectClient(clientId) { - const client = clients.get(clientId); - if (!client) return; - client.socket.destroy(); - }, - clients: (): ReadonlyMap<string, ClientSocket> => clients, clientCount: (): number => clients.size, }; };
@@ -3,7 +3,6 @@ import { asArrayOf, asNumber, asString, isRecord } from "./util/guards";
export type BrowserState = { readonly namespace: string; - readonly remoteBrowserId?: string; readonly ownedTargetIds?: ReadonlyArray<string>; readonly harnessWindowTargetId?: string; readonly harnessWindowId?: number;@@ -21,13 +20,11 @@
const asPersistedState = (v: unknown): Partial<BrowserState> | undefined => { if (!isRecord(v)) return undefined; const namespace = asString(v["namespace"]); - const remoteBrowserId = asString(v["remoteBrowserId"]); const ownedTargetIds = asArrayOf(v["ownedTargetIds"], asString); const harnessWindowTargetId = asString(v["harnessWindowTargetId"]); const harnessWindowId = asNumber(v["harnessWindowId"]); return { ...(namespace !== undefined ? { namespace } : {}), - ...(remoteBrowserId !== undefined ? { remoteBrowserId } : {}), ...(ownedTargetIds !== undefined ? { ownedTargetIds } : {}), ...(harnessWindowTargetId !== undefined ? { harnessWindowTargetId } : {}), ...(harnessWindowId !== undefined ? { harnessWindowId } : {}),
@@ -4,7 +4,5 @@ ArrowLeft: 37, ArrowUp: 38, ArrowRight: 39, ArrowDown: 40,
Home: 36, End: 35, PageUp: 33, PageDown: 34, }; -export const SPECIAL_KEYS: ReadonlyArray<string> = Object.keys(VIRTUAL_KEY_CODES); - export const virtualKeyCode = (key: string): number => VIRTUAL_KEY_CODES[key] ?? (key.length === 1 ? key.charCodeAt(0) : 0);
@@ -7,9 +7,3 @@ export const err = <E>(error: E): Result<never, E> => ({ success: false, error });
export const map = <T, U, E>(r: Result<T, E>, f: (t: T) => U): Result<U, E> => r.success ? ok(f(r.data)) : r; - -export const andThen = <T, U, E>(r: Result<T, E>, f: (t: T) => Result<U, E>): Result<U, E> => - r.success ? f(r.data) : r; - -export const mapErr = <T, E, F>(r: Result<T, E>, f: (e: E) => F): Result<T, F> => - r.success ? r : err(f(r.error));