> Uncaught DOMException: Failed to execute 'toBlob' on 'HTMLCanvasElement': Tainted canvases may not be exported.
如遇到跨域问题,在非safari中一般可以添加:
const _img = new Image
_img.setAttribute('crossOrigin', 'anonymous');//这一行
但是safari无效
一个解决方案就是,先把图片转为本地blob资源
const img = new Image
fetch('xxx.png',{
mode: 'cors',
headers: {
"Content-Type": "application/json",
},
}).then(response=>response.blob()).then(myBlob=>{
let objectURL = URL.createObjectURL(myBlob);
img.src = objectURL;
img.onload = ()=>{
// ctx.drawImage(img,0,0,1,1)
// canvas.toBlob(e=>{
// console.log(e)
// })
}
})