Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 3.0 License, and code samples are licensed under the BSD License.
©2009 Google
Content scripts operate on
a set of URLs defined by match patterns.
You can put one or more match patterns
in the "matches"
part of
a content script's section of the manifest.
This page describes the match pattern syntax —
the rules you need to follow when you specify
which URLs your content script affects.
A match pattern is essentially a URL
that begins with http
, https
,
file
, or ftp
,
and that can contain '*
' characters.
Each match pattern has 3 parts:
http
or file
www.google.com
or *.google.com
or *
;
if the scheme is file
,
there is no host part
/*
, /foo*
,
or /foo/bar
Here's the basic syntax:
<url-pattern> := <scheme>://<host><path>
<scheme> := 'http' | 'https' | 'file' | 'ftp'
<host> := '*' | '*.' <any char except '/' and '*'>+
<path> := '/' <any chars>
The meaning of '*
' depends on whether
it's in the host or the path part.
If the host is just *
,
then it matches any host.
If the host is *.hostname
,
then it matches the specified host or any of its subdomains.
In the path section,
each '*
' matches 0 or more characters.
The following table shows some valid patterns.
Pattern | What it does | Examples of matching URLs |
---|---|---|
http://*/*
|
Matches any URL that uses the http scheme |
http://www.google.com/ http://example.org/foo/bar.html |
http://*/foo*
|
Matches any URL that uses the http scheme, on any host,
as long as the path starts with /foo
|
http://example.com/foo/bar.html http://www.google.com/foo |
https://*.google.com/foo*bar
|
Matches any URL that uses the https scheme,
is on a google.com host
(such as www.google.com, docs.google.com, or google.com),
as long as the path starts with /foo
and ends with bar
|
http://www.google.com/foo/baz/bar http://docs.google.com/foobar |
http://example.org/foo/bar.html
|
Matches the specified URL | http://example.org/foo/bar.html |
file:///foo*
|
Matches any local file whose path starts with /foo |
file:///foo/bar.html file:///foo |
http://127.0.0.1/*
|
Matches any URL that uses the http scheme
and is on the host 127.0.0.1
|
http://127.0.0.1/ http://127.0.0.1/foo/bar.html |
Here are some examples of invalid pattern matches:
Bad pattern | Why it's bad |
---|---|
http://* |
No path |
http://*foo/bar |
'*' in the host can be followed only by a '.' or '/' |
http://foo.*.bar/baz |
If '*' is in the host, it must be the first character |
http:/bar |
Missing scheme separator ("/" should be "//") |
foo://* |
Invalid scheme |