| OLD | NEW |
| 1 <p> | 1 <p> |
| 2 The commands API allows you to add keyboard shortcuts that trigger actions in | 2 The commands API allows you to add keyboard shortcuts that trigger actions in |
| 3 your extension. An action can be opening the browser action or page action popup | 3 your extension. An action can be opening the browser action or page action popup |
| 4 or sending a command to the extension. | 4 or sending a command to the extension. |
| 5 </p> | 5 </p> |
| 6 | |
| 7 <h2 id="manifest">Manifest</h2> | 6 <h2 id="manifest">Manifest</h2> |
| 8 <p> | 7 <p> |
| 9 In addition to the "experimental" permission you must declare the "commands" | 8 In addition to the "experimental" permission you must declare the "commands" |
| 10 permission in your extension's manifest to use this API and set manifest_version | 9 permission in your extension's manifest to use this API and set manifest_version |
| 11 to (at least) 2. | 10 to (at least) 2. |
| 12 </p> | 11 </p> |
| 13 | |
| 14 <pre>{ | 12 <pre>{ |
| 15 "name": "My extension", | 13 "name": "My extension", |
| 16 ... | 14 ... |
| 17 <b> "permissions": [ | 15 <b> "permissions": [ |
| 18 "experimental", | 16 "experimental", |
| 19 "commands", | 17 "commands", |
| 20 ]</b>, | 18 ]</b>, |
| 21 ... | 19 ... |
| 22 }</pre> | 20 }</pre> |
| 23 | |
| 24 <h2 id="usage">Usage</h2> | 21 <h2 id="usage">Usage</h2> |
| 25 <p>The commands API allows you to define specific commands, and bind them to a | 22 <p>The commands API allows you to define specific commands, and bind them to a |
| 26 default key combination. Each command your extension accepts must be listed in | 23 default key combination. Each command your extension accepts must be listed in |
| 27 the manifest as an attribute of the 'commands' manifest key. Note: Combinations | 24 the manifest as an attribute of the 'commands' manifest key. Note: Combinations |
| 28 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the | 25 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the |
| 29 AltGr key.</p> | 26 AltGr key.</p> |
| 30 | |
| 31 <pre>{ | 27 <pre>{ |
| 32 "name": "My extension", | 28 "name": "My extension", |
| 33 ... | 29 ... |
| 34 <b> "commands": { | 30 <b> "commands": { |
| 35 "toggle-feature-foo": { | 31 "toggle-feature-foo": { |
| 36 "suggested_key": { | 32 "suggested_key": { |
| 37 "default": "Ctrl+Shift+Y", | 33 "default": "Ctrl+Shift+Y", |
| 38 "mac": "Command+Shift+Y" | 34 "mac": "Command+Shift+Y" |
| 39 }, | 35 }, |
| 40 "description": "Toggle feature foo" | 36 "description": "Toggle feature foo" |
| 41 }, | 37 }, |
| 42 "_execute_browser_action": { | 38 "_execute_browser_action": { |
| 43 "suggested_key": { | 39 "suggested_key": { |
| 44 "windows": "Ctrl+Shift+Y", | 40 "windows": "Ctrl+Shift+Y", |
| 45 "mac": "Command+Shift+Y", | 41 "mac": "Command+Shift+Y", |
| 46 "chromeos": "Ctrl+Shift+U", | 42 "chromeos": "Ctrl+Shift+U", |
| 47 "linux": "Ctrl+Shift+J" | 43 "linux": "Ctrl+Shift+J" |
| 48 } | 44 } |
| 49 }, | 45 }, |
| 50 "_execute_page_action": { | 46 "_execute_page_action": { |
| 51 "suggested_key": { | 47 "suggested_key": { |
| 52 "default": "Ctrl+E" | 48 "default": "Ctrl+E" |
| 53 "windows": "Alt+P", | 49 "windows": "Alt+P", |
| 54 "mac": "Option+P", | 50 "mac": "Option+P", |
| 55 } | 51 } |
| 56 } | 52 } |
| 57 }</b>, | 53 }</b>, |
| 58 ... | 54 ... |
| 59 }</pre> | 55 }</pre> |
| 60 | |
| 61 <p>In your background page, you can bind a handler to each of the commands | 56 <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 | 57 defined in the manifest (except for '_execute_browser_action' and |
| 63 '_execute_page_action') via onCommand.addListener. For example:</p> | 58 '_execute_page_action') via onCommand.addListener. For example:</p> |
| 64 | |
| 65 <pre> | 59 <pre> |
| 66 chrome.experimental.commands.onCommand.addListener(function(command) { | 60 chrome.experimental.commands.onCommand.addListener(function(command) { |
| 67 console.log('Command:', command); | 61 console.log('Command:', command); |
| 68 }); | 62 }); |
| 69 </pre> | 63 </pre> |
| 70 | |
| 71 <p>The '_execute_browser_action' and '_execute_page_action' commands are | 64 <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 | 65 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 | 66 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 | 67 popup opening, consider listening for an 'onDomReady' event inside your popup's |
| 75 code. | 68 code. |
| 76 </p> | 69 </p> |
| OLD | NEW |