From e67552d8bdd2bc5cfdfbced9f9217d39c59548f0 Mon Sep 17 00:00:00 2001 From: Yiling-J Date: Sun, 9 Aug 2026 17:09:01 +0800 Subject: [PATCH] fix(webui): batch download no longer flashes a tab per file (#287) startDownload() used anchors, which made Chrome open a new tab for every file that then auto-closed as soon as the download started (Content-Disposition: attachment). Replace with hidden iframes: downloads start in the background without opening tabs, and a failed/expired link renders inside the hidden iframe instead of navigating the SPA tab away. --- .../file-browser/use-file-actions.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/webui/components/file-browser/use-file-actions.ts b/packages/webui/components/file-browser/use-file-actions.ts index a84c99f2..49c47c20 100644 --- a/packages/webui/components/file-browser/use-file-actions.ts +++ b/packages/webui/components/file-browser/use-file-actions.ts @@ -303,13 +303,17 @@ export function useFileActions({ for (let i = 0; i < files.length; i += batchSize) { const chunk = files.slice(i, i + batchSize) for (const file of chunk) { - const a = document.createElement('a') - a.href = file.url - a.download = file.name - a.target = '_blank' - document.body.appendChild(a) - a.click() - document.body.removeChild(a) + // Use a hidden iframe instead of an anchor with target="_blank". + // Download URLs respond with Content-Disposition: attachment, so the + // browser starts the download in the background: no flash of a tab + // that opens and auto-closes. A failed/expired link renders inside + // the hidden iframe instead of navigating the SPA tab away. + const iframe = document.createElement('iframe') + iframe.style.display = 'none' + iframe.src = file.url + document.body.appendChild(iframe) + // Remove the iframe once the download has had time to start. + window.setTimeout(() => iframe.remove(), 60_000) } if (i + batchSize < files.length) { await delay(600)