1 <h1>Match Patterns
</h1>
4 <a href=
"declare_permissions.html#host-permissions">Host
5 permissions
</a> and
<a href=
"content_scripts.html">content
6 script
</a> matching are based on a set of URLs defined by
7 <dfn>match patterns
</dfn>. A match pattern is essentially a
8 URL that begins with a permitted scheme (
<code>http
</code>,
9 <code>https
</code>,
<code>file
</code>,
<code>ftp
</code>, or
10 <code>chrome-extension
</code>),
11 and that can contain '
<code>*
</code>' characters.
13 <code><all_urls
></code> matches any URL
14 that starts with a permitted scheme.
15 Each match pattern has
3 parts:
</p>
19 <li> <em>scheme
</em> —
20 for example,
<code>http
</code> or
<code>file
</code>
24 Access to
<code>file
</code> URLs isn't automatic.
25 The user must visit the extensions management page
26 and opt in to
<code>file
</code> access for each extension that requests it.
29 <li> <em>host
</em> —
30 for example,
<code>www.google.com
</code>
31 or
<code>*.google.com
</code>
33 if the scheme is
<code>file
</code>,
34 there is no
<em>host
</em> part
36 <li> <em>path
</em> —
37 for example,
<code>/*
</code>,
<code>/foo*
</code>,
38 or
<code>/foo/bar
</code>. The path must be present in a
39 host permission, but is always treated
44 <p>Here's the basic syntax:
</p>
47 <em><url-pattern
></em> :=
<em><scheme
></em>://
<em><host
></em><em><path
></em>
48 <em><scheme
></em> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome-extension'
49 <em><host
></em> := '*' | '*.'
<em><any char except '/' and '*'
></em>+
50 <em><path
></em> := '/'
<em><any chars
></em>
54 The meaning of '
<code>*
</code>' depends on whether
55 it's in the
<em>scheme
</em>,
<em>host
</em>, or
<em>path
</em> part.
56 If the
<em>scheme
</em> is
<code>*
</code>,
57 then it matches either
<code>http
</code> or
<code>https
</code>,
58 and
<strong>not
</strong> <code>file
</code>,
<code>ftp
</code>,
59 or
<code>chrome-extension
</code>.
60 If the
<em>host
</em> is just
<code>*
</code>,
61 then it matches any host.
62 If the
<em>host
</em> is
<code>*.
<em>hostname
</em></code>,
63 then it matches the specified host or any of its subdomains.
64 In the
<em>path
</em> section,
65 each '
<code>*
</code>' matches
0 or more characters.
66 The following table shows some valid patterns.
69 <table class=
"simple">
72 <th style=
"margin-left:0; padding-left:0">Pattern
</th>
73 <th style=
"margin-left:0; padding-left:0">What it does
</th>
74 <th style=
"margin-left:0; padding-left:0">Examples of matching URLs
</th>
79 <code>http://*/*
</code>
82 <td>Matches any URL that uses the
<code>http
</code> scheme
</td>
85 http://www.google.com/
<br>
86 http://example.org/foo/bar.html
92 <code>http://*/foo*
</code>
96 Matches any URL that uses the
<code>http
</code> scheme, on any host,
97 as long as the path starts with
<code>/foo
</code>
101 http://example.com/foo/bar.html
<br>
102 http://www.google.com/foo
<b></b>
108 <code>https://*.google.com/foo*bar
</code>
112 Matches any URL that uses the
<code>https
</code> scheme,
113 is on a google.com host
114 (such as www.google.com, docs.google.com, or google.com),
115 as long as the path starts with
<code>/foo
</code>
116 and ends with
<code>bar
</code>
120 http://www.google.com/foo/baz/bar
<br>
121 http://docs.google.com/foobar
127 <code>http://example.org/foo/bar.html
</code>
130 <td>Matches the specified URL
</td>
133 http://example.org/foo/bar.html
139 <code>file:///foo*
</code>
142 <td>Matches any local file whose path starts with
<code>/foo
</code>
146 file:///foo/bar.html
<br>
153 <code>http://
127.0.0.1/*
</code>
157 Matches any URL that uses the
<code>http
</code> scheme
158 and is on the host
127.0.0.1
161 http://
127.0.0.1/
<br>
162 http://
127.0.0.1/foo/bar.html
168 <code>*://mail.google.com/*
</code>
172 Matches any URL that starts with
173 <code>http://mail.google.com
</code> or
174 <code>https://mail.google.com
</code>.
178 http://mail.google.com/foo/baz/bar
<br>
179 https://mail.google.com/foobar
185 <code>chrome-extension://*/*
</code>
189 Matches any URL pointing to an extension (the first
<code>*
</code>
190 represents a filter for extension IDs, the second for paths).
194 chrome-extension://askla...asdf/options.html
200 <code><all_urls
></code>
204 Matches any URL that uses a permitted scheme.
205 (See the beginning of this section for the list of permitted
209 http://example.org/foo/bar.html
<br>
217 Here are some examples of
<em>invalid
</em> pattern matches:
220 <table class=
"simple">
223 <th style=
"margin-left:0; padding-left:0">Bad pattern
</th>
224 <th style=
"margin-left:0; padding-left:0">Why it's bad
</th>
228 <td><code>http://www.google.com
</code></td>
229 <td>No
<em>path
</em></td>
233 <td><code>http://*foo/bar
</code></td>
234 <td>'*' in the
<em>host
</em> can be followed only by a '.' or '/'
</td>
238 <td><code>http://foo.*.bar/baz
</code></td>
239 <td>If '*' is in the
<em>host
</em>, it must be the first character
</td>
243 <td><code>http:/bar
</code></td>
244 <td>Missing
<em>scheme
</em> separator (
"/" should be
"//")
</td>
248 <td><code>foo://*
</code></td>
249 <td>Invalid
<em>scheme
</em></td>
255 Some schemes are not supported in all contexts.