简体   繁体   English

Chrome:受污染的画布可能无法导出; 仅限离线应用

[英]Chrome: Tainted canvases may not be exported; Offline-only app

This question is similar, but not identical to many of the existing questions on this topic, including Tainted canvases may not be exported . 该问题与该主题上的许多现有问题相似,但并不完全相同,包括可能无法导出脏画布

I am writing an offline-only app that has to stay that way and cannot use a local web server. 我正在编写仅离线应用程序,该应用程序必须保持这种状态,并且不能使用本地Web服务器。 Is there any way to circumvent the CORS check on the canvas in order to copy the data back to the base image. 有什么方法可以规避画布上的CORS检查,以便将数据复制回基础图像。


Here is an example of the code I am trying: 这是我尝试的代码示例:

var c1 = document.getElementById("tmp1");
var ctx1 = c1.getContext('2d');
var tmpImg1 = document.getElementById("tmpimg1");
ctx1.drawImage(img1, 0, 0, 150, 150);     
tmpImg1.src = c1.toDataURL();

The error message from Chrome is as follows: 来自Chrome的错误消息如下:

Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported. 未捕获到的SecurityError:无法在“ HTMLCanvasElement”上执行“ toDataURL”:可能无法导出污染的画布。


In an offline-only situation, what options are available that still have the same end result? 在仅脱机的情况下,哪些可用选项仍具有相同的最终结果?

You could specify all your img.src as inline base64-encoded URLs. 您可以将所有img.src指定为内联base64编码的URL。

img.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAA ..."

This way all the imgs are local to your app and CORS is satisfied. 这样,所有img都在您的应用程序本地,并且满足CORS。

暂无
暂无

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

相关问题 受污染的画布不得出口 - Tainted canvases may not be exported 离线版本的 HTML2canvas - 受污染的画布可能无法导出 - HTML2canvas in offline version - Tainted canvases may not be exported Canvas.toDataURL() 受污染的画布可能无法导出 - Canvas.toDataURL() Tainted canvases may not be exported 可能无法导出空白的PNG /污染的画布(不使用图像) - Blank PNG / Tainted canvases may not be exported (not using images) JavaScript:toDataUrl()抛出“安全错误:可能无法导出受污染的画布”。 - JavaScript: toDataUrl() throwing “Security Error: Tainted canvases may not be exported.” 带有 React 的 Tesseract.js:受污染的画布可能无法导出 - Tesseract.js with React: Tainted canvases may not be exported DOMException:无法在“HTMLCanvasElement”上执行“toDataURL”:可能无法导出受污染的画布 - DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported 未捕获的 DOMException:无法在“HTMLCanvasElement”上执行“toDataURL”:可能无法导出受污染的画布 - Uncaught DOMException: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported 受污染的“OffscreenCanvas”可能无法导出 - Tainted "OffscreenCanvas" may not be exported 从视频提升创建的画布“可能无法导出受污染的画布。” 保存时出错 - Canvas that created from video raising "Tainted canvases may not be exported." error when saving
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM