I am trying to add some keyboard shortcuts to my Chrome extension, specifically to allow the user to use hotkeys to open up a browser action/popup. I\'ve read the d
As you can see in the source code here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package:chromium&rcl=1409677023
The key binding update is only run when OnExtensionWillBeInstalled callback is triggered.
So you need to uninstall and reinstall your local extension to see the default keyboard command appear in : chrome://extensions/configureCommands
I was struggling with the same issue of the "_execute_browser_action" keyboard shortcut not being set automatically despite not conflicting with any existing shortcuts.
It turns out my problem was caused by the following:
...
"commands" : {
"_execute_browser_action": {
"suggested_key": {
"mac": "Alt+J",
"linux": "Ctrl+Shift+J"
},
"global": true <-- this shouldn't be here
}
...
Removing the "global": true resolved my issue. Hope this helps.
If you are testing your shortcut with console.log, it will not show up. Perhaps test it with chrome.tabs.create({url: "http://www.google.com/"});
This will require permissions to "tabs".
As per documentation:
The user is free to designate any shortcut as global using the UI in chrome://extensions \ Keyboard Shortcuts, but the extension developer is limited to specifying only Ctrl+Shift+[0..9] as global shortcuts. This is to minimize the risk of overriding shortcuts in other applications since if, for example, Alt+P were to be allowed as global, the printing shortcut might not work in other applications.
Somehow the keyboard shortcuts started working after I set the shortcuts to contain just one of Ctrl / Cmd / Alt / Shift. So, Alt+S worked but Alt+Shift+S did not work.
Adding to all of the correct answers above: After removing and adding the extension in the extensions page, the shortcut still didn't apply to the current window i was working in. It only worked once i opened a new chrome window.