简体   繁体   English

如何修复 html2canvas 库中的错误

[英]How can I fix error in html2canvas library

I was using html2canvas to convert an image in base 64 and send it through PHP and thus store it as a Blob, at first it worked correctly and when I decoded it it showed me the image, but now it shows me this error in the library and I don't know why it happens.我正在使用 html2canvas 转换 base 64 中的图像并通过 PHP 发送它,从而将其存储为 Blob,起初它工作正常,当我解码它时它向我显示图像,但现在它向我显示库中的这个错误我不知道为什么会这样。

The error is the following:错误如下:

 documentClone.replaceChild(documentClone.adoptNode(cloner.documentElement), documentClone.documentElement);

When I execute the event to take the capture of my html, I get an error in the library code, and my code sends me a base64 image but it does not exist, because the library did not take any capture of my html.当我执行捕获我的 html 的事件时,库代码出现错误,我的代码向我发送了一张 base64 图像,但它不存在,因为库没有捕获我的 html。

This is my javascript with which I send the image in base64这是我的 javascript,我用它发送 base64 中的图像

 html2canvas(document.body).then(function (canvas){ var ajax = new XMLHttpRequest(); var num = Math.floor(Math.random()*10000); ajax.open("POST", "save-any.php", true); ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded") ajax.send("num=" + num + "&image=" + canvas.toDataURL("image/jpeg", 0.9)); }); }

What happens to me is that the library does not save me any image but it generates a url that does not lead to any image.发生在我身上的是图书馆没有为我保存任何图像,但它生成了一个 url,它不会导致任何图像。

This error indicates that document.body is probably undefined.此错误表明 document.body 可能未定义。 Use chrome Deb tools and put a break on html2canvas(document.body).then(function and inspect value of document.body.使用 chrome Deb 工具并中断 html2canvas(document.body).then(函数并检查 document.body 的值。

I have also seen this error when the element sent to html2canvas is not a single element/node but rather an array of nodes.当发送到 html2canvas 的元素不是单个元素/节点而是节点数组时,我也看到了这个错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM