Chrome扩展声明权限混淆

Chrome Extension Declare Permissions confusion

本文关键字:权限 声明 扩展 Chrome      更新时间:2023-09-26

为高对比度设置指定键盘快捷键的简单扩展,以便在不经过菜单的情况下进行切换。问题:下面的代码正在生成此错误

ChromeSetting.get:您无权访问首选项"highContrast"。请确保在清单中声明您需要的权限。

API简介https://developer.chrome.com/extensions/accessibilityFeatures#property-highContrast说要声明accessibilityFeatures.modifyaccessibilityFeatures.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);
    });
  }
});

"accessibilityFeatures.read""accessibilityFeatures.modify"目前仅在Chrome操作系统中受支持,而在其他操作系统中不受支持,如中所示https://chromium.googlesource.com/chromium/src/+/7c61e0145f3e598ae7a9acc9159234d6ec7f6008/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"]
  },