Open Ponali opened 8 months ago
most code with any errors don't update the url. your code is almost certainly infinitely recursive, which still means it's broken. firefox seems to just crash the tab when this happens, it doesn't even report an error.
the player might be able to handle the error a bit better, but it can't make the code work and it can't make it work in all browsers. you should probably just fix your bytebeat code for now.
window.location.hash = `#v3b64${ btoa(String.fromCharCode.apply(undefined, deflateRaw(JSON.stringify(songData)))).replaceAll('=', '') }`;
I think the error appears in the String.fromCharCode.apply
like devtools says. If a code is large enough even after being compressed with pako, turning each element of it into it's own parameter probably would use up the call stack eventually. This is not an issue with an individual bytebeat code and is to do with the player itself.
I'm wondering if instead of running String.fromCharCode on the entire thing in a single pass like this, you map each element of the array to a character individually and then join it into a single string:
window.location.hash = `#v3b64${ btoa(deflateRaw(JSON.stringify(songData)).map(k=>String.fromCharCode(k)).join('')).replaceAll('=', '') }`;
Or turn the bytes into characters one by one:
let bytes = deflateRaw(JSON.stringify(songData)).reverse();
let str = "";
while(bytes.length>0) {
str+=String.fromCharCode(bytes.pop());
}
window.location.hash = `#v3b64${ btoa(str).replaceAll('=', '') }`;
I can imagine these are slower, but they might fix the issue. iirc firefox does say "Too many parameters passed to String.charcode.apply" or something like that.
the map would be better. firefox limits the amount of function arguments to 50000, which is sufficient for well written code, but function arguments aren't meant to act as arrays. although i think that 50k for a single bytebeat isn't a good way to go about making bytebeats, it's entirely reasonable someone would hit that number with some inefficient auto generation tool or audio samples.
when large amounts of valid javascript code is inserted, the client does not update the sample rate nor the link to the page (normal behaviour would normally turn the URL to have the code after the hashtag.) when setting the sample rate, it does not do anything to the audio, when reloading, the sample rate option defaulted back to before i set it. when inserting large amounts of code, the URL does not update, meaning that when reloading, the code dissapears, and defaults back to before i set the large portion of code. this is what i can gather from DevTools that is related to this subject: