google-chrome - 仅为主机启用 chrome 扩展
问题描述
嗨,我正在创建我的第一个 chrome 扩展,这是我的 minifest 文件
{
"name": "Get pages source",
"version": "1.0",
"manifest_version": 2,
"description": "Get pages source from a popup",
"browser_action": {
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"default_popup": "popup.html"
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"permissions": ["tabs", "<all_urls>"]
}
我想禁用除少数以外的所有 url 的扩展,可以说我只想为 yahoo.com 和 stackoverflow.com 启用我需要做的扩展。
解决方案
您应该matches
在清单中使用。
https://developer.chrome.com/extensions/content_scripts#declaratively
例如:
{
"name": "Get pages source",
"version": "1.0",
"manifest_version": 2,
"description": "Get pages source from a popup",
"browser_action": {
"default_icon": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"default_popup": "popup.html"
},
"icons": {
"16": "images/get_started16.png",
"32": "images/get_started32.png",
"48": "images/get_started48.png",
"128": "images/get_started128.png"
},
"content_scripts": [
{
"matches": ["http://*.yahoo.com*", "http://*.stackoverflow.com*"]
}
],
"permissions": ["tabs", "<all_urls>"]
}
顺便提一句。all_urls
如果不需要,请避免许可。
推荐阅读
- c# - 如何从列表中获取数字的总和
- android - 从 jarsigner 迁移到 apksigner
- mapbox - 为什么 Carto 底图比 Mapbox 地图更高效?
- c - gcc 从自定义路径链接单个库,但不链接其他库
- asp.net-core - 从右到左语言的 .Net 核心本地化问题
- google-sheets - 根据复选框创建列表
- html - 基于 dir scss 为 html 标签添加样式
- firebase - 在我的云功能中使用 Firestore 触发器 (onUpdate) 时如何访问根文档?
- reactjs - 未定义(未定义,未定义)中的 TypeScript 错误:找不到“src”的类型定义文件。TS2688
- sql - 选择语句 - 使用创建的列进行操作