I'm trying to program an Edge extension, and I would like the extension to open when I press a keyboard shortcut (for now, I want to use Ctrl-B). I found a way to assign a keyboard shortcut after I install the extension, by going to edge://extensions/shortcuts and then using the Microsoft GUI to assign the keyboard shortcut. But, I want to do this via code. I've tried the following snippets in manifest.json and popup.js, but they don't work. Thanks in advance for your help.
.....
"commands": {
"openExtension": {
"suggested_key": {
"default": "Ctrl+B"
},
"description": "My description"
}
}
.....
....
chrome.commands.onCommand.addListener(function(command) {
if (command === 'openExtension') {
chrome.runtime.sendMessage({action: 'openExtension'});
}
});
....
It seems that we only need to use
_execute_actionto define the shortcut to open the extension. For example, you can add below code in manifest.json:Then you'll find it works and automatically shows in edge://extensions/shortcuts.
Please note that not all keyboards combinations will work, I suggest you use
Ctrl+Shift+[0..9]. You can also refer to this doc: