admin管理员组文章数量:1314315
I have little problem. I need to connect image from the internet in my app, but I encounter error.
Refused to load the image 'http//testdomain/test_img.jpg' because it violates the following Content Security Policy directive: "img-src 'self' data: chrome-extension-resource:".
manifest.json
{
"name": "TEST",
"description": "TEST for TEST",
"version": "0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
"storage",
"fullscreen",
],
"content_security_policy": "img-src 'self' data: chrome-extension-resource:;",
"icons": {"128": "icon.png" }
}
index.html
<html><img src="http://testdomain/test_img.jpg"></html>
I have little problem. I need to connect image from the internet in my app, but I encounter error.
Refused to load the image 'http//testdomain/test_img.jpg' because it violates the following Content Security Policy directive: "img-src 'self' data: chrome-extension-resource:".
manifest.json
{
"name": "TEST",
"description": "TEST for TEST",
"version": "0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
"storage",
"fullscreen",
],
"content_security_policy": "img-src 'self' data: chrome-extension-resource:;",
"icons": {"128": "icon.png" }
}
index.html
<html><img src="http://testdomain/test_img.jpg"></html>
Share
Improve this question
edited Feb 19, 2016 at 17:20
Mark Pattison
3,0391 gold badge23 silver badges45 bronze badges
asked Mar 3, 2014 at 17:03
vovcyanvovcyan
311 silver badge2 bronze badges
2 Answers
Reset to default 6Setting or removing content_security_policy
with different options did not work at all for me, but there is a very good explanation in the chrome dev docs:
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://supersweetdomainbutnotcspfriendly./image.png', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
var img = document.createElement('img');
img.src = window.URL.createObjectURL(this.response);
document.body.appendChild(img);
};
xhr.send();
Source: https://developer.chrome./apps/app_external#webview
You just need to load the image with XMLHttpRequest
. I did NOT need to add the host to the permissions
though. Which is good, because in my case the host is dynamic.
Because you're trying to load an image from an external source, it violates the CSP you have in there:
img-src 'self' data: chrome-extension-resource
Just remove the CSP entirely.
本文标签: javascriptContent Security Policy Chrome App (imgsrc)Stack Overflow
版权声明:本文标题:javascript - Content Security Policy Chrome App (img-src) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741958533a2407130.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论