Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / common / extensions / docs / templates / intros / commands.html
blob8aebec77f678d7634561ef47ef4c4f716ccf5e4f
1 <h2 id="manifest">Manifest</h2>
2 <p>
3 You must have a <code>"manifest_version"</code> of at least <code>2</code> to use this API.
4 </p>
6 <h2 id="usage">Usage</h2>
7 <p>The commands API allows you to define specific commands, and bind them to a
8 default key combination. Each command your extension accepts must be listed in
9 the manifest as an attribute of the 'commands' manifest key. An extension can
10 have many commands but only 4 suggested keys can be specified. The user can
11 manually add more shortcuts from the chrome://extensions/configureCommands
12 dialog.</p>
14 <p>Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown,
15 Space, Insert, Delete, Arrow keys (Up, Down, Left, Right) and the Media Keys
16 (MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).</p>
18 <p>Note: All key combinations must include either Ctrl* or Alt. Combinations
19 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the
20 AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required.
21 Modifiers (such as Ctrl) can not be used in combination with the Media Keys.
22 Tab key was removed from list of supported keys in Chrome version 33 and above
23 for accessibility reasons.<p>
25 <p>* Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If
26 you want 'Ctrl' instead, please specify 'MacCtrl'.</p>
28 <p>* Additionally, on Chrome OS, you can specify 'Search' as a modifier.</p>
30 <p>Certain Chrome shortcuts (e.g. window management) always take priority over
31 Extension Command shortcuts and can not be overwritten.</p>
33 <pre data-filename="manifest.json">
35 "name": "My extension",
36 ...
37 <b> "commands": {
38 "toggle-feature-foo": {
39 "suggested_key": {
40 "default": "Ctrl+Shift+Y",
41 "mac": "Command+Shift+Y"
43 "description": "Toggle feature foo"
45 "_execute_browser_action": {
46 "suggested_key": {
47 "windows": "Ctrl+Shift+Y",
48 "mac": "Command+Shift+Y",
49 "chromeos": "Ctrl+Shift+U",
50 "linux": "Ctrl+Shift+J"
53 "_execute_page_action": {
54 "suggested_key": {
55 "default": "Ctrl+Shift+E",
56 "windows": "Alt+Shift+P",
57 "mac": "Alt+Shift+P"
60 }</b>,
61 ...
62 }</pre>
64 <p>In your background page, you can bind a handler to each of the commands
65 defined in the manifest (except for '_execute_browser_action' and
66 '_execute_page_action') via onCommand.addListener. For example:</p>
68 <pre>
69 chrome.commands.onCommand.addListener(function(command) {
70 console.log('Command:', command);
71 });
72 </pre>
74 <p>The '_execute_browser_action' and '_execute_page_action' commands are
75 reserved for the action of opening your extension's popups. They won't normally
76 generate events that you can handle. If you need to take action based on your
77 popup opening, consider listening for an 'onDomReady' event inside your popup's
78 code.
79 </p>
81 <h2 id="usage">Scope</h2>
82 <p>By default, Commands are scoped to the Chrome browser, which means that while
83 the browser does not have focus, the shortcut will be inactive. On desktop
84 Chrome, Commands can instead have global scope, as of version 35, and will then
85 also work while Chrome does *not* have focus. NOTE: The exception here is
86 Chrome OS, where global commands are not allowed at the moment.</p>
88 <p>The user is free to designate any shortcut as global using the UI in
89 chrome://extensions \ Keyboard Shortcuts, but the extension developer is limited
90 to specifying only Ctrl+Shift+[0..9] as global shortcuts. This is to minimize
91 the risk of overriding shortcuts in other applications since if, for example,
92 Alt+P were to be allowed as global, the printing shortcut might not work in
93 other applications.</p>
95 <p>Example:</p>
97 <pre data-filename="manifest.json">
99 "name": "My extension",
101 "commands": {
102 "toggle-feature-foo": {
103 "suggested_key": {
104 "default": "Ctrl+Shift+5"
106 "description": "Toggle feature foo",
107 <b>"global": true</b>
111 }</pre>