Hopding / js-visualizer-9000-client

A React app to interactively visualize JavaScript's Event Loop
https://jsv9000.app
1.15k stars 132 forks source link

I can't copy the code to the page #41

Open lm101845 opened 1 year ago

lm101845 commented 1 year ago

When I copy the code to the page, the website is clean and the console displays the following error message:

"react-dom.production.min.js:2857 Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range."

image

I searched from the internet,The reason seems to be this:

This error indicates that a string that does not conform to the Latin1 character set range was passed while using the btoa function. The Latin1 character set (also known as ISO-8859-1) contains most commonly used Latin letters and numbers, but excludes Chinese characters and some other common non-Latin characters.

To solve this problem, you need to transcode the strings so that they conform to the range of the Latin1 character set. This can be done using JavaScript's encodeURIComponent function, for example:

var str = "这是一个包含中文字符的字符串";
var encodedStr = encodeURIComponent(str);

// now you can use btoa safely
var base64Str = btoa(encodedStr);

could you please fix this problem?thank you very much!

Your website(https://www.jsv9000.app/) is very good!

lm101845 commented 1 year ago

I cloned your code and run,I found that if I added this code I seemed could fix the problem:

image

image

the file location is js-visualizer-9000-client/src/components/ShareButton.js 84row

cloudyan commented 1 year ago

I cloned your code and run,I found that if I added this code I seemed could fix the problem:

the file location is js-visualizer-9000-client/src/components/ShareButton.js 84row

url.searchParams.set('code', btoa(encodeURIComponent(code)));

It's working