1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

download file via content script

This commit is contained in:
Kyle Spearrin
2019-08-21 21:10:38 -04:00
parent 2e609331f3
commit 8dd574bf9a
3 changed files with 39 additions and 6 deletions

View File

@@ -9,7 +9,16 @@ document.addEventListener('DOMContentLoaded', (event) => {
safari.self.addEventListener('message', (msgEvent: any) => {
const msg = JSON.parse(msgEvent.message.msg);
if (msg.command === 'downloaderPageData') {
const blob = new Blob([msg.data.blobData], msg.data.blobOptions);
let data: any = msg.data.blobData;
if (msg.data.blobOptions == null || msg.data.blobOptions.type !== 'text/plain') {
const binaryString = window.atob(msg.data.blobData);
const bytes = new Uint8Array(binaryString.length);
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
data = bytes.buffer;
}
const blob = new Blob([data], msg.data.blobOptions);
if (navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, msg.data.fileName);
} else {
@@ -20,7 +29,6 @@ document.addEventListener('DOMContentLoaded', (event) => {
a.click();
document.body.removeChild(a);
}
window.setTimeout(() => window.close(), 1500);
}
}, false);
});