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

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

当我尝试使用文件保护程序和 html2canvas 时,它显示错误,如何解决?

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');
      });
      });
  });

此错误意味着对 HTMLCanvasElement#toBlob() 的调用失败,发生这种情况的原因可能有以下几个:

  • 返回的 canvas 的 heightwidth 设置为 0:

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

  • 返回的canvas的面积超过maximum area the browser could support:

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

所以您应该检查元素的计算样式,特别注意它的大小,还要注意它的 display 值,因为这个问题通常是由定位具有 display: none 的元素引起的。