我正在尝试理解以下两者之间的区别:
"permissions": [
"*.google.com"
],
并且
"content_scripts": [
{
"matches": ["*.google.com"]
}
]
我正在尝试理解以下两者之间的区别:
"permissions": [
"*.google.com"
],
并且
"content_scripts": [
{
"matches": ["*.google.com"]
}
]
1. 域名权限
网页无法进行跨域XMLHttpRequest (AJAX)请求,但是扩展程序可以。在权限中添加域名将允许您从内容脚本对指定的域名进行ajax请求。
2. 匹配模式
内容脚本工作于已加载的页面内。通过 matches
,您可以指定要注入内容脚本的页面。
例如:我想从 openweathermap.org 获取天气数据,并仅在 google.com 页面上显示数据。
"permissions": [
"http://api.openweathermap.org/*"
],
"content_scripts": [
{
"matches": ["https://*.google.com/*"],
"js": ["js/content.js"]
}
]