So I have this piece of code here for my WebExtension to export some data using JavaScript in the options page.
function downloadTextFile(arr) {
var txt = "";
arr.forEach(function(row) {
txt += row;
txt += "\n";
});
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:text/plain;charset=utf-8,' + encodeURIComponent(txt);
hiddenElement.target = '_target';
hiddenElement.download = 'URLS.txt';
document.body.appendChild(hiddenElement);
hiddenElement.click();
document.body.removeChild(hiddenElement);
}
The only problem is that in Firefox it just displays the text file without downloading it, while in Chrome, the text file actually downloads.