简体   繁体   English

Chrome扩展程序图片资源未显示(清单版本2)

[英]Chrome extension image assets not showing up (manifest version 2)

I've just been updating a chrome plugin to manifest version 2. I've had no issues with permissions relating to javascript but the plugin has some image assets packaged with it that are no longer showing up. 我刚刚更新了一个chrome插件来显示版本2.我没有与javascript相关的权限问题,但插件有一些图片资产打包,不再出现。

The two specific cases are in popup notifications when the user interacts with the plugin in certain ways and some small images the plugin inserts into certain pages. 当用户以某种方式与插件交互时,以及插件插入某些页面的一些小图像时,两个特定情况是弹出通知。 In both cases the images are packaged with the plugin. 在这两种情况下,图像都与插件一起打包。 I'm having no issue with the plugin loading images from external resources. 我对从外部资源加载图片的插件没有任何问题。 My object-src setting in the content_security_policy includes 'self' . content_security_policy中的object-src设置包括'self'

What am I missing? 我错过了什么? I can open the images if I navigate to them directly via "chrome-extension:///some_img.png" so they are definitely there. 如果我通过“chrome-extension:///some_img.png”直接导航它们,我可以打开图像,所以它们肯定在那里。 I've used the webkit inspector and finding the img that has been inserted, right clicking on the img src and opening in a new tab also shows the img so the urls being inserted are correct (which they should be, I'm using the chrome.extension.getURL function). 我已经使用webkit检查器并找到已插入的img,右键单击img src并在新选项卡中打开也显示img所以插入的url是正确的(他们应该是,我正在使用chrome.extension.getURL函数)。

UPDATE: 更新:

Setting img-src in the content_security_policy also did nothing. content_security_policy设置img-src也没有做任何事情。 I don't know if chrome even uses that particular option but it's in the W3C spec. 我不知道chrome是否使用了该特定选项,但它符合W3C规范。

After digging through the changelog for the last few chrome versions, I came across a new (added in Chrome 18) manifest option web_accessible_resources . 在深入了解最后几个chrome版本的更新日志之后,我遇到了一个新的(在Chrome 18中添加)清单选项web_accessible_resources This needs to be added to your manifest with a value that's a list of strings. 这需要使用值为字符串列表的值添加到清单中。 The strings are paths in you plugin's directory to resources (imgs etc...) that you want to be accessible within web pages (or importantly, chrome desktop notifications). 字符串是您插件的目录中的路径到您希望在网页中可访问的资源(imgs等...)(或者重要的是,Chrome桌面通知)。 Adding this parameter to my manifest gave permissions for the necessary images to be loaded. 将此参数添加到我的清单中,可以为要加载的必要图像提供权限。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM