From ea567819d835d4704d9fb38cd114e0e5b231759e Mon Sep 17 00:00:00 2001 From: Tianren Dong Date: Sat, 16 May 2026 13:03:51 -0400 Subject: 0.17.3: daemon self-heal on missing-daemon fetch failure In 0.17.x the daemon is a separate process that can idle-shut-down (10 min idle) or be killed externally while Pi sessions are running. Without self-heal, the next /chrome onboard or chrome_* call surfaces 'fetch failed' instead of recovering. bridge.admin() now catches the failed fetch, re-runs ensureDaemonRunning (probe -> spawn if missing), and retries once. bridge.sendViaOwner() pre-probes /status and spawns the daemon if missing before issuing the signed /command. Net effect: a missing daemon transparently respawns instead of bubbling fetch failed up to the user. --- .../browser-extension/manifest.json | 2 +- extensions/chrome-profile-bridge/index.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'extensions') diff --git a/extensions/chrome-profile-bridge/browser-extension/manifest.json b/extensions/chrome-profile-bridge/browser-extension/manifest.json index d3db49e..b3fcd7a 100644 --- a/extensions/chrome-profile-bridge/browser-extension/manifest.json +++ b/extensions/chrome-profile-bridge/browser-extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Pi Chrome Connector", - "version": "0.17.2", + "version": "0.17.3", "description": "Lets Pi control tabs in Chrome via a local connector at 127.0.0.1.", "permissions": [ "tabs", diff --git a/extensions/chrome-profile-bridge/index.ts b/extensions/chrome-profile-bridge/index.ts index 820c7d7..718012a 100644 --- a/extensions/chrome-profile-bridge/index.ts +++ b/extensions/chrome-profile-bridge/index.ts @@ -923,7 +923,17 @@ class ChromeProfileBridge { const sig = this.auth.signPeerRequest("POST", "/admin", payload); if (sig) headers[AUTH_HEADER] = sig; } - const response = await fetch(`${this.url}/admin`, { method: "POST", headers, body: payload }); + const doFetch = () => fetch(`${this.url}/admin`, { method: "POST", headers, body: payload }); + let response: Response; + try { response = await doFetch(); } + catch (error) { + // Daemon isn't reachable. Self-heal by re-running the spawn path, then retry once. + // Covers the common case where the daemon idle-shut-down since the Pi session started + // (or was killed manually) but the Pi-side bridge still thinks mode === "client". + console.warn(`pi-chrome: /admin fetch failed (${(error as Error).message}); re-spawning daemon and retrying`); + await this.ensureDaemonRunning(); + response = await doFetch(); + } const respText = await response.text(); // Verify owner sig when present (paired state). For pre-pair calls, no sig to verify. if (this.auth.paired) { @@ -1011,6 +1021,13 @@ class ChromeProfileBridge { } private async sendViaOwner(action: string, params: Record, timeoutMs: number, signal?: AbortSignal): Promise { + // Self-heal: re-spawn the daemon if it's gone. Cheap when daemon is up (a no-op since + // the version probe inside ensureDaemonRunning returns compatible immediately). + try { + const probed = probeBridgeStatus(this.host, this.port); + if (!probed) await this.ensureDaemonRunning(); + } catch { /* fall through to the fetch — will surface a clearer error if anything is + actually broken. */ } if (!this.auth.paired) { throw new Error("Chrome bridge not paired with this Pi config. Run /chrome pair in the Pi session that owns the bridge first."); } -- cgit v1.2.3