I have a button in my extension that triggers the following code:
chrome.tabs.create({url: 'data:text;base64,'+btoa(data), active:false});
This triggers a download of my string (data), as I expected. Unfortunately, it seems to be stripping out newline characters.
I have tried other encoding methods, including utf-8 and the encodeUri()
function. I also tried switching the mimetype to data:text/plain
, but that simply opens in a new tab (with the correct newline characters) instead of downloading.
Is there a way to encode my text so that newline characters are preserved? If not, is there a different method for triggering file downloads in the browser?
edit
I have discovered that the newlines do appear in some text editors. Previously, I was using notepad, which did not recognize the newline characters from chrome, but my other text editor (notepad++) does seem to recognize them