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