javascript 如何使用 html2canvas 代理

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9825962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 07:57:23  来源:igfitidea点击:

How to use html2canvas proxy

javascriptjquerypythonhtml2canvas

提问by amine

I'm using html2canvas plugin to generate snapshot of web pages. The problem is that everything runs ok in the localhost, however when deployed on the remote server I get the following error : Unable to get image data from canvas because the canvas has been tainted by cross-origin data.

我正在使用 html2canvas 插件生成网页快照。问题是在本地主机中一切正常,但是当部署在远程服务器上时,我收到以下错误:无法从画布获取图像数据,因为画布已被跨域数据污染。

I've found a plugin that is supposed to work : https://github.com/niklasvh/html2canvas-proxy

我找到了一个应该可以工作的插件:https: //github.com/niklasvh/html2canvas-proxy

The problem is that I don't know how to use it !

问题是我不知道如何使用它!

Similar question is asked here but remains without answer : https://github.com/niklasvh/html2canvas/issues/61

这里提出了类似的问题,但仍然没有答案:https: //github.com/niklasvh/html2canvas/issues/61

采纳答案by amine

I've solved this issue, the proxy code needs to be added to the server side scripts. Then I needed to change the order of if statements to make calling the proxy the first choice since it will be the case for all the images we are dealing with in our project. Thanks Niklas. More details are here : https://github.com/niklasvh/html2canvas-proxy/issues/2#

我已经解决了这个问题,需要将代理代码添加到服务器端脚本中。然后我需要更改 if 语句的顺序以使调用代理成为首选,因为我们在项目中处理的所有图像都是这种情况。谢谢尼克拉斯。更多细节在这里:https: //github.com/niklasvh/html2canvas-proxy/issues/2#