在安装过程中,activeTab 权限不显示任何警告消息。 ### # 选择可选权限 通过包含可选权限,使用户能够从扩展中选择所需的功能和权限。如果某个功能对于扩展程序的核心功能不是必需的,请将其设为可选,然后将 API 或域名移至 optional_permissions 字段中。
{
"name": "Very Secure Extension",
"version": "1.0",
"description": "Example of a Secure Extension",
"permissions": ["activeTab"],
"manifest_version": 2
}
可选权限可以使扩展向用户解释启用相关功能时为何需要特定权限。该扩展可以为用户提供启用功能的选项。
{
"name": "Very Secure Extension",
…
"optional_permissions": [ "tabs", "https://www.google.com/" ],
…
}

然后,将向用户提示以下请求。
document.querySelector('#button').addEventListener('click', function(event) {
// Permissions must be requested from inside a user gesture, like a button's
// click handler.
chrome.permissions.request({
permissions: ['tabs'],
origins: ['https://www.google.com/']
}, function(granted) {
// The callback argument will be true if the user granted the permissions.
if (granted) {
// doSomething();
} else {
// doSomethingElse();
}
});
});

