Chrome 扩展清单权限 v3
Chrome extension manifest permissions v3
好的,我正在做我的第一个 chrome 扩展,我 运行 遇到了一些问题:
manifest.json
{
"name": "...",
"description": "...",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": [
"tabs",
"scripting",
"activeTab"
],
"host_permissions": [
"tabs",
"scripting",
"activeTab"
]
}
background.js
chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
if (info.status == 'complete') changeTheme(tab);
});
function changeTheme(tab) {
chrome.scripting.insertCSS({
target: {tabId: tab.id},
css: "h1 { color: #212121; }"
})
}
扩展开发工具控制台记录如下:
Error: Cannot access contents of url "long ass url". Extension manifest must request permission to access this host.
我将如何“请求”许可?
"host_permissions"
用于匹配 urls
而非权限。
改变这个:
"host_permissions": [
"tabs",
"scripting",
"activeTab"
]
进入这个:
"host_permissions": [
"https://example.org/foo/bar.html"
]
或您希望扩展可用的任何其他网址(预计 chrome://
)
如果您希望扩展程序在所有站点上可用,请使用:
"host_permissions": [
"<all_urls>"
]
好的,我正在做我的第一个 chrome 扩展,我 运行 遇到了一些问题:
manifest.json
{
"name": "...",
"description": "...",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": [
"tabs",
"scripting",
"activeTab"
],
"host_permissions": [
"tabs",
"scripting",
"activeTab"
]
}
background.js
chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
if (info.status == 'complete') changeTheme(tab);
});
function changeTheme(tab) {
chrome.scripting.insertCSS({
target: {tabId: tab.id},
css: "h1 { color: #212121; }"
})
}
扩展开发工具控制台记录如下:
Error: Cannot access contents of url "long ass url". Extension manifest must request permission to access this host.
我将如何“请求”许可?
"host_permissions"
用于匹配 urls
而非权限。
改变这个:
"host_permissions": [
"tabs",
"scripting",
"activeTab"
]
进入这个:
"host_permissions": [
"https://example.org/foo/bar.html"
]
或您希望扩展可用的任何其他网址(预计 chrome://
)
如果您希望扩展程序在所有站点上可用,请使用:
"host_permissions": [
"<all_urls>"
]