Software⏱️ 2 min read📅 2026-05-31

How to Fix: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.

Base64 encoding issue in Google Chrome due to non-Latin1 characters in XML file.

Quick Answer: Use a different encoding or escape special characters before base64 encoding.

The error in the title is thrown only in Google Chrome, according to your tests. You're base64 encoding a big XML file so that it can be downloaded: this.loader.src = "data:application/x-forcedownload;base64,"+ btoa("<?xml version="1.0" encoding="utf-8"?> <" + this.gamesave.tagName + "\gt; " + this.xml.firstChild.innerHTML + "\lt;/" + this.gamesave.tagName + "\gt;");

🔍 Why This Happens

  • [Cause]

✅ Best Solutions to Fix It

Method 1: Encoding as UTF-8

  1. Step 1: Replace all XML tags with their HTML equivalents.

Method 2: Using a Different Encoding

  1. Step 1: Use the `xml-escape` function to escape special characters in your XML string.

🎯 Final Words

By following these methods, you should be able to fix the error and successfully download your XML file in Google Chrome.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions