Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome crashes when URI is too long

I'm making an export function to a HTML5 game of mine and my current saving method is a crude serialization of game data and then:

// this is Javascript
var gameData = "abc"; // this is actually a HUGE string of over 2MB
try
{
    document.location = "data:text/octet-stream,"+encodeURIComponent(JSON.stringify(gameData));
}
catch(e)
{
    console.log(e);
}

From: Using HTML5/Javascript to generate and save a file

I don't mind the fact that I can't use it for big strings, but I'd like it to generate a warning that informs that this method doesn't work, unfortunately Chrome (16) crashes without catching that exception.

Is there a better way to implement this kind of export, the important thing being for me is to make it work locally. FileAPI would be a better solution, but doesn't work locally.

like image 943
Solenoid Avatar asked Jan 05 '12 19:01

Solenoid


People also ask

Why does Chrome keep crashing when I search?

If your computer is low on RAM (which is often a problem due to Chrome's high memory usage), it may cause websites to crash. Try closing all tabs you're not using, pausing any Chrome downloads, and quitting any unnecessary programs running on your computer.

How do I get rid of Google Chrome from crashing?

From the “Menu” button in the upper-right corner of the Chrome window, choose “More Tools” > “Clear browsing data…“. Press “CTRL” + “Shift” + “Delete” keys in Windows or Linux, or “Command” + “Shift” + “Delete” keys on MacOS. Select “Menu” > “Settings” > “Advanced” > “Clear browsing data…“.

Why do my Chrome windows keep crashing?

If too many tabs are open in Google Chrome, it becomes slow thereby leading to Chrome crashing problems. To solve the problem of Google Chrome not responding try closing all tabs and restart Chrome to check if the problem is resolved. However, if Google Chrome still keeps freezing Windows 10, try disabling extensions.


1 Answers

AFAIK not possible client-side; but a 1.99MB file can be saved this way in Chrome; maybe you should try to compress/optimize your game data a little bit. One way to do that is to use JSZip.

In order to check if the current browser is Google Chrome and so the method doesn't work with long strings you can use something like this:

if(gameData.length > 1999999 && window.chrome){
    alert("Sorry, this export method does not work in Google Chrome")
    return; 
}
like image 54
Ivan Castellanos Avatar answered Oct 05 '22 21:10

Ivan Castellanos