it show Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed

Viewed 568

when I try to use file saver and html2canvas it show that error, How to fix this ?

Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.

$( "#click" ).on( "click", function() {
    html2canvas(document.querySelector("#Views")).then(canvas => {
      canvas.toBlob(function(blob) {

        window.saveAs(blob, 'img.jpg');
      });
      });
  });
1 Answers

This error means that the call to HTMLCanvasElement#toBlob() failed, this can happen for a couple of reasons:

  • The returned canvas had either its height or width set to 0:

document.querySelector("canvas").toBlob(console.log);
<canvas width="0">

document.querySelector("canvas").toBlob(console.log);
<canvas width="80000" height="80000">

So you should check your element's computed style, taking particular attention to its size, but also to its display value, since this problem is quite frequently caused by targeting an element with display: none.

Related