Extensions use match patterns to specify a group of URLs. They are mainly used to declare host permissions along with other permissions to use certain Chrome APIs or when injecting content scripts. Extensions also use match patterns in:
What is a match pattern?
A match pattern is a URL that begins with a permitted scheme, separated by a
://, followed by a host and path. It can contain wildcard (
*) characters. Most match patterns are composed of three parts:
Each part can use wildcards
*. Below is a detailed description:
scheme: Must include a valid scheme:
'urn'. The wildcard
host: A hostname (
*before the hostname to match subdomains (
*.example.com), or just a wildcard
path: Must start with
/and be present. If alone, it is treated as
/*. For example:
/foo/bar. Each '
*' matches 0 or more characters.
- It matches any URL that starts with a permitted scheme, including any pattern listed under valid patterns. This is a broad host permission, meaning the Chrome web store review may take longer.
- Allows your extension to run on local files. It has no host and requires the user to manually [grant access][permissions-allow-access].
- Localhost URLs and IP addresses
- To match any localhost port during development, use
http://localhost:*/*. For example, it will match any paths under
http://localhost:3000. For IP addresses, specify the address plus a wildcard in the path. For example:
http://127.0.0.1/*. Another approach is to use
http://*:*/*which will match localhost, IP addresses and any port.
- Top Level domain match patterns
- Top Level domain match patterns like
http://google.*/*are not supported. They should be listed individually. For example:
✅ Valid patterns
|Pattern||What it does||Examples|
|Matches any URL that uses the ||https://www.google.com/ |
|Matches any URL that uses the ||http://188.8.131.52/search |
|Matches any URL that uses the ||https://example.com/foo/bar.html https://www.google.com/foo|
|Matches any URL that uses the ||https://www.google.com/foo/baz/bar|
|Matches any local file whose path starts with ||file:///foo/bar.html|
|Matches any URL that uses the ||http://127.0.0.1/|
|Matches any localhost port||http://localhost:3000|
|Matches any URL that starts with ||http://mail.google.com/foo/baz/bar|
|Matches any URL that starts with ||urn:uuid:54723bea-c94e-480e-80c8-a69846c3f582|
❌ Invalid patterns
Here are some examples of invalid match patterns:
|Invalid pattern||Why it's invalid|
|'*' in the host can be followed only by a '.' or '/'|
|If '*' is in the host, it must be the first character|
|Missing scheme separator ("/" should be "//")|
Content scripts can be injected into related frames like
data:, etc by setting
"true" in the manifest. See Injecting in related frames for details.