files/en-us/mozilla/add-ons/webextensions/match_patterns/index.md
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 content scripts into, and to specify which URLs to add webRequest listeners to.
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 content_scripts key in manifest.json.
[!NOTE] Some browsers don't support certain schemes. Check the Browser compatibility table for details.
All match patterns are specified as strings. Apart from the special <all_urls> pattern, match patterns consist of three parts: scheme, host, and path. The scheme and host are separated by ://.
<scheme>://<host><path>
The scheme component may take one of two forms:
<table class="fullwidth-table standard-table"> <thead> <tr> <th scope="col">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>data</code>, <code>file</code>, or <code>(chrome-)extension</code>. </td> <td>Only the given scheme.</td> </tr> </tbody> </table>The host component may take one of these forms:
<table class="fullwidth-table standard-table"> <thead> <tr> <th scope="col">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, optionally, including a port.</td> <td>The given host (and port) and any of its subdomains.</td> </tr> <tr> <td>A complete hostname, without wildcards, optionally, including a port.</td> <td>Only the host (and port).</td> </tr> </tbody> </table>[!NOTE] Firefox doesn't support the inclusion of a port number due to (Firefox bug 1362809) and (Firefox bug 1468162).
host is optional only if the scheme is "file".
Note that the wildcard may only appear at the start.
The path component must begin with a /.
After that, it may subsequently contain any combination of the * wildcard and any of the characters that are allowed in URL paths or query strings. Unlike host, the path component may contain the * wildcard in the middle or at the end, and the * wildcard may appear more than once.
The value for the path matches against the string which is the URL path plus the URL query string. This includes the ? 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 foo.bar, then you need to use an array of Match Patterns like ["*://*/*foo.bar", "*://*/*foo.bar?*"]. The ?* is needed, rather than just bar*, in order to anchor the ending * as applying to the URL query string and not some portion of the URL path.
Neither the URL fragment identifier nor the # that precedes it are considered as part of the path and are ignored during pattern matching. A match pattern containing # will fail to match with any URL.
The special value <all_urls> matches all URLs under any of the supported schemes: that is "http", "https", "ws", "wss", "ftp", "data", and "file".
{{Compat}}