fix export
This commit is contained in:
parent
ef0a802c16
commit
8a70fc5f81
@ -1,46 +1,23 @@
|
|||||||
class IO {
|
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("\n\n\n\n---------- Starting export of log to file ----------------");
|
||||||
|
|
||||||
console.info("[info] json string for exportObject:", jsonString.length);
|
console.info("[info] json string for exportObject:", jsonString.length);
|
||||||
|
|
||||||
const blob = new Blob([jsonString], {type: 'application/json'});
|
const blob = new Blob([jsonString], {type: 'application/json'});
|
||||||
|
|
||||||
console.info("[ ok ] Blob created");
|
|
||||||
|
|
||||||
const fileUrl = URL.createObjectURL(blob);
|
const fileUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
console.info("[ ok ] fileUrl created");
|
const a = document.createElement('a');
|
||||||
|
a.style.display = 'none';
|
||||||
try {
|
a.href = fileUrl;
|
||||||
console.log("[info] inside try/catch block. BrowserDetect:", currentBrowser);
|
a.download = 'ultrawidify-log.json';
|
||||||
if (currentBrowser.firefox) {
|
document.body.appendChild(a);
|
||||||
console.info("[info] we are using firefox");
|
a.click();
|
||||||
await browser.permissions.request({permissions: ['downloads']});
|
window.URL.revokeObjectURL(fileUrl);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user