Microsoft Edge 扩展可以请求访问 file
URL。 若要启用此功能,需要显式配置此访问。 不会自动访问 file
URL。 必须访问 Microsoft Edge 加载项上的“扩展管理”页,才能选择访问file
请求file
访问 URL 的每个 Microsoft Edge 扩展。
对于 Microsoft Edge 扩展,主机权限和内容脚本模式匹配如下所示。
主机权限和内容脚本匹配基于匹配模式定义的一组 URL。 匹配模式实质上是一个 URL,它以允许的方案开头, (http
、 https
、 file
或 ftp
,可以包含“”*
字符。 特殊模式 <all_urls>
与以允许的方案开头的任何 URL 匹配。 每个匹配模式有 3 个部分:
方案 — 例如,
http
或file
*
_host_
— 例如,www.google.com
或 或*.google.com
*
;如果方案是文件,则没有主机部件。_path_
— 例如 、/*
/foo*
或/foo/bar
。 路径必须存在于主机权限中,但始终被视为/*
。
基本语法
基本语法:
<url-pattern> := <scheme>://<host><path>
<scheme> := '*' | 'http' | 'https' | 'file' | 'ftp'
<host> := '*' | '*.' <any char except '/' and '*'>+
<path> := '/' <any chars>
的含义 *
取决于它是在方案、主机还是路径部分中。 如果方案为 *
,则它匹配 http
或 https
,而不是 file
、 或 ftp
。 如果主机只是 *
,则它与任何主机匹配。 如果主机为 *.hostname
,则它与指定的主机或任何子域匹配。 在路径部分中,每个 *
匹配 0 个或多个字符。 下表显示了一些有效的模式。
有效模式的示例
模式 | 功能 | 匹配 URL 的示例 |
---|---|---|
http://*/* |
匹配使用 http 方案的任何 URL |
http://www.google.com
http://example.org/foo/bar.html
|
http://*/foo* |
匹配在任何主机上使用 http 方案的任何 URL,前提是路径以 开头 /foo |
http://example.com/foo/bar.html
http://www.google.com/foo
|
https://*.google.com/foo*bar |
匹配使用 https 方案的任何 URL,位于 google.com 主机上 (,例如 www.google.com 、 docs.google.com 或 google.com ) ,只要路径以 开头 /foo 并结尾 bar |
https://www.google.com/foo/baz/bar
https://docs.google.com/foobar
|
http://example.org/foo/bar.html |
匹配指定的 URL | http://example.org/foo/bar.html |
file:///foo* |
匹配路径以 开头的任何本地文件 /foo |
file:///foo/bar.html
file:///foo
|
http://127.0.0.1/* |
匹配使用 http 方案且位于主机上的任何 URL 127.0.0.1 |
http://127.0.0.1
http://127.0.0.1/foo/bar.html
|
*://mail.google.com/* |
匹配以 或 https://mail.google.com 开头http://mail.google.com 的任何 URL。 |
http://mail.google.com/foo/baz/bar
https://mail.google.com/foobar
|
<all_urls> |
匹配使用允许的方案的任何 URL。 (有关允许的方案列表,请参阅本部分的开头。) |
http://example.org/foo/bar.html
file:///bar/baz.html
|
无效模式的示例
下面是模式匹配的 _invalid_
一些示例:
错误的模式 | 为什么它不好 |
---|---|
http://www.foo.com |
否 _path_ |
http://*foo/bar |
主机中的“”* 后跟只能是“”. 或“”/ |
http://foo.*.bar/baz |
如果 “”* 位于 中 _host_ ,则它必须是第一个字符 |
http:/bar |
缺少 _scheme_ 分隔符 (“/ ”应为“// ”) |
foo://* |
无效 _scheme_ |
某些方案并非在所有上下文中都受支持。
注意
此页面的某些部分是根据 Google 创建和共享的作品所做的修改,并根据 Creative Commons Attribution 4.0 International License 中描述的条款使用。 原始页面位于此处。
本作品根据 Creative Commons Attribution 4.0 International License 获得许可。