Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome: maximum of 4 chrome.commands allowed?

I have run into what I think is a hard maximum of 4 chrome.commands allowed, based on the following error I get in Google Chrome when trying to add 5 or more in the manifest.json file:

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

Is there any particular reason for this limit, or any way to get around it?

For context: I'm currently working on an extension that adds the current page as a bookmark to a specific folder based on a specific hotkey, currently along the lines of ctrl+alt+0, ctrl+alt+1, up to ctrl+alt+9.

like image 509
theborg3of5 Avatar asked Dec 22 '12 05:12

theborg3of5


People also ask

Is there a limit to shortcuts on Chrome?

You can add up to 10 shortcuts. You can also edit the existing shortcuts: just hover your mouse over one, then click the three dots that show up.

How many shortcuts are allowed on Google homepage?

Note: At present Google Chrome only supports a maximum of 10 such website shortcuts on the Homepage. To add shortcuts manually, click on the 'Add shortcut' tile present on the homepage of Google Chrome.


2 Answers

I have looked at source code and figured out following lines of code.

constant declared for error message in extension_manifest_constants.cc

const char kInvalidKeyBindingTooMany[] =
    "Too many commands specified for 'commands': The maximum is *.";

constant declared for maximum number of commands in extension.cc

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

and validation code in extension.cc looks for following check

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

Google developers marked constant to 4, so you can not add more than 4 commands for now.

Work Around:

Star this issue and look for developers response, if you really want to go with commands, you have to create multiple extensions with commands set of 4 for each.

Let me know if you need more information.

like image 174
Sudarshan Avatar answered Oct 19 '22 12:10

Sudarshan


This is a very old question but I had a hard time finding information anywhere and this question was the top google search result for a few of my searches, so I'll add some info here.

Despite the wordage of the error, you can have as many commands as you want. This error actually refers to the number of "suggested_key" objects you can have. Chrome's documents specify the following:

An extension can have many commands but only 4 suggested keys can be specified.

So in your manifest, while you can specify additional commands, you can only give 4 of them the "suggested_key" object

"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"
      }
}
like image 40
SparkleStep Avatar answered Oct 19 '22 12:10

SparkleStep