简单扩展,为高对比度设置指定键盘快捷键,以便在不经过菜单的情况下切换它。问题:以下代码产生此错误
ChromeSetting.get:您无权访问首选项'highContrast'。请务必在清单中声明所需的权限。
此API https://developer.chrome.com/extensions/accessibilityFeatures#property-highContrast的介绍说明了我已完成的accessibilityFeatures.modify
和accessibilityFeatures.read
,但这些权限都不在声明的权限列表https://developer.chrome.com/extensions/declare_permissions上,所以我不知道从哪里开始......
的manifest.json
{
"name": "High Contrast Shortcut",
"description": "Press Ctrl+Shift+Y to send an event.",
"version": "1.0",
"default_locale": "en",
"manifest_version": 2,
"background": {
"scripts": ["src/bg/background.js"],
"persistent": true
},
"permissions": [
"accessibilityFeatures.read",
"accessibilityFeatures.modify"
],
"commands": {
"toggle-feature": {
"suggested_key": { "default": "Ctrl+Shift+Y" },
"description": "Send a 'toggle-feature' event to the extension"
}
}
}
background.js
chrome.commands.onCommand.addListener(function(command) {
if (command == "toggle-feature") {
var value = chrome.accessibilityFeatures.highContrast.get({'incognito': false}, function (callback) {
console.log(callback);
});
}
});
答案 0 :(得分:0)
"accessibilityFeatures.read"
和"accessibilityFeatures.modify"
目前仅支持Chrome操作系统,而不支持其他操作系统,如https://chromium.googlesource.com/chromium/src/+/7c61e0145f3e598ae7a9ac69159234d6ec7f6008/chrome/common/extensions/api/_permission_features.json所示:
"accessibilityFeatures.modify": {
"channel": "stable",
"extension_types": ["extension", "platform_app"],
"platforms": ["chromeos"]
},
"accessibilityFeatures.read": {
"channel": "stable",
"extension_types": ["extension", "platform_app"],
"platforms": ["chromeos"]
},