2

This new issue is related to this question. I use the following Javascript code to download the content of a textarea on the browser in a text file.

var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(logs));
pom.setAttribute('download', log_file_name);
pom.style.display = 'none';
document.body.appendChild(pom);
pom.click();
document.body.removeChild(pom);

This works fine for small files, but fails when file size exceeds about 1MB or so, with error message "Failed.Network error". Of course, I don't have any network problem because Firefox and Safari work just fine. Clicking "More info" takes me to this page, which has useless information for me. I Google'd the error message and found some info that I tried with no luck. I even reinstalled Chrome, tried Chrome Canary. Nothing worked.

Anyone knows a trick to get Chrome to work as well?

Community
  • 1
  • 1
rh4games
  • 962
  • 2
  • 15
  • 38
  • I think url has a maximum length in the url string format, shouldn't be the case that chrome is truncating the `data:text` and you are having issues because of it? – ncubica May 16 '17 at 00:25
  • other ideas is that maybe, adding a node of 1mb in the dom is taking more time chrome to do it, and when you call the function `pom.click` the dom actually don't exist in the dom yet. – ncubica May 16 '17 at 00:26
  • see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs#Common_problems for the likely reason – Jaromanda X May 16 '17 at 00:28
  • see http://stackoverflow.com/questions/695151/data-protocol-url-size-limitations for more recent limits – Jaromanda X May 16 '17 at 00:31
  • Thanks all for these pointers. These seem to indicate Chrome should handle up to 2MB but in my case, it is failing around 1MB. Is there an alternate way to download a file from the browser page? – rh4games May 16 '17 at 00:51
  • @ncubica I checked href and it is not truncated. using step by step debug mode from the console, all looks OK until pom.click happens – rh4games May 16 '17 at 20:11

0 Answers0