From 8a70fc5f813c417fc217a4804ac713a463ed24b3 Mon Sep 17 00:00:00 2001 From: Tamius Han Date: Tue, 4 Feb 2020 23:14:48 +0100 Subject: [PATCH] fix export --- src/common/js/IO.js | 47 ++++++++++++--------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/src/common/js/IO.js b/src/common/js/IO.js index f11d3c1..5ca32ae 100644 --- a/src/common/js/IO.js +++ b/src/common/js/IO.js @@ -1,46 +1,23 @@ class IO { - static async exportStringToFile(jsonString) { + /** + * Export a (presumably json) string to file. Meant for use with content script. + * @param {*} jsonString string to be saved + */ + static async csStringToFile(jsonString) { console.info("\n\n\n\n---------- Starting export of log to file ----------------"); console.info("[info] json string for exportObject:", jsonString.length); const blob = new Blob([jsonString], {type: 'application/json'}); - - console.info("[ ok ] Blob created"); - const fileUrl = URL.createObjectURL(blob); - console.info("[ ok ] fileUrl created"); - - try { - console.log("[info] inside try/catch block. BrowserDetect:", currentBrowser); - if (currentBrowser.firefox) { - console.info("[info] we are using firefox"); - await browser.permissions.request({permissions: ['downloads']}); - console.info("[ ok ] download permissions ok"); - browser.downloads.download({saveAs: true, filename: 'extension-log.json', url: fileUrl}); - } else if (currentBrowser.chrome) { - console.info("[info] we are using chrome"); - - const ths = this; - - chrome.permissions.request( - {permissions: ['downloads']}, - (granted) => { - if (granted) { - chrome.downloads.download({saveAs: true, filename: 'extension-log.json', url: fileUrl}); - } else { - ths.downloadPermissionError = true - } - } - ) - } - this.globalHistory = {}; - this.history = []; - } catch (e) { - console.error("[fail] error while saving file.", e); - this.downloadPermissionError = true; - } + const a = document.createElement('a'); + a.style.display = 'none'; + a.href = fileUrl; + a.download = 'ultrawidify-log.json'; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(fileUrl); } }