blob: f98ce3ec9d54789ccfa8be6e45751a96def4bd1f [file] [log] [blame]
<h2 id="manifest">Manifest</h2>
<p>
You must set manifest_version to (at least) 2 to use this API.
</p>
<h2 id="usage">Usage</h2>
<p>The commands API allows you to define specific commands, and bind them to a
default key combination. Each command your extension accepts must be listed in
the manifest as an attribute of the 'commands' manifest key. An extension can
have many commands but only 4 suggested keys can be specified. The user can
manually add more shortcuts from the chrome://extensions page.</p>
<p>Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Insert,
Delete, Arrow keys (Up, Down, Left, Right) and the Media Keys
(MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).</p>
<p>Note: All key combinations must include either Ctrl* or Alt. Combinations
that involve Ctrl+Alt are not permitted in order to avoid conflicts with the
AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required.
Modifiers (such as Ctrl) can not be used in combination with the Media Keys.
Tab key was removed from list of supported keys in Chrome version 33 and above
for accessibility reasons.<p>
<p>* Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If
you want 'Ctrl' instead, please specify 'MacCtrl'.</p>
<p>Certain Chrome shortcuts (e.g. window management) always take priority over
Extension Command shortcuts and can not be overwritten.</p>
<pre data-filename="manifest.json">
{
"name": "My extension",
...
<b> "commands": {
"toggle-feature-foo": {
"suggested_key": {
"default": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y"
},
"description": "Toggle feature foo"
},
"_execute_browser_action": {
"suggested_key": {
"windows": "Ctrl+Shift+Y",
"mac": "Command+Shift+Y",
"chromeos": "Ctrl+Shift+U",
"linux": "Ctrl+Shift+J"
}
},
"_execute_page_action": {
"suggested_key": {
"default": "Ctrl+E",
"windows": "Alt+P",
"mac": "Option+P"
}
}
}</b>,
...
}</pre>
<p>In your background page, you can bind a handler to each of the commands
defined in the manifest (except for '_execute_browser_action' and
'_execute_page_action') via onCommand.addListener. For example:</p>
<pre>
chrome.commands.onCommand.addListener(function(command) {
console.log('Command:', command);
});
</pre>
<p>The '_execute_browser_action' and '_execute_page_action' commands are
reserved for the action of opening your extension's popups. They won't normally
generate events that you can handle. If you need to take action based on your
popup opening, consider listening for an 'onDomReady' event inside your popup's
code.
</p>