この翻訳は不完全です。英語から この記事を翻訳 してください。
タイプ | 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
andcss
, 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 |
Defaults to |
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 If the URL of a page matches a pattern in |
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:
then Files are injected at the time specified by |
matches |
Array |
An array of match patterns. The scripts specified in
This is the only mandatory key. |
run_at |
String |
This option determines when the scripts specified in
The default value is |
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".