fix(webui): batch download no longer flashes a tab per file (#287)

startDownload() used <a target="_blank" download> 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.
This commit is contained in:
Yiling-J
2026-08-09 17:09:01 +08:00
committed by GitHub
parent 8080acfb2e
commit e67552d8bd
@@ -303,13 +303,17 @@ export function useFileActions({
for (let i = 0; i < files.length; i += batchSize) { for (let i = 0; i < files.length; i += batchSize) {
const chunk = files.slice(i, i + batchSize) const chunk = files.slice(i, i + batchSize)
for (const file of chunk) { for (const file of chunk) {
const a = document.createElement('a') // Use a hidden iframe instead of an anchor with target="_blank".
a.href = file.url // Download URLs respond with Content-Disposition: attachment, so the
a.download = file.name // browser starts the download in the background: no flash of a tab
a.target = '_blank' // that opens and auto-closes. A failed/expired link renders inside
document.body.appendChild(a) // the hidden iframe instead of navigating the SPA tab away.
a.click() const iframe = document.createElement('iframe')
document.body.removeChild(a) 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) { if (i + batchSize < files.length) {
await delay(600) await delay(600)