0

Is there a way to send an image from the background page of a chrome extension to a content script, in such a way that the content script does not retrieve the image from an external webpage to display, but uses the image stored with the extension locally?

Perhaps using the sendMessage API?

Xan
  • 74,770
  • 16
  • 179
  • 206
Jack
  • 391
  • 5
  • 25
  • How do you get the image? How do you store it (if you do it already)? – Xan Apr 07 '15 at 14:29
  • @Xan the image is already stored in a local directory that is packaged with the extension, I want to be able to pass it from the background page to the content script so it can be displayed on a given webpage – Jack Apr 07 '15 at 15:53

1 Answers1

2

You don't need to "pass" an image that is already in the packaged resources.

All you need to use it is:

  1. Use the chrome.runtime.getURL() function, which can be used in a content script:

    // Use relative path in the package directory
    img.src = chrome.runtime.getURL("images/image.png")
    
  2. Whitelist the image in "web_accessible_resources" in the manifest:

    "web_accessible_resources": [
      "images/*.png"
    ],
    
Xan
  • 74,770
  • 16
  • 179
  • 206