OLD | NEW |
(Empty) | |
| 1 <h1>Match Patterns</h1> |
| 2 |
| 3 <p> |
| 4 <a href="content_scripts.html">Content scripts</a> operate on |
| 5 a set of URLs defined by match patterns. |
| 6 You can put one or more match patterns |
| 7 in the <code>"matches"</code> part of |
| 8 a content script's section of the manifest, |
| 9 as well as in the <code>"exclude_matches"</code> section. |
| 10 This page describes the match pattern syntax — |
| 11 the rules you need to follow when you specify |
| 12 which URLs your content script affects. |
| 13 </p> |
| 14 |
| 15 <p> |
| 16 A match pattern is essentially a URL |
| 17 that begins with a permitted scheme (<code>http</code>, |
| 18 <code>https</code>, <code>file</code>, <code>ftp</code>, or |
| 19 <code>chrome-extension</code>), |
| 20 and that can contain '<code>*</code>' characters. |
| 21 The special pattern |
| 22 <code><all_urls></code> matches any URL |
| 23 that starts with a permitted scheme. |
| 24 Each match pattern has 3 parts:</p> |
| 25 </p> |
| 26 |
| 27 <ul> |
| 28 <li> <em>scheme</em> — |
| 29 for example, <code>http</code> or <code>file</code> |
| 30 or <code>*</code> |
| 31 <p class="note"> |
| 32 <b>Note:</b> |
| 33 Access to <code>file</code> URLs isn't automatic. |
| 34 The user must visit the extensions management page |
| 35 and opt in to <code>file</code> access for each extension that requests it. |
| 36 </p> |
| 37 </li> |
| 38 <li> <em>host</em> — |
| 39 for example, <code>www.google.com</code> |
| 40 or <code>*.google.com</code> |
| 41 or <code>*</code>; |
| 42 if the scheme is <code>file</code>, |
| 43 there is no <em>host</em> part |
| 44 </li> |
| 45 <li> <em>path</em> — |
| 46 for example, <code>/*</code>, <code>/foo* </code>, |
| 47 or <code>/foo/bar </code> |
| 48 </li> |
| 49 </ul> |
| 50 |
| 51 <p>Here's the basic syntax:</p> |
| 52 |
| 53 <pre> |
| 54 <em><url-pattern></em> := <em><scheme></em>://<em><host></em><
em><path></em> |
| 55 <em><scheme></em> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome-ext
ension' |
| 56 <em><host></em> := '*' | '*.' <em><any char except '/' and '*'></em>
+ |
| 57 <em><path></em> := '/' <em><any chars></em> |
| 58 </pre> |
| 59 |
| 60 <p> |
| 61 The meaning of '<code>*</code>' depends on whether |
| 62 it's in the <em>scheme</em>, <em>host</em>, or <em>path</em> part. |
| 63 If the <em>scheme</em> is <code>*</code>, |
| 64 then it matches either <code>http</code> or <code>https</code>. |
| 65 If the <em>host</em> is just <code>*</code>, |
| 66 then it matches any host. |
| 67 If the <em>host</em> is <code>*.<em>hostname</em></code>, |
| 68 then it matches the specified host or any of its subdomains. |
| 69 In the <em>path</em> section, |
| 70 each '<code>*</code>' matches 0 or more characters. |
| 71 The following table shows some valid patterns. |
| 72 </p> |
| 73 |
| 74 <table class="columns"> |
| 75 <tbody> |
| 76 <tr> |
| 77 <th style="margin-left:0; padding-left:0">Pattern</th> |
| 78 <th style="margin-left:0; padding-left:0">What it does</th> |
| 79 <th style="margin-left:0; padding-left:0">Examples of matching URLs</th> |
| 80 </tr> |
| 81 |
| 82 <tr> |
| 83 <td> |
| 84 <code>http://*/*</code> |
| 85 </td> |
| 86 |
| 87 <td>Matches any URL that uses the <code>http</code> scheme</td> |
| 88 |
| 89 <td> |
| 90 http://www.google.com/<br> |
| 91 http://example.org/foo/bar.html |
| 92 </td> |
| 93 </tr> |
| 94 |
| 95 <tr> |
| 96 <td> |
| 97 <code>http://*/foo*</code> |
| 98 </td> |
| 99 |
| 100 <td> |
| 101 Matches any URL that uses the <code>http</code> scheme, on any host, |
| 102 as long as the path starts with <code>/foo</code> |
| 103 </td> |
| 104 |
| 105 <td> |
| 106 http://example.com/foo/bar.html<br> |
| 107 http://www.google.com/foo<b></b> |
| 108 </td> |
| 109 </tr> |
| 110 |
| 111 <tr> |
| 112 <td> |
| 113 <code>https://*.google.com/foo*bar </code> |
| 114 </td> |
| 115 |
| 116 <td> |
| 117 Matches any URL that uses the <code>https</code> scheme, |
| 118 is on a google.com host |
| 119 (such as www.google.com, docs.google.com, or google.com), |
| 120 as long as the path starts with <code>/foo</code> |
| 121 and ends with <code>bar</code> |
| 122 </td> |
| 123 |
| 124 <td> |
| 125 http://www.google.com/foo/baz/bar<br> |
| 126 http://docs.google.com/foobar |
| 127 </td> |
| 128 </tr> |
| 129 |
| 130 <tr> |
| 131 <td> |
| 132 <code>http://example.org/foo/bar.html </code> |
| 133 </td> |
| 134 |
| 135 <td>Matches the specified URL</td> |
| 136 |
| 137 <td> |
| 138 http://example.org/foo/bar.html |
| 139 </td> |
| 140 </tr> |
| 141 |
| 142 <tr> |
| 143 <td> |
| 144 <code>file:///foo*</code> |
| 145 </td> |
| 146 |
| 147 <td>Matches any local file whose path starts with <code>/foo</code> |
| 148 </td> |
| 149 |
| 150 <td> |
| 151 file:///foo/bar.html<br> |
| 152 file:///foo |
| 153 </td> |
| 154 </tr> |
| 155 |
| 156 <tr> |
| 157 <td> |
| 158 <code>http://127.0.0.1/*</code> |
| 159 </td> |
| 160 |
| 161 <td> |
| 162 Matches any URL that uses the <code>http</code> scheme |
| 163 and is on the host 127.0.0.1 |
| 164 </td> |
| 165 <td> |
| 166 http://127.0.0.1/<br> |
| 167 http://127.0.0.1/foo/bar.html |
| 168 </td> |
| 169 </tr> |
| 170 |
| 171 <tr> |
| 172 <td> |
| 173 <code>*://mail.google.com/* </code> |
| 174 </td> |
| 175 |
| 176 <td> |
| 177 Matches any URL that starts with |
| 178 <code>http://mail.google.com</code> or |
| 179 <code>https://mail.google.com</code>. |
| 180 </td> |
| 181 |
| 182 <td> |
| 183 http://mail.google.com/foo/baz/bar<br> |
| 184 https://mail.google.com/foobar |
| 185 </td> |
| 186 </tr> |
| 187 |
| 188 <tr> |
| 189 <td> |
| 190 <code>chrome-extension://*/* </code> |
| 191 </td> |
| 192 |
| 193 <td> |
| 194 Matches any URL pointing to an extension (the first <code>*</code> |
| 195 represents a filter for extension IDs, the second for paths). |
| 196 </td> |
| 197 |
| 198 <td> |
| 199 chrome-extension://askla...asdf/options.html |
| 200 </td> |
| 201 </tr> |
| 202 |
| 203 <tr> |
| 204 <td> |
| 205 <code><all_urls></code> |
| 206 </td> |
| 207 |
| 208 <td> |
| 209 Matches any URL that uses a permitted scheme. |
| 210 (See the beginning of this section for the list of permitted |
| 211 schemes.) |
| 212 </td> |
| 213 <td> |
| 214 http://example.org/foo/bar.html<br> |
| 215 file:///bar/baz.html |
| 216 </td> |
| 217 </tr> |
| 218 </tbody> |
| 219 </table> |
| 220 |
| 221 <p> |
| 222 Here are some examples of <em>invalid</em> pattern matches: |
| 223 </p> |
| 224 |
| 225 <table class="columns"> |
| 226 <tbody> |
| 227 <tr> |
| 228 <th style="margin-left:0; padding-left:0">Bad pattern</th> |
| 229 <th style="margin-left:0; padding-left:0">Why it's bad</th> |
| 230 </tr> |
| 231 |
| 232 <tr> |
| 233 <td><code>http://www.google.com</code></td> |
| 234 <td>No <em>path</em></td> |
| 235 </tr> |
| 236 |
| 237 <tr> |
| 238 <td><code>http://*foo/bar</code></td> |
| 239 <td>'*' in the <em>host</em> can be followed only by a '.' or '/'</td> |
| 240 </tr> |
| 241 |
| 242 <tr> |
| 243 <td><code>http://foo.*.bar/baz </code></td> |
| 244 <td>If '*' is in the <em>host</em>, it must be the first character</td> |
| 245 </tr> |
| 246 |
| 247 <tr> |
| 248 <td><code>http:/bar</code></td> |
| 249 <td>Missing <em>scheme</em> separator ("/" should be "//")</td> |
| 250 </tr> |
| 251 |
| 252 <tr> |
| 253 <td><code>foo://*</code></td> |
| 254 <td>Invalid <em>scheme</em></td> |
| 255 </tr> |
| 256 </tbody> |
| 257 </table> |
| 258 |
| 259 <p> |
| 260 Some schemes are not supported in all contexts. |
| 261 </p> |
OLD | NEW |