“Refused to load the image” in a Chrome App

僤鯓⒐⒋嵵緔 提交于 2019-12-24 02:43:08

问题


I have this problem in dart

Refused to load the image 'https://**.png' because it violates the following Content Security Policy directive: "img-src 'self' data: chrome-extension-resource:".

when try to set src in image element

ImageButtonInputElement button = new ImageButtonInputElement();
button.className="button_element";
button.src=el["imageUrl"]; //like "https://**.png"

whit this manifest.json

"content_security_policy":"img-src https://server.example.org"

Someone would know help me?

Thanks

Sorry for my bad English

EDIT

I have the same problem with

<iframe id="iframe" src="https://server.example.org/example.html"></iframe>

Refused to frame https://server.example.org/example.html because it violates the following Content Security Policy directive: "frame-src 'self' data: chrome-extension-resource:".


回答1:


This is the solution I have adopted in the end:

var imgRequest = new HttpRequest();
imgRequest.open('GET', url);
imgRequest.responseType = 'blob';
imgRequest.onReadyStateChange.listen((var request){
  if (imgRequest.readyState == HttpRequest.DONE &&
      imgRequest.status == 200) {
      FileReader reader = new FileReader();
      reader.onLoad.listen((fe) { 
        button.src = reader.result;
      });
      reader.readAsDataUrl(imgRequest.response); 
    }  

});

imgRequest.send();



回答2:


Apps cannot override the CSP. That manifest key is only for extensions.

See documentation for loading remote content for display.

Likewise, you have to use <webview> instead of iframes in a Chrome App.



来源:https://stackoverflow.com/questions/30544033/refused-to-load-the-image-in-a-chrome-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!