aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-28 21:47:21 +0530
committerAman Kumar <145339995+amankumarsingh77@users.noreply.github.com>2026-08-02 19:12:46 +0530
commitaedbb88a8025851067be9f77ec406b29d65599a8 (patch)
tree8e62b333e4aad20998056614e19acd34ff6abc3b /src
parentea11182a0e8cb62d208b5b53a60c98c8bdef9e9a (diff)
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>
Diffstat (limited to 'src')
-rw-r--r--src/cdp/types.ts7
-rw-r--r--src/daemon/bridge.ts8
-rw-r--r--src/daemon/protocol.ts2
-rw-r--r--src/daemon/server.ts20
-rw-r--r--src/state.ts3
-rw-r--r--src/util/keycodes.ts2
-rw-r--r--src/util/result.ts6
7 files changed, 3 insertions, 45 deletions
diff --git a/src/cdp/types.ts b/src/cdp/types.ts
index 33ab202..984b930 100644
--- a/src/cdp/types.ts
+++ b/src/cdp/types.ts
@@ -46,13 +46,6 @@ export type DaemonStatus = {
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"];
diff --git a/src/daemon/bridge.ts b/src/daemon/bridge.ts
index 95f6888..d9a54ed 100644
--- a/src/daemon/bridge.ts
+++ b/src/daemon/bridge.ts
@@ -17,8 +17,6 @@ export type CdpBridge = {
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;
@@ -98,10 +96,6 @@ class EventRouter {
}
return [...this.clientSessions.keys()];
}
-
- allClients(): string[] {
- return [...this.clientSessions.keys()];
- }
}
export const createCdpBridge = (): CdpBridge => {
@@ -357,8 +351,6 @@ export const createCdpBridge = (): CdpBridge => {
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; },
diff --git a/src/daemon/protocol.ts b/src/daemon/protocol.ts
index 43c89de..2501980 100644
--- a/src/daemon/protocol.ts
+++ b/src/daemon/protocol.ts
@@ -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;
diff --git a/src/daemon/server.ts b/src/daemon/server.ts
index 7c78372..142bddb 100644
--- a/src/daemon/server.ts
+++ b/src/daemon/server.ts
@@ -7,7 +7,6 @@ import {
isWireMessage,
DAEMON_SOCKET_PATH,
DAEMON_MAX_CLIENTS,
- DAEMON_STALE_SOCKET_CLEANUP,
} from "./protocol";
export type ClientSocket = {
@@ -29,8 +28,6 @@ export type IpcServer = {
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 @@ export const createIpcServer = (): IpcServer => {
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 @@ export const createIpcServer = (): IpcServer => {
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 @@ export const createIpcServer = (): IpcServer => {
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,
};
};
diff --git a/src/state.ts b/src/state.ts
index 71f164b..8f25dc4 100644
--- a/src/state.ts
+++ b/src/state.ts
@@ -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 @@ export const persistState = (pi: ExtensionAPI, state: BrowserState): void => {
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 } : {}),
diff --git a/src/util/keycodes.ts b/src/util/keycodes.ts
index 2445eaf..68be059 100644
--- a/src/util/keycodes.ts
+++ b/src/util/keycodes.ts
@@ -4,7 +4,5 @@ const VIRTUAL_KEY_CODES: Readonly<Record<string, number>> = {
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);
diff --git a/src/util/result.ts b/src/util/result.ts
index ca57c2a..d57fea7 100644
--- a/src/util/result.ts
+++ b/src/util/result.ts
@@ -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));