简体   繁体   English

如何避免帆布污染?

[英]How to avoid tainted canvas?

I try to save an Canvas as an Image. 我尝试将“画布”另存为图像。 But it fails always. 但是它总是失败。 I was looking up the Internet and Stackoverflow.com but I couldn't find the right answer. 我一直在寻找Internet和Stackoverflow.com,但找不到正确的答案。 I use the answer in this question to get the context. 我用这个问题的答案来获取上下文。 This works fine, but if I use context.toDataURL I receive error the Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. 这可以正常工作,但是如果我使用context.toDataURL ,则会收到未捕获的SecurityError错误:无法在'HTMLCanvasElement'上执行'toDataURL':可能无法导出污染的画布。

I do not understand why I get this until now, because I added to my canvas and to the videostream the attribute crossorigin="anonymous" and if I check the attribute in the javascript section I still receive that crossorigin is anonymous. 我现在不明白为什么要得到这个消息,因为我在画布和视频流中添加了属性crossorigin="anonymous"并且如果我在javascript部分中检查了该属性,我仍然会收到crossorigin是匿名的。 Therefore it should work. 因此,它应该工作。

function captureimage(){
var canvas = document.getElementById("c");
var video = document.getElementById("v");
var ctx;
if(video.paused) {
    try {
         ctx = canvas.getContext('2d').drawImage(video, 0, 0);
     } catch (e) {
          alert(e);
     }
     var a = ctx.toDataURL();
}   
}

How can I solve this security issue? 如何解决此安全问题? I also added Header set Access-Control-Allow-Origin * to my httpd.conf, but this didn't solve the problem either. 我还在我的httpd.conf中添加了Header set Access-Control-Allow-Origin * ,但这也不能解决问题。

我遇到了同样的问题,可以通过在视频代码中添加crossorigin =“ *”来解决

I had this problem when i was trying to draw an image that Chrome had cached into a canvas. 当我尝试绘制Chrome已缓存到画布中的图像时遇到了这个问题。 I solved my issue by adding a unique cache breaking parameter to the image URL, to ensure that the image was never being cached. 我通过向图像URL添加唯一的缓存中断参数解决了我的问题,以确保从未缓存图像。

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

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