A snippet of client-side Blob saving code has suddenly stopped working in Google Chrome. The same code continues to work in Firefox. The code is almost identical to that provided in this answer, among others.
var downloadLink = document.createElement("a");
var url = URL.createObjectURL(new Blob(["\ufeff", rows]));
downloadLink.href = url;
downloadLink.download = filename;
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
Setting a breakpoint on the .click()
and then single-stepping causes the file to download as expected, but running the code normally does not. I did find that wrapping the .click()
in a setTimeout
does allow it to succeeed, but only if the timeout is sufficiently long
var downloadLink = document.createElement("a");
var url = URL.createObjectURL(new Blob(["\ufeff", rows]));
downloadLink.href = url;
downloadLink.download = filename;
document.body.appendChild(downloadLink);
setTimeout(function() {
downloadLink.click();
document.body.removeChild(downloadLink);
}, duration);
where
Duration | Download
----------+----------
0 ms | Fail
1 ms | Fail
10 ms | Fail
100 ms | Fail
1000 ms | Succeed
I don't know for sure that the problem started at Version 57, but I am looking for any information or advice on how to improve the Blob download without resorting to a setTimeout
hack.
** Edit **
I should be clear that the Blob download is being triggered by a button click initiated by the user and is not a piece of code that runs unconditionally upon page load.