javascript - How to test if Canvas.toBlob() failed -
using canvas.toblob(callback, ...)
, converting several large canvas elements (2048x2048 pixels) png.
however, @ least in chrome, callback not called. there no errors generated in chrome devtools.
my questions:
- is there way check if
toblob()
failed, aside timing out after x seconds? - under conditions
toblob()
fail? how know condition not met / how error message?
the code using:
function trigger_browser_download(blob, filename) { "use strict"; var url = window.url.createobjecturl(blob); a.href = url; a.download = filename; a.click(); window.url.revokeobjecturl(url); }; function download_canvas(canvas, filename) { "use strict"; canvas.toblob(function(blob) { debugger; // not reached if(blob instanceof blob) { trigger_browser_download(blob, filename); } else { console.error("error generating blob"); } }, 'application/octet-binary'); } for(var = 0; < 10; ++i) { var canvas = document.createelement('canvas'); canvas.height = 2048; canvas.width = 2048; download_canvas(canvas, + ".png"); }
Comments
Post a Comment