aboutsummaryrefslogtreecommitdiff
path: root/extensions/chrome-profile-bridge/index.ts
diff options
context:
space:
mode:
authorTianren Dong <tianrendong.dtr@gmail.com>2026-05-16 13:03:51 -0400
committerTianren Dong <tianrendong.dtr@gmail.com>2026-05-16 13:03:51 -0400
commitea567819d835d4704d9fb38cd114e0e5b231759e (patch)
treeb0169202354482907dd95e51fcc94018d9e4e491 /extensions/chrome-profile-bridge/index.ts
parentfcae5b188baa1bdfed48208d7cfc2b711af4aae3 (diff)
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.
Diffstat (limited to 'extensions/chrome-profile-bridge/index.ts')
-rw-r--r--extensions/chrome-profile-bridge/index.ts19
1 files changed, 18 insertions, 1 deletions
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<string, unknown>, timeoutMs: number, signal?: AbortSignal): Promise<unknown> {
+ // 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.");
}