1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
---
title: dubla padrões em extensão manifestos
slug: Mozilla/Add-ons/WebExtensions/Match_patterns
translation_of: Mozilla/Add-ons/WebExtensions/Match_patterns
original_slug: Mozilla/Add-ons/WebExtensions/dubla_padrões
---
<div>{{AddonSidebar}}</div>
<p>Match patterns are a way to specify groups of URLs: a match pattern matches a specific set of URLs. They are used in WebExtensions APIs in a few places, most notably to specify which documents to load <a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts">content scripts</a> into, and to specify which URLs to add <code><a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webRequest">webRequest</a></code> listeners to.</p>
<p>APIs that use match patterns usually accept a list of match patterns, and will perform the appropriate action if the URL matches any of the patterns. See, for example, the <code><a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts">content_scripts</a></code> key in manifest.json.</p>
<h2 id="Match_pattern_structure">Match pattern structure</h2>
<div class="note">
<p><strong>Note:</strong> Some browsers don’t support certain schemes.<br>
Check the <a href="#Browser_compatibility">Browser compatibility table</a> for details.</p>
</div>
<p>All match patterns are specified as strings. Apart from the special <code><a href="/en-US/Add-ons/WebExtensions/Match_patterns#%3Call_urls%3E"><all_urls></a></code> pattern, match patterns consist of three parts: <em>scheme</em>, <em>host</em>, and <em>path</em>. The scheme and host are separated by <code>://</code>.</p>
<pre><scheme>://<host><path></pre>
<h3 id="scheme">scheme</h3>
<p>The <em>scheme</em> component may take one of two forms:</p>
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col" style="width: 50%;">Form</th>
<th scope="col">Matches</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>*</code></td>
<td>Only "http" and "https" and in some browsers also <a href="/en-US/docs/Web/API/WebSockets_API">"ws" and "wss"</a>.</td>
</tr>
<tr>
<td>One of <code>http</code>, <code>https</code>, <code>ws</code>, <code>wss</code>, <code>ftp</code>, <code>ftps</code>, <code>data</code> or <code>file</code>.</td>
<td>Only the given scheme.</td>
</tr>
</tbody>
</table>
<h3 id="host">host</h3>
<p>The <em>host</em> component may take one of three forms:</p>
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col" style="width: 50%;">Form</th>
<th scope="col">Matches</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>*</code></td>
<td>Any host.</td>
</tr>
<tr>
<td><code>*.</code> followed by part of the hostname.</td>
<td>The given host and any of its subdomains.</td>
</tr>
<tr>
<td>A complete hostname, without wildcards.</td>
<td>Only the given host.</td>
</tr>
</tbody>
</table>
<p><em>host</em> must not include a port number.</p>
<p><em>host</em> is optional only if the <em>scheme</em> is "file".</p>
<p>Note that the wildcard may only appear at the start.</p>
<h3 id="path">path</h3>
<p>The <em>path</em> component must begin with a <code>/</code>.</p>
<p>After that, it may subsequently contain any combination of the <code>*</code> wildcard and any of the characters that are allowed in URL paths or query strings. Unlike <em>host</em>, the <em>path</em> component may contain the <code>*</code> wildcard in the middle or at the end, and the <code>*</code> wildcard may appear more than once.</p>
<p>The value for the <em>path</em> matches against the string which is the URL path plus the <a href="https://en.wikipedia.org/wiki/Query_string">URL query string</a>. This includes the <code>?</code> between the two, if the query string is present in the URL. For example, if you want to match URLs on any domain where the URL path ends with <code>foo.bar</code>, then you need to use an array of Match Patterns like <code>['*://*/*foo.bar', '*://*/*foo.bar?*']</code>. The <code>?*</code> is needed, rather than just <code>bar*</code>, in order to anchor the ending <code>*</code> as applying to the URL query string and not some portion of the URL path.</p>
<p>Neither the <a href="https://en.wikipedia.org/wiki/Fragment_identifier">URL fragment identifier</a>, nor the <code>#</code> which precedes it, are considered as part of the <em>path</em>.</p>
<div class="blockIndicator note">
<p><strong>Note</strong>: The path pattern string should not include a port number. Adding a port, as in: <em>"http://localhost:1234/*" </em>causes the match pattern to be ignored. However, "<em>http://localhost:1234</em>" will match with "<em>http://localhost/*</em>"</p>
</div>
<h3 id="<all_urls>"><all_urls></h3>
<p>The special value <code><all_urls></code> matches all URLs under any of the supported schemes: that is "http", "https", "ws", "wss", "ftp", "data", and "file".</p>
<h2 id="Examples">Examples</h2>
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col" style="width: 33%;">Pattern</th>
<th scope="col" style="width: 33%;">Example matches</th>
<th scope="col" style="width: 33%;">Example non-matches</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p><code><all_urls></code></p>
<p>Match all URLs.</p>
</td>
<td>
<p><code>http://example.org/</code></p>
<p><code>https://a.org/some/path/</code></p>
<p><code>ws://sockets.somewhere.org/</code></p>
<p><code>wss://ws.example.com/stuff/</code></p>
<p><code>ftp://files.somewhere.org/</code></p>
<p><code>ftps://files.somewhere.org/</code></p>
</td>
<td>
<p><code>resource://a/b/c/</code><br>
(unsupported scheme)</p>
</td>
</tr>
<tr>
<td>
<p><code>*://*/*</code></p>
<p>Match all HTTP, HTTPS and WebSocket URLs.</p>
</td>
<td>
<p><code>http://example.org/</code></p>
<p><code>https://a.org/some/path/</code></p>
<p><code>ws://sockets.somewhere.org/</code></p>
<p><code>wss://ws.example.com/stuff/</code></p>
</td>
<td>
<p><code>ftp://ftp.example.org/</code><br>
(unmatched scheme)</p>
<p><code>ftps://ftp.example.org/</code><br>
(unmatched scheme)</p>
<p><code>file:///a/</code><br>
(unmatched scheme)</p>
</td>
</tr>
<tr>
<td>
<p><code>*://*.mozilla.org/*</code></p>
<p>Match all HTTP, HTTPS and WebSocket URLs that are hosted at "mozilla.org" or one of its subdomains.</p>
</td>
<td>
<p><code>http://mozilla.org/</code></p>
<p><code>https://mozilla.org/</code></p>
<p><code>http://a.mozilla.org/</code></p>
<p><code>http://a.b.mozilla.org/</code></p>
<p><code>https://b.mozilla.org/path/</code></p>
<p><code>ws://ws.mozilla.org/</code></p>
<p><code>wss://secure.mozilla.org/something</code></p>
</td>
<td>
<p><code>ftp://mozilla.org/</code><br>
(unmatched scheme)</p>
<p><code>http://mozilla.com/</code><br>
(unmatched host)</p>
<p><code>http://firefox.org/</code><br>
(unmatched host)</p>
</td>
</tr>
<tr>
<td>
<p><code>*://mozilla.org/</code></p>
<p>Match all HTTP, HTTPS and WebSocket URLs that are hosted at exactly "mozilla.org/".</p>
</td>
<td>
<p><code>http://mozilla.org/</code></p>
<p><code>https://mozilla.org/</code></p>
<p><code>ws://mozilla.org/</code></p>
<p><code>wss://mozilla.org/</code></p>
</td>
<td>
<p><code>ftp://mozilla.org/</code><br>
(unmatched scheme)</p>
<p><code>http://a.mozilla.org/</code><br>
(unmatched host)</p>
<p><code>http://mozilla.org/a</code><br>
(unmatched path)</p>
</td>
</tr>
<tr>
<td>
<p><code>ftp://mozilla.org/</code></p>
<p>Match only "ftp://mozilla.org/".</p>
</td>
<td><code>ftp://mozilla.org</code></td>
<td>
<p><code>http://mozilla.org/</code><br>
(unmatched scheme)</p>
<p><code>ftp://sub.mozilla.org/</code><br>
(unmatched host)</p>
<p><code>ftp://mozilla.org/path</code><br>
(unmatched path)</p>
</td>
</tr>
<tr>
<td>
<p><code>https://*/path</code></p>
<p>Match HTTPS URLs on any host, whose path is "path".</p>
</td>
<td>
<p><code>https://mozilla.org/path</code></p>
<p><code>https://a.mozilla.org/path</code></p>
<p><code>https://something.com/path</code></p>
</td>
<td>
<p><code>http://mozilla.org/path</code><br>
(unmatched scheme)</p>
<p><code>https://mozilla.org/path/</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/a</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/path?foo=1</code><br>
(unmatched path due to URL query string)</p>
</td>
</tr>
<tr>
<td>
<p><code>https://*/path/</code></p>
<p>Match HTTPS URLs on any host, whose path is "path/" and which has no URL query string.</p>
</td>
<td>
<p><code>https://mozilla.org/path/</code></p>
<p><code>https://a.mozilla.org/path/</code></p>
<p><code>https://something.com/path</code>/</p>
</td>
<td>
<p><code>http://mozilla.org/path/</code><br>
(unmatched scheme)</p>
<p><code>https://mozilla.org/path</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/a</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/path/</code><code>?foo=1</code><br>
(unmatched path due to URL query string)</p>
</td>
</tr>
<tr>
<td>
<p><code>https://mozilla.org/*</code></p>
<p>Match HTTPS URLs only at "mozilla.org", with any URL path and URL query string.</p>
</td>
<td>
<p><code>https://mozilla.org/</code></p>
<p><code>https://mozilla.org/path</code></p>
<p><code>https://mozilla.org/another</code></p>
<p><code>https://mozilla.org/path/to/doc</code></p>
<p><code>https://mozilla.org/path/to/doc?foo=1</code></p>
</td>
<td>
<p><code>http://mozilla.org/path</code><br>
(unmatched scheme)</p>
<p><code>https://mozilla.com/path</code><br>
(unmatched host)</p>
</td>
</tr>
<tr>
<td>
<p><code>https://mozilla.org/a/b/c/</code></p>
<p>Match only this URL, or this URL with any URL fragment.</p>
</td>
<td>
<p><code>https://mozilla.org/a/b/c/</code></p>
<p><code>https://mozilla.org/a/b/c/#section1</code></p>
</td>
<td>Anything else.</td>
</tr>
<tr>
<td>
<p><code>https://mozilla.org/*/b/*/</code></p>
<p>Match HTTPS URLs hosted on "mozilla.org", whose path contains a component "b" somewhere in the middle. Will match URLs with query strings, if the string ends in a <code>/</code>.</p>
</td>
<td>
<p><code>https://mozilla.org/a/b/c/</code></p>
<p><code>https://mozilla.org/d/b/f/</code></p>
<p><code>https://mozilla.org/a/b/c/d/</code></p>
<p><code>https://mozilla.org/a/b/c/d/#section1</code></p>
<p><code>https://mozilla.org/a/b/c/d/?foo=/</code></p>
<p><code>https://mozilla.org/a?foo=21314&bar=/b/&extra=c/</code></p>
</td>
<td>
<p><code>https://mozilla.org/b/*/</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/a/b/</code><br>
(unmatched path)</p>
<p><code>https://mozilla.org/a/b/c/d/?foo=bar</code><br>
(unmatched path due to URL query string)</p>
</td>
</tr>
<tr>
<td>
<p><code>file:///blah/*</code></p>
<p>Match any FILE URL whose path begins with "blah".</p>
</td>
<td>
<p><code>file:///blah/</code></p>
<p><code>file:///blah/bleh</code></p>
</td>
<td><code>file:///bleh/</code><br>
(unmatched path)</td>
</tr>
</tbody>
</table>
<h3 id="Invalid_match_patterns">Invalid match patterns</h3>
<table class="fullwidth-table standard-table">
<thead>
<tr>
<th scope="col">Invalid pattern</th>
<th scope="col">Reason</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>resource://path/</code></td>
<td>Unsupported scheme.</td>
</tr>
<tr>
<td><code>https://mozilla.org</code></td>
<td>No path.</td>
</tr>
<tr>
<td><code>https://mozilla.*.org/</code></td>
<td>"*" in host must be at the start.</td>
</tr>
<tr>
<td><code>https://*zilla.org/</code></td>
<td>"*" in host must be the only character or be followed by ".".</td>
</tr>
<tr>
<td><code>http*://mozilla.org/</code></td>
<td>"*" in scheme must be the only character.</td>
</tr>
<tr>
<td><code>https://mozilla.org:80/</code></td>
<td>Host must not include a port number.</td>
</tr>
<tr>
<td><code>*://*</code></td>
<td>Empty path: this should be "<code>*://*/*</code>".</td>
</tr>
<tr>
<td><code>file://*</code></td>
<td>Empty path: this should be "<code>file:///*</code>".</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<h3 id="scheme_2">scheme</h3>
<p>{{Compat("webextensions.match_patterns.scheme",10)}}</p>
|