Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
https://github.com/niklasvh/html2canvas/issues/1614
朋友圈h5需要动态生成一些长按分享的图片, 用html2canvas最合适不过。但是经常会报错。
总结下来,发现引入两个参数就可以了。
allowTaint: true, // 生成包含外链图片的canvas时不报错
useCORS: true // 生成base64时不报错
var $tmp = $('<div></div>').addClass('tmp');
$tmp.appendTo($('body'));
var $a = $('#result .top').clone().appendTo($tmp);
html2canvas($tmp[0], {
allowTaint: true,
useCORS: true
// foreignObjectRendering: true
}).then(canvas => {
// $('#result .top').append(canvas);
var b64;
try {
b64 = canv