I'm building a Google Chrome extension, which injects HTML into a real web page. The injection contains also images and now I wonder how to refer to images within the extension. So far I was able to only refer them on a server using http://example.com/myimage.png. But this takes a noticeable while until they load.
Is it possible to pack images within the extension and refer them from anywhere in the browser? How?
Thanks for any help.
You could use
chrome.runtime.getURL()
(docs) to get the internal extension folder URL. Pass it the image relative path and you'll get the full URL for it.For example, if you have a folder named "images", and an image named "profile.jpg" in it, both in the extension folder, you could inject it into the body of the page by doing:
Also, check out the
web_accessible_resources
manifest property documented here - you might need to declare your resources for them to available in this method.