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, Arrow keys (Up, Down, Left, Right) and the Media Keys 15 (MediaNextTrack, MediaPlayPause, MediaPrevTrack, MediaStop).</p> 16 17 <p>Note: All key combinations must include either Ctrl* or Alt. Combinations 18 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the 19 AltGr key. Shift can be used in addition to Alt or Ctrl, but is not required. 20 Modifiers (such as Ctrl) can not be used in combination with the Media Keys. 21 Tab key was removed from list of supported keys in Chrome version 33 and above 22 for accessibility reasons.<p> 23 24 <p>* Also note that on Mac 'Ctrl' is automatically converted to 'Command'. If 25 you want 'Ctrl' instead, please specify 'MacCtrl'.</p> 26 27 <p>Certain Chrome shortcuts (e.g. window management) always take priority over 28 Extension Command shortcuts and can not be overwritten.</p> 29 30 <pre data-filename="manifest.json"> 31 { 32 "name": "My extension", 33 ... 34 <b> "commands": { 35 "toggle-feature-foo": { 36 "suggested_key": { 37 "default": "Ctrl+Shift+Y", 38 "mac": "Command+Shift+Y" 39 }, 40 "description": "Toggle feature foo" 41 }, 42 "_execute_browser_action": { 43 "suggested_key": { 44 "windows": "Ctrl+Shift+Y", 45 "mac": "Command+Shift+Y", 46 "chromeos": "Ctrl+Shift+U", 47 "linux": "Ctrl+Shift+J" 48 } 49 }, 50 "_execute_page_action": { 51 "suggested_key": { 52 "default": "Ctrl+E", 53 "windows": "Alt+P", 54 "mac": "Option+P" 55 } 56 } 57 }</b>, 58 ... 59 }</pre> 60 61 <p>In your background page, you can bind a handler to each of the commands 62 defined in the manifest (except for '_execute_browser_action' and 63 '_execute_page_action') via onCommand.addListener. For example:</p> 64 65 <pre> 66 chrome.commands.onCommand.addListener(function(command) { 67 console.log('Command:', command); 68 }); 69 </pre> 70 71 <p>The '_execute_browser_action' and '_execute_page_action' commands are 72 reserved for the action of opening your extension's popups. They won't normally 73 generate events that you can handle. If you need to take action based on your 74 popup opening, consider listening for an 'onDomReady' event inside your popup's 75 code. 76 </p> 77