aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/bridge.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-06 23:15:08 +0530
committeramankumarsingh77 <amankumarsingh7702@gmail.com>2026-07-06 23:15:08 +0530
commit2ba584869909363705b9f1b7232cf2bd89ba9cff (patch)
tree7d29ac75c9c32e8cb0bfc62aff2cf844c2988654 /src/daemon/bridge.ts
parent26daf87896d6645fe9be71460d2868755a4f939f (diff)
fix: stale socket detection prevents daemon spawn after crash
isDaemonRunning() only checked file existence of the Unix socket. A dead daemon leaves a stale socket, causing ensureDaemon() to skip spawning and client.start() to fail with 'Chrome not connected'. Replace with a liveness probe: connect, register, verify ack, then disconnect. On failure, clean up the stale socket. Also makes bridge handleRequest async to poll for Chrome connection for up to 15s before rejecting.
Diffstat (limited to 'src/daemon/bridge.ts')
-rw-r--r--src/daemon/bridge.ts16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/daemon/bridge.ts b/src/daemon/bridge.ts
index c2c1355..33ef63b 100644
--- a/src/daemon/bridge.ts
+++ b/src/daemon/bridge.ts
@@ -29,7 +29,7 @@ export type CdpBridge = {
* are initialized (not when Chrome is connected — that may take retries). */
start(): Promise<void>;
stop(): Promise<void>;
- handleRequest(req: WireRequest, clientId: string, send: SendToClient): void;
+ handleRequest(req: WireRequest, clientId: string, send: SendToClient): Promise<void>;
/** True when the Chrome WebSocket is open and ready. */
isAlive(): boolean;
recordSession(clientId: string, sessionId: string): void;
@@ -339,11 +339,21 @@ export const createCdpBridge = (): CdpBridge => {
wsUrl = null;
};
- const handleRequest = (
+ const handleRequest = async (
req: WireRequest,
clientId: string,
send: SendToClient,
- ): void => {
+ ): Promise<void> => {
+ // ponytail: wait for Chrome to connect (user may still be clicking "Allow").
+ // Bridge retries in background; this polls so the client doesn't fail first try.
+ if (!ws || ws.readyState !== WebSocket.OPEN) {
+ const deadline = Date.now() + 15_000;
+ while (Date.now() < deadline) {
+ await new Promise((r) => setTimeout(r, 250));
+ if (ws && ws.readyState === WebSocket.OPEN) break;
+ }
+ }
+
if (!ws || ws.readyState !== WebSocket.OPEN) {
send(clientId, {
type: "response",