1 <h2 id="manifest">Manifest</h2> 2 <p> 3 You must set manifest_version to (at least) 2 to use this API. 4 </p> 5 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 page.</p> 12 13 <p>Supported keys: A-Z, 0-9, Comma, Period, Home, End, PageUp, PageDown, Insert, 14 Delete, Tab and the arrow keys (Up, Down, Left, Right).</p> 15 16 <p>Note: All key combinations must include either Ctrl* or Alt. Combinations 17 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the 18 AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required.<p> 19 20 <p>* Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If 21 you want 'Ctrl' instead, please specify 'MacCtrl'.</p> 22 23 <p>Certain Chrome shortcuts (e.g. window management) always take priority over 24 Extension Command shortcuts and can not be overwritten.</p> 25 26 <pre>{ 27 "name": "My extension", 28 ... 29 <b> "commands": { 30 "toggle-feature-foo": { 31 "suggested_key": { 32 "default": "Ctrl+Shift+Y", 33 "mac": "Command+Shift+Y" 34 }, 35 "description": "Toggle feature foo" 36 }, 37 "_execute_browser_action": { 38 "suggested_key": { 39 "windows": "Ctrl+Shift+Y", 40 "mac": "Command+Shift+Y", 41 "chromeos": "Ctrl+Shift+U", 42 "linux": "Ctrl+Shift+J" 43 } 44 }, 45 "_execute_page_action": { 46 "suggested_key": { 47 "default": "Ctrl+E" 48 "windows": "Alt+P", 49 "mac": "Option+P", 50 } 51 } 52 }</b>, 53 ... 54 }</pre> 55 56 <p>In your background page, you can bind a handler to each of the commands 57 defined in the manifest (except for '_execute_browser_action' and 58 '_execute_page_action') via onCommand.addListener. For example:</p> 59 60 <pre> 61 chrome.commands.onCommand.addListener(function(command) { 62 console.log('Command:', command); 63 }); 64 </pre> 65 66 <p>The '_execute_browser_action' and '_execute_page_action' commands are 67 reserved for the action of opening your extension's popups. They won't normally 68 generate events that you can handle. If you need to take action based on your 69 popup opening, consider listening for an 'onDomReady' event inside your popup's 70 code. 71 </p> 72