From 4d7ff1a0e7f636f786fe45565e14df48f1e870e7 Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Tue, 18 Aug 2026 15:55:48 +0800 Subject: [PATCH] fix: revoke object URL on download completion --- background.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index ef929f8..5382615 100644 --- a/background.js +++ b/background.js @@ -33,6 +33,17 @@ async function generatePdf(data) { const url = URL.createObjectURL(blob); const name = (data.header && data.header.fullName) || 'Student'; const filename = 'Study Load - ' + name + '.pdf'; - await browser.downloads.download({ url, filename, saveAs: true }); - setTimeout(() => URL.revokeObjectURL(url), 10000); + try { + const id = await browser.downloads.download({ url, filename, saveAs: true }); + const onChanged = (delta) => { + if (delta.id === id && delta.state && (delta.state.current === 'complete' || delta.state.current === 'interrupted')) { + browser.downloads.onChanged.removeListener(onChanged); + URL.revokeObjectURL(url); + } + }; + browser.downloads.onChanged.addListener(onChanged); + } catch (err) { + URL.revokeObjectURL(url); + throw err; + } }