Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

web_accessible_resources

この記事はまだボランティアによって 日本語 に翻訳されていません。ぜひ MDN に参加して翻訳を手伝ってください!

Type Array
Mandatory No
Example
"web_accessible_resources": [
  "images/my-image.png"
]

Sometimes you will want to package some resources - for example, images, HTML, CSS, or JavaScript - with your extension, and make them available to web pages.

For example, the "beastify" example extension used in the walkthrough tutorial replaces images in a web page with images of some beasts, by setting the src attribute of any <img> elements. The images are packaged with the extension, and for the web page to be able to load them, they must be made web accessible.

The web_accessible_resources key lists all packaged resources that you want to make available to web pages in this way. You specify them as paths relative to the manifest.json file.

The files will then be available using a URL like: "moz-extension://<extension-id>/<path/to/resource>".

For example, consider an entry like this:

  "web_accessible_resources": ["images/my-image.png"]

If your extension's ID is 944cfddf-7a95-3c47-bd9a-663b3ce8d699, then this resource will be available at the following URL:

moz-extension://944cfddf-7a95-3c47-bd9a-663b3ce8d699/images/my-image.png

Entries can contain wildcards, for example:

  "web_accessible_resources": ["images/*.png"]

Will also work.

The easiest way to get this URL, though, is to use the chrome.extension.getURL API, and give it the path relative to manifest.json:

chrome.extension.getURL("images/my-image.png");

Note that content scripts don't need to be listed as web accessible resources.

Example

"web_accessible_resources": ["images/my-image.png"]

Make the file at "images/my-image.png" web accessible.

ドキュメントのタグと貢献者

 このページの貢献者: Makyen, wbamberg, andymckay-github
 最終更新者: Makyen,