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

content_scripts

この翻訳は不完全です。英語から この記事を翻訳 してください。

タイプ Array
必須か No

与えられたパターンにURLがマッチしているページにコンテンツスクリプトをロードすることをブラウザに教えます。

このキーはarrayです。それぞれのアイテムは以下の条件を満たすobjectです:

  • 必ずmatchesという名前のキーを含まなければなりません。that specifies the URL patterns to be matched in order for the scripts to be loaded
  • may contain keys named js and css, which list scripts to be loaded into matching pages
  • may contain a number of other properties that control finer aspects of how and when content scripts are loaded

Details of all the keys you can include are given in the table below.

Name Type Description
all_frames Boolean

true: inject the scripts specified in js and css into all frames in the page.

false: inject into only the topmost frame.

Defaults to false.

css Array

An array of paths, relative to manifest.json, referencing CSS files that will be injected into matching pages.

Files are injected in the order given, and before the DOM is loaded.

exclude_matches Array

An array of match patterns. Use this to exclude pages that are matched by matches.

If the URL of a page matches a pattern in matches, and also matches a pattern in exclude_matches, then the scripts specified in js and css will not be loaded into it.

js Array

An array of paths, relative to the manifest.json file, referencing JavaScript files that will be injected into matching pages.

Files are injected in the order given. This means that, for example, if you include jQuery here followed by another content script, like this:

"js": ["jquery.js", "my-content-script.js"]

then "my-content-script.js" can use jQuery.

Files are injected at the time specified by run_at.

matches Array

An array of match patterns. The scripts specified in js and css will be loaded into a page only if the URL of the page:

  • matches any of the match patterns specified in matches, and
  • does not match any of the match patterns specified in exclude_matches.

This is the only mandatory key.

run_at String

This option determines when the scripts specified in js are injected. You can supply one of three strings here, each of which identifies a state in the process of loading a document. The states directly correspond to Document.readyState:

  • "document_start": corresponds to loading. The DOM is still loading.
  • "document_end": corresponds to interactive. The DOM has finished loading, but resources such as scripts and images may still be loading.
  • "document_idle": corresponds to complete. The document and all its resources have finished loading.

The default value is "document_idle".

In all cases, files in js are injected after files in css.

Chrome incompatibilities

Firefox does not support:

  • match_about_blank

"content_scripts": [
  {
    "matches": ["*://*.mozilla.org/*"],
    "js": ["borderify.js"]
  }
]

This injects a single content script "borderify.js" into all pages under "mozilla.org" or any of its subdomains, whether served over HTTP or HTTPS.

  "content_scripts": [
    {
      "exclude_matches": ["*://developer.mozilla.org/*"],
      "matches": ["*://*.mozilla.org/*"],
      "js": ["jquery.js", "borderify.js"]
    }
  ]

This injects two content scripts into all pages under "mozilla.org" or any of its subdomains except "developer.mozilla.org", whether served over HTTP or HTTPS.

The content scripts see the same view of the DOM and are injected in the order they appear in the array, so "borderify.js" can see global variables added by "jquery.js".

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

 このページの貢献者: lv7777
 最終更新者: lv7777,