| 类型 |
数组
|
|---|---|
| Mandatory | No |
| 范例 |
|
Instructs the browser to load content scripts into web pages whose URL matches a given pattern.
This key is an array. Each item is an object which:
匹配
, which specifies the URL patterns to be matched in order for the scripts to be loaded;
js
and
css
, which list scripts and/or stylesheets to be loaded into matching pages; and
Details of all the keys you can include are given in the table below.
| 名称 | 类型 | 描述 |
|---|---|---|
all_frames
|
布尔
|
Inject the scripts specified in
注意: This also applies to any tracker or ad that uses iframes, which means that enabling this could make your content script get called dozens of times on some pages.
默认为
|
css
|
数组
|
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 at the time specified by
注意: Firefox resolves URLs in injected CSS files relative to the CSS file itself, rather than to the page it's injected into. |
exclude_globs
|
数组
|
An array of strings containing wildcards. See Matching URL patterns 下文。 |
exclude_matches
|
数组
|
An array of match patterns 。见 Matching URL patterns 下文。 |
include_globs
|
数组
|
An array of strings containing wildcards. See Matching URL patterns 下文。 |
js
|
数组
|
An array of paths, relative to
manifest.json
, 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
The files are injected after any files in
|
match_about_blank
|
布尔
|
Insert the content scripts into pages whose URL is
"about:blank"
or
"about:srcdoc"
, if the URL
of the page that opened or created this page
matches the patterns
specified in
the rest of the
content_scripts
key.
This is especially useful to run scripts in empty iframes , whose URL
is
For example, suppose you have a
If the user loads
注意:
Note that in Firefox, content scripts won't be injected into empty
iframes at
|
匹配
|
数组
|
An array of
match patterns
。见
Matching URL patterns
下文。
This is the only mandatory key. |
run_at
|
字符串
|
This option determines when the files specified in
css
and
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
:
默认值为
|
"content_scripts"
key attaches content scripts to documents based on URL matching: if the document's URL matches the specification in the key, then the script will be attached. There are four properties inside
"content_scripts"
that you can use for this specification:
匹配
an array of match patterns
exclude_matches
an array of match patterns
include_globs
an array of globs
exclude_globs
an array of globs
To match one of these properties, a URL must match at least one of the items in its array. For example, given a property like:
"matches": ["*://*.example.org/*", "*://*.example.com/*"]
Both
http://example.org/
and
http://example.com/
will match.
由于
匹配
is the only mandatory key, the other three keys are used to limit further the URLs that match. To match the key as a whole, a URL must:
匹配
property
include_globs
property, if present
exclude_matches
property, if present
exclude_globs
property, if present
A glob is just a string that may contain wildcards.
There are two types of wildcard, and you can combine them in the same glob:
*
matches zero or more characters
?
matches exactly one character.
例如:
"*na?i"
would match
"illuminati"
and
"annunaki"
, but not
"sagnarelli"
.
"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
.
BCD tables only load in the browser
最后修改: , 由 MDN 贡献者