6

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.

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'.

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. 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).

UPDATE:

Setting img-src in the content_security_policy also did nothing. I don't know if chrome even uses that particular option but it's in the W3C spec.

Endophage
  • 21,038
  • 13
  • 59
  • 90
  • possible duplicate of [Insert an image in chrome extension](http://stackoverflow.com/questions/11804332/insert-an-image-in-chrome-extension) – Rob W Aug 07 '12 at 20:45
  • @RobW half a duplicate, the web_accessible_resources was the thing I needed. Took me a lot of digging to find it and that Q never came up in my searching so hopefully this Q will be easier for people experiencing the same issue (url to extension's images being fine but images not showing) to find. – Endophage Aug 07 '12 at 21:07
  • If I read correctly, you want to insert an image from your extension into a non-extension page. Looks like a close duplicate to me. – Rob W Aug 07 '12 at 21:26
  • @RobW You read not quite correctly. I inserted the image successfully, however it wasn't visible. – Endophage Aug 07 '12 at 22:38
  • That's the same problem as [Insert an image in chrome extension](http://stackoverflow.com/questions/11804332/insert-an-image-in-chrome-extension): Chrome does not prevent `` from being inserted, it just fails to load (thus display) the extension's resource when manifest version 2 is active *and* the when the resource is not added to w_a_r. – Rob W Aug 08 '12 at 09:33
  • @RobW partially the same problem. In that Q the OP didn't know how to get the correct extension url for the resource in the first place. – Endophage Aug 08 '12 at 19:09

1 Answers1

11

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. 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). Adding this parameter to my manifest gave permissions for the necessary images to be loaded.

Stephen Kaiser
  • 1,545
  • 14
  • 10
Endophage
  • 21,038
  • 13
  • 59
  • 90