I want to open an extension on Firefox using a hotkeys. But how can I do that?
Asked
Active
Viewed 181 times
-2
-
By "open an extension" do you mean "open the extension's `browser_action` popup"? Or, do you mean: register a shortcut key which my extension will be informed of when it's pressed? Please [edit] your question to clarify. Given your wording, I'm assuming the former (popup). – Makyen Oct 09 '17 at 22:47
1 Answers
0
You can use the commands API
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/commands https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands
like this in manifest.json
"commands": {
"my-shortcut-was-hit": {
"suggested_key": {
"default": "Ctrl+Shift+Y"
},
"description": "Send a 'my-shortcut-was-hit' event to the background script"
}
}
and in your background script:
browser.commands.onCommand.addListener(function(command) {
if (command == "my-shortcut-was-hit") {
console.log("my shortcut was hit!");
}
});
See also https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/commands/onCommand

Smile4ever
- 3,491
- 2
- 26
- 34
-
-
I thought you wanted to achieve doing some action when a shortcut is pressed. That is what the code above does - it's a Firefox extension in its own, that consists of a manifest.json file (partly above) - see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands - and a background.js file, see https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/background – Smile4ever Oct 10 '17 at 04:58