Persistent btoa/atob Runtime Error on v0 Platform (Need Help ASAP pls)

Hello Support Team,

I’ve been struggling with the following issue for quite some time and need immediate assistance. Despite multiple attempts and revisions, the error persists. Below is a summary of what I’ve already tried:

  1. Default Project:
    Encountered the same error repeatedly despite nearly 100 revisions using the default “Fix with v0” option. None of the fixes resolved the issue.

  2. Cloned Project:
    Created a clone of the same project in v0, hoping a fresh instance would work — no luck.

  3. Manual Fix Attempt:
    With the help of Cursor AI, I completely removed all btoa and atob calls from the code and created a new v0 instance. The error still persists, even though I can confirm there are no such calls within my code (explicitly or internally).

Notably, all three versions run perfectly fine locally on my system. The issue only occurs when running the project through the v0 platform, which strongly suggests it may be related to the runtime preview engine or platform-level configuration.

Could you please investigate this further and help get this showstopper issue resolved asap?
I’m happy to connect live or provide any additional details required.

image

getting the same issue same, started a few weeks ago

Can you share the template or the project once so that I can test it out once.

Else you can check the fix with v0 button and v0 will try to fix it once.

What is it you are doing or trying to do when this all occurs? or is it just when opening a project?
I have yet to experience this issue in such terrible ways to be honest. I did get this screen once, maybe a week ago, but the Fix with v0” button cleared it up in one go. So i am wondering if there is something deeper going on. If you have cloned it and all and it is still not correct that is very odd.

But you are saying it works on Cursor which is interesting. Have you tried pushing that instance on Cursor to GitHub, download that rep (created from Cursor) and then start a new project in v0 by uploading that zipped file? Would be curious to hear the results from that.

https://v0.app/templates/mushie-it-gzsWeCXQSSF?ref=Z0LLWE

Thank you, template above:

Hey so btoa error is something that is occuring when the code is trying to encode a string in JS using btoa function. Now it can be related to as you said but mostly it is related to the dangerous HTML setting that you are using in the layout.tsx which should happen at all.

The Fixed Code block:

(function() {
  if (typeof window === 'undefined' || typeof window.btoa === 'undefined') return;
  
  var nativeBtoa = window.btoa.bind(window);
  var descriptor = Object.getOwnPropertyDescriptor(window, 'btoa');
  if (descriptor && descriptor.get && descriptor.get.__v0Patched) return;
  
  function safeBtoaWrapper(input) {
    if (input == null) return '';
    var str = String(input);
    if (str === '') return '';
    
    try {
      // First try native btoa (fastest for ASCII)
      return nativeBtoa(str);
    } catch (error) {
      try {
        // For UTF-8 strings, properly encode to Latin1-compatible format
        var utf8Bytes = unescape(encodeURIComponent(str));
        return nativeBtoa(utf8Bytes);
      } catch (error2) {
        try {
          // Manual base64 encoding as last resort
          var base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
          var result = '';
          var bytes = [];
          
          // Convert string to UTF-8 bytes
          for (var i = 0; i < str.length; i++) {
            var code = str.charCodeAt(i);
            if (code < 128) {
              bytes.push(code);
            } else if (code < 2048) {
              bytes.push(192 | (code >> 6), 128 | (code & 63));
            } else if (code < 65536) {
              bytes.push(224 | (code >> 12), 128 | ((code >> 6) & 63), 128 | (code & 63));
            } else {
              bytes.push(
                240 | (code >> 18),
                128 | ((code >> 12) & 63),
                128 | ((code >> 6) & 63),
                128 | (code & 63)
              );
            }
          }
          
          // Encode bytes to base64
          for (var i = 0; i < bytes.length; i += 3) {
            var b1 = bytes[i];
            var b2 = i + 1 < bytes.length ? bytes[i + 1] : 0;
            var b3 = i + 2 < bytes.length ? bytes[i + 2] : 0;
            
            var enc1 = b1 >> 2;
            var enc2 = ((b1 & 3) << 4) | (b2 >> 4);
            var enc3 = ((b2 & 15) << 2) | (b3 >> 6);
            var enc4 = b3 & 63;
            
            if (i + 1 >= bytes.length) {
              enc3 = enc4 = 64;
            } else if (i + 2 >= bytes.length) {
              enc4 = 64;
            }
            
            result += base64chars.charAt(enc1) + base64chars.charAt(enc2);
            result += enc3 === 64 ? '=' : base64chars.charAt(enc3);
            result += enc4 === 64 ? '=' : base64chars.charAt(enc4);
          }
          
          return result;
        } catch (error3) {
          console.warn('[v0] btoa: All encoding failed, returning empty', error3);
          return '';
        }
      }
    }
  }
  
  Object.defineProperty(window, 'btoa', {
    get: function() { return safeBtoaWrapper; },
    set: function() { console.warn('[v0] btoa override blocked'); },
    configurable: false,
    enumerable: true
  });
  
  safeBtoaWrapper.__v0Patched = true;
  console.log('[v0] btoa wrapper installed');
})();

Also the location to replace it is in your layout.tsx.

Try it once and it might be able to fix the error.

1 Like