| 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 | 6 |
| 7 <h2 id="manifest">Manifest</h2> | 7 <h2 id="manifest">Manifest</h2> |
| 8 <p> | 8 <p> |
| 9 In addition to the "experimental" permission you must declare the "commands" | 9 You must declare the "commands" permission in your extension's manifest to use |
| 10 permission in your extension's manifest to use this API and set manifest_version | 10 this API and set manifest_version to (at least) 2. |
| 11 to (at least) 2. | |
| 12 </p> | 11 </p> |
| 13 | 12 |
| 14 <pre>{ | 13 <pre>{ |
| 15 "name": "My extension", | 14 "name": "My extension", |
| 16 ... | 15 ... |
| 17 <b> "permissions": [ | 16 <b> "permissions": [ |
| 18 "experimental", | |
| 19 "commands", | 17 "commands", |
| 20 ]</b>, | 18 ]</b>, |
| 21 ... | 19 ... |
| 22 }</pre> | 20 }</pre> |
| 23 | 21 |
| 24 <h2 id="usage">Usage</h2> | 22 <h2 id="usage">Usage</h2> |
| 25 <p>The commands API allows you to define specific commands, and bind them to a | 23 <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 | 24 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 | 25 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 | 26 that involve Ctrl+Alt are not permitted in order to avoid conflicts with the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 56 } | 54 } |
| 57 }</b>, | 55 }</b>, |
| 58 ... | 56 ... |
| 59 }</pre> | 57 }</pre> |
| 60 | 58 |
| 61 <p>In your background page, you can bind a handler to each of the commands | 59 <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 | 60 defined in the manifest (except for '_execute_browser_action' and |
| 63 '_execute_page_action') via onCommand.addListener. For example:</p> | 61 '_execute_page_action') via onCommand.addListener. For example:</p> |
| 64 | 62 |
| 65 <pre> | 63 <pre> |
| 66 chrome.experimental.commands.onCommand.addListener(function(command) { | 64 chrome.commands.onCommand.addListener(function(command) { |
| 67 console.log('Command:', command); | 65 console.log('Command:', command); |
| 68 }); | 66 }); |
| 69 </pre> | 67 </pre> |
| 70 | 68 |
| 71 <p>The '_execute_browser_action' and '_execute_page_action' commands are | 69 <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 | 70 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 | 71 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 | 72 popup opening, consider listening for an 'onDomReady' event inside your popup's |
| 75 code. | 73 code. |
| 76 </p> | 74 </p> |
| OLD | NEW |