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