diff --git a/index.html b/index.html index 89a78f4..9945064 100644 --- a/index.html +++ b/index.html @@ -108,14 +108,15 @@ try { fetch(`https://addons.mozilla.org/api/v5/addons/addon/${document.getElementById('addon-url').value.match(/\/addon\/([^/]+)/)[1]}/`) .then(res => res.ok ? res.json() : Promise.reject(new Error(`Server responded ${res.status}`))) - .then(data => { - const a = document.createElement('a'); - a.href = data.current_version.file.url; - a.download = a.href.split('/').pop().replace(/\.xpi$/, '.zip'); + .then(data => (status.textContent = 'Downloading file...', fetch(data.current_version.file.url).then(res => res.ok ? res.blob() : Promise.reject(new Error(`File download failed: ${res.status}`))).then(blob => ({blob, url: data.current_version.file.url})))) + .then(({blob, url}) => { + const a = document.createElement('a'), fileName = url.split('/').pop().replace(/\.xpi$/, '.zip'); + a.href = URL.createObjectURL(blob); + a.download = fileName; document.body.appendChild(a).click(); + URL.revokeObjectURL(a.href); document.body.removeChild(a); - status.className = 'success'; - status.textContent = `Download initiated for ${a.download}.`; + status.className = 'success'; status.textContent = `Download initiated for ${fileName}.`; }) .catch(err => { status.className = 'error'; status.textContent = `Error: ${err.message}.`; }) .finally(() => setTimeout(() => status.textContent = status.className = '', 5000));