From 2601c90bc0ec54f1e6234d05112c99c458d4ae5e Mon Sep 17 00:00:00 2001 From: Uttkarsh <38376852+uttkarsh-26@users.noreply.github.com> Date: Mon, 12 Oct 2026 00:09:18 +0530 Subject: fix: browser_download no longer hijacks the user's own downloads (#33) Browser.setDownloadBehavior was sent without a browserContextId, so the override applied to the user's default context and outlived the session. browser_download now takes restore:true, tracks the override this process set, and a clean session shutdown restores Chrome's default with a bounded call that is skipped when the browser is already gone. Co-Authored-By: Claude Fable 5.1 --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index a2e0c11..5818a5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { readPin } from "./profile/store"; import { type BrowserState, createStatePersister, defaultState, restoreState } from "./state"; import { registerAllTools } from "./registry"; import { cleanupTempDirs } from "./util/truncate"; +import { restoreDownloadBehavior } from "./domains/files"; import { createDaemonTransport } from "./daemon/transport"; import { setDebugClicks } from "./util/debug"; import { asBoolean, asString } from "./util/guards"; @@ -132,6 +133,11 @@ export default function browserHarnessExtension(pi: ExtensionAPI): void { pi.on("session_shutdown", async () => { if (client) { try { + // Warn but keep going: detach and tab cleanup still have to run, and a throw here would skip both. + const restored = await restoreDownloadBehavior(client); + if (!restored.success) { + console.warn(`[pi-browser-harness] ${restored.error.message}`); + } await client.detach(); await client.closeOwnedTabs(); } catch (e) { -- cgit v1.2.3