The commands key is an object, and each shortcut is a property of it. The property's name is the name of the shortcut.
Each shortcut's value is an object, with up to 2 properties:
-
suggested_key: the combination of keys that activate the shortcut. -
description: a string that describes the shortcut; i.e. what it does.
The suggested_key property is an object with any of the following properties (all strings):
"default" "mac" "linux" "windows" "chromeos" "android" "ios"
The value of each property is the keyboard shortcut for the command on that platform, as a string containing keys separated by "+". The value for "default" is used on all platforms that are not explicitly listed.
For example:
"commands": {
"toggle-feature": {
"suggested_key": {
"default": "Alt+Shift+U",
"linux": "Ctrl+Shift+U"
},
"description": "Send a 'toggle-feature' event to the extension"
},
"do-another-thing": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
}
}
}
This JSON defines 2 shortcuts:
-
"toggle-feature", accessed with Ctrl + Shift + U on Linux, and Alt + Shift + U on all other platforms. -
"do-another-thing", accessed with Ctrl + Shift + Y on all platforms.
You could then listen for the "toggle-feature" command with code like this:
browser.commands.onCommand.addListener((command) => {
if (command === "toggle-feature") {
console.log("Toggling the feature!");
}
});