diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index fbba159057e..d931e62ce76 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -199,11 +199,11 @@ class BrowserApi { } static downloadFile(win: Window, blobData: any, blobOptions: any, fileName: string) { - if (win.navigator.msSaveOrOpenBlob || BrowserApi.isSafariApi) { + if (BrowserApi.isSafariApi) { const tab = BrowserApi.createNewTab(BrowserApi.getAssetUrl('downloader/index.html')); - const madeTab = BrowserApi.makeTabObject(tab); - setTimeout(() => { - BrowserApi.tabSendMessage(madeTab, { + const tabToSend = BrowserApi.makeTabObject(tab); + setTimeout(async () => { + BrowserApi.tabSendMessage(tabToSend, { command: 'downloaderPageData', data: { blobData: blobData, @@ -214,12 +214,16 @@ class BrowserApi { }, 1000); } else { const blob = new Blob([blobData], blobOptions); - const a = win.document.createElement('a'); - a.href = win.URL.createObjectURL(blob); - a.download = fileName; - win.document.body.appendChild(a); - a.click(); - win.document.body.removeChild(a); + if (navigator.msSaveOrOpenBlob) { + navigator.msSaveBlob(blob, fileName); + } else { + const a = win.document.createElement('a'); + a.href = win.URL.createObjectURL(blob); + a.download = fileName; + win.document.body.appendChild(a); + a.click(); + win.document.body.removeChild(a); + } } } diff --git a/src/downloader/downloader.ts b/src/downloader/downloader.ts index 05eaa5d2574..dfd321a3b0c 100644 --- a/src/downloader/downloader.ts +++ b/src/downloader/downloader.ts @@ -2,16 +2,14 @@ document.addEventListener('DOMContentLoaded', () => { const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1; - if (isSafari) { - safari.self.addEventListener('message', (msgEvent: any) => { - doDownload(msgEvent.message); - }, false); - } else if (navigator.userAgent.indexOf(' Edge/') !== -1) { - chrome.runtime.onMessage.addListener((msg: any, sender: any, sendResponse: any) => { - doDownload(msg); - }); + if (!isSafari) { + return; } + safari.self.addEventListener('message', (msgEvent: any) => { + doDownload(msgEvent.message); + }, false); + function doDownload(msg: any) { if (msg.command === 'downloaderPageData' && msg.data) { const blob = new Blob([msg.data.blobData], msg.data.blobOptions); diff --git a/src/popup/app/tools/export.component.ts b/src/popup/app/tools/export.component.ts index fbaa767f1f9..67f5133a63b 100644 --- a/src/popup/app/tools/export.component.ts +++ b/src/popup/app/tools/export.component.ts @@ -73,15 +73,15 @@ export class ExportController { await Promise.all(promises); const foldersMap = new Map(); - for (const f of decFolders) { + decFolders.forEach((f: any) => { foldersMap.set(f.id, f); - } + }); - const exportCiphers = []; - for (const c of decCiphers) { + const exportCiphers: any[] = []; + decCiphers.forEach((c: any) => { // only export logins and secure notes if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) { - continue; + return; } const cipher: any = { @@ -99,7 +99,7 @@ export class ExportController { }; if (c.fields) { - for (const f of c.fields) { + c.fields.forEach((f: any) => { if (!cipher.fields) { cipher.fields = ''; } else { @@ -107,7 +107,7 @@ export class ExportController { } cipher.fields += ((f.name || '') + ': ' + f.value); - } + }); } switch (c.type) { @@ -122,11 +122,11 @@ export class ExportController { cipher.type = 'note'; break; default: - continue; + return; } exportCiphers.push(cipher); - } + }); const csv = papa.unparse(exportCiphers); return csv;