Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(browser): bind session-only navigation to its first resource tab

zszz33ec492b78a1f
diff --git a/apps/desktop/electron/main/browser-host.ts b/apps/desktop/electron/main/browser-host.ts
index b641fbd19..8c192d206 100644
--- a/apps/desktop/electron/main/browser-host.ts
+++ b/apps/desktop/electron/main/browser-host.ts
@@ -208,8 +208,9 @@ export class BrowserHost {
const id = sessionId?.trim();
const target = location.trim();
if (!id || !target) return;
- if (this.selectedTabs.has(id)) {
- const key = this.key(id, this.selectedTabs.get(id) ?? null);
+ const tabId = this.selectedTabs.get(id);
+ if (tabId != null) {
+ const key = this.key(id, tabId);
this.locations.set(key, target);
if (this.active?.key !== key) this.pendingTabs.add(key);
} else {
diff --git a/apps/desktop/test/browser-host-session.test.mjs b/apps/desktop/test/browser-host-session.test.mjs
index 4a0e24b2e..2d41bdf6b 100644
--- a/apps/desktop/test/browser-host-session.test.mjs
+++ b/apps/desktop/test/browser-host-session.test.mjs
@@ -93,6 +93,11 @@ test("background navigation targets that session's last selected tab", async ()
await h.host.navigate({ url: "https://fixture.invalid/queued" }, "C");
await open(h, "C", "c", "old.html");
assert.equal(h.host.getState().url, "https://fixture.invalid/queued");
+ h.host.setChromeSession("E"); // A session may exist without a concrete resource tab.
+ h.host.setChromeSession("A", "a");
+ await h.host.navigate({ url: "https://fixture.invalid/first-e" }, "E");
+ await open(h, "E", "e", "old-e.html");
+ assert.equal(h.host.getState().url, "https://fixture.invalid/first-e");
h.host.setChromeSession("C", "blank");
assert.equal(h.host.getState(), null);
});