I am doing a verification code to automatically fill in the plugin, but I have encountered an error.
Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.
Error Image: https://img-ask.csdn.net/upload/201902/03/1549128446_976961.png
The corresponding code is:
Code Image https://img-ask.csdn.net/upload/201902/03/1549128473_324557.png
function getBase64Image(im)
{
im.crossOrigin="";
var canvas = document.createElement("canvas");
canvas.width = im.width;
canvas.height = im.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(im, 0, 0);
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace("data:image/png;base64,", "");
}
I found a lot of solutions in Google, mostly telling me that this is a cross-domain error. solutions
I can add code to be
img.crossOrigin="Anonymous";
Resolve cross-domain issues, but still give an error after trying Next, I found a solution to this type of problem on stackoverflow.
Got it
img.crossOrigin="";
Still added after the addition
This solution is feasible on other pages, that is, this page cannot be killed or killed.
Test:
Test URL::Click here to jump to the Alipay login page
1.Enter a function in the Console
Such as:
function getBase64Image(im) { im.crossOrigin=""; var canvas = document.createElement("canvas"); canvas.width = im.width; canvas.height = im.height; var ctx = canvas.getContext("2d"); ctx.drawImage(im, 0, 0); var dataURL = canvas.toDataURL("image/png"); return dataURL.replace("data:image/png;base64,", ""); }
2.Next
getBase64Image(document.getElementById("J-checkcode-img"))
I don't know much about JavaScript development.
I haven't found a suitable solution on the Internet for a long time.
I don't know how to solve it. I hope you can help, thank you!