Failed to execute ‘btoa’ on ‘Window’: The string to be encoded contains characters outside of the Latin1 range.

The error in the title is thrown only in Google Chrome, according to my tests. I’m base64 encoding a big XML file so that it can be downloaded:

this.loader.src = "https://stackoverflow.com/questions/23223718/data:application/x-forcedownload;base64,"+
                  btoa("<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                  +"<"+this.gamesave.tagName+">"
                  +this.xml.firstChild.innerHTML
                  +"</"+this.gamesave.tagName+">");

this.loader is hidden iframe.

This error is actually quite a change because normally, Google Chrome would crash upon btoa call. Mozilla Firefox has no problems here, so the issue is browser related.
I’m not aware of any strange characters in file. Actually I do believe there are no non-ascii characters.

Q:
How do I find the problematic characters and replace them so that Chrome stops complaining?

I have tried to use Downloadify to initiate the download, but it does not work. It’s unreliable and throws no errors to allow debug.

7 Answers
7

Leave a Comment