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