谷歌浏览器:允许最多4个chrome.commands?

the*_*of5 11 google-chrome-extension

根据我在Google Chrome浏览器中尝试在manifest.json文件中添加5个或更多内容时出现的以下错误,我遇到了我认为最多允许4个chrome.commands的内容:

"Could not load extension from '[Extension Path]'. Too many commands specified for 'commands': The maximum is 4."

这个限制是否有任何特殊原因,或以任何方式绕过它?

对于上下文:我目前正在开发一个扩展,它将当前页面添加为基于特定热键的特定文件夹的书签,目前沿着ctrl+ alt+ 0,ctrl+ alt+ 1,最多ctrl+ alt+ 9.

Sud*_*han 11

我查看了源代码并找出了以下代码行.

extension_manifest_constants.cc中为error消息声明的常量

const char kInvalidKeyBindingTooMany[] =
    "Too many commands specified for 'commands': The maximum is *.";
Run Code Online (Sandbox Code Playgroud)

extension.cc中的最大命令数声明的常量

// The maximum number of commands (including page action/browser actions) an
// extension can have.
const size_t kMaxCommandsPerExtension = 4;
Run Code Online (Sandbox Code Playgroud)

extension.cc中的验证代码查找以下检查

if (commands - > size() > kMaxCommandsPerExtension) { 
      * error = ErrorUtils::FormatErrorMessageUTF16(
        errors::kInvalidKeyBindingTooMany,
        base::IntToString(kMaxCommandsPerExtension));
        return false;
}
Run Code Online (Sandbox Code Playgroud)

Google开发人员标记为常量为4,因此您暂时无法添加4个以上的命令.

解决方法:

明确这个问题并寻找开发人员的响应,如果你真的想要使用命令,你必须创建多个扩展,每个扩展命令集为4.

如果您需要更多信息,请与我们联系.


小智 8

这是一个非常古老的问题,但我很难在任何地方找到信息,而且这个问题是我的一些搜索的顶级谷歌搜索结果,所以我会在这里添加一些信息。

尽管错误的字眼,您可以拥有任意数量的命令。这个错误实际上是指您可以拥有的“suggested_key”对象的数量。Chrome 的文档指定了以下内容:

一个扩展可以有很多命令,但只能指定 4 个建议的键。

所以在你的清单中,虽然你可以指定额外的命令,但你只能给其中的 4 个“suggested_key”对象

"commands": {
    "contains-suggested-key": {
        "suggested_key": {
            "default": "Ctrl+Shift+Y",
            "mac": "Command+Shift+Y"
        },
        "description": "Toggle feature foo"
      },
      "NO-suggested-key": {
          "description": "user must specify shortcut keys for this from the extensions page"
      }
}
Run Code Online (Sandbox Code Playgroud)