Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I link to a local image for a Google Chrome Extension?

I want to display an image on a page within my Google Chrome extension, but I want to store the image within a folder called "images" within my chrome extension. How do I link to this image? What URL do I use?

I need it to go here (in place of "URL"). How do I implement it?

<a href="URL"><img src="URL" /></a>

UPDATE

answer did not work; still need help.


1 Answers

var url = chrome.extension.getURL('/folder/file.png');

https://code.google.com/chrome/extensions/extension.html#method-getURL


Update: Added working example.

In index.html:

<img id='someid' src="">

<script>
  var img = document.getElementById('someid');
  img.src = chrome.extension.getURL('/images/google.png');
</script>

In manifest.json:

{
  "name": "My Extension",
  "version": "1"
}

Opening chrome-extension://xyz/index.html shows the image as expected.

like image 69
abraham Avatar answered Sep 21 '25 13:09

abraham