[英]Same origin policy, google chrome, canvas and file:// scheme
When trying to read image data from a canvas which was painted an image upon beforehand, Google Chrome raises a cross origin exception (complaining about the canvas being "tainted"). 当尝试从预先绘制图像的画布上读取图像数据时,谷歌浏览器引发了一个交叉起源异常(抱怨画布被“污染”)。 The directory structure is as follows.
目录结构如下。
/html/base/path
|-- index.html contains the canvas element, references the script.js
|-- script.js loads imgs/images.jpg, paints and queries the canvas
`-- imgs/image.jpg
The error occurs only when the page was loaded by the file:// scheme. 仅当页面由file:// scheme加载时才会发生错误。
I wonder whether this is a Chrome bug. 我想知道这是否是一个Chrome bug。 If not, which rules do apply?
如果不是,哪些规则适用? Are there any workarounds?
有没有解决方法?
Unfortunately, off-line viewing is the ultimate use case, so 不幸的是,离线观看是最终的用例,所以
Files loaded with file://
are always considered as coming from different domains, this is a feature you can't bypass. 使用
file://
加载的file://
始终被视为来自不同的域,这是您无法绕过的功能。
From the HTML5 spec's definition of Origin : 从HTML5规范的Origin定义 :
If a Document was obtained in some other manner (eg a data: URL typed in by the user, a Document created using the createDocument() API, etc) The origin is a globally unique identifier assigned when the Document is created.
如果以某种其他方式获取文档(例如,数据:用户键入的URL,使用createDocument()API创建的文档等)原点是在创建文档时分配的全局唯一标识符。
You can display but you can't analyze or change data read from another file if the loading protocol is file:
. 您可以显示但如果加载协议是
file:
则无法分析或更改从另一个文件读取的数据file:
。
What I would probably do in your situation (if I understand it correctly from your comments) : I would write a tiny program, that could be released in the external storage media, which would both start an http server and launch a web browser. 在你的情况下我可能会做什么(如果我从你的评论中正确理解的话):我会写一个小程序,可以在外部存储介质中发布,这将启动一个http服务器并启动一个Web浏览器。 I would do it in Go (simple to make an http server in two or three lines, native compilation for linux, Mac and Windows, enabling you to provide all needed executables) but other languages can be used too.
我会在Go(简单地用两行或三行制作一个http服务器,用于linux,Mac和Windows的原生编译,使你能够提供所有需要的可执行文件)中做到这一点,但也可以使用其他语言。
Give them instructions for them to start up chrome with the flag --allow-file-access-from-files
. 给他们指示他们用标志
--allow-file-access-from-files
启动chrome。
Other than that, they would need to run a local server instance to avoid the errors. 除此之外,他们需要运行本地服务器实例以避免错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.