Uncaught DOMException: Failed to execute ‘toDataURL’ on ‘HTMLCanvasElement’: Tainted canvases may not be exported.

一、问题

canvas.toDataURL()报错如下:

二、解决

图片设置 :crossOrigin属性
代码片段:img.setAttribute("crossOrigin",'Anonymous')