mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-17 23:08:33 +02:00
Update onCommand action for the commands example
This commit is contained in:
@@ -1,13 +1,6 @@
|
|||||||
# commands
|
# commands
|
||||||
|
|
||||||
This extension includes:
|
This extension shows how to use the `commands` manifest key to register keyboard shortcuts for your extension.
|
||||||
|
|
||||||
* a background script, "background.js"
|
It registers a shortcut (Ctrl+Shift+U) to send a command to the extension (Command+Shift+U on a Mac).
|
||||||
|
When the user enters the shortcut, the extension opens a new browser tab and loads https://developer.mozilla.org into it.
|
||||||
All it does is:
|
|
||||||
|
|
||||||
* register a shortcut (Ctrl+Shift+U) to send a command to the extension (Command+Shift+U on a Mac).",
|
|
||||||
|
|
||||||
It shows:
|
|
||||||
|
|
||||||
* how to use browser.commands to register keyboard shortcuts for your extension.
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
var gettingAllCommands = browser.commands.getAll();
|
var gettingAllCommands = browser.commands.getAll();
|
||||||
gettingAllCommands.then((commands) => {
|
gettingAllCommands.then((commands) => {
|
||||||
for (let command of commands) {
|
for (let command of commands) {
|
||||||
|
// Note that this logs to the Add-on Debugger's console: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Debugging
|
||||||
|
// not the regular Web console.
|
||||||
console.log(command);
|
console.log(command);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -24,5 +26,5 @@ gettingAllCommands.then((commands) => {
|
|||||||
* On Mac, this command will automatically be converted to "Command+Shift+U".
|
* On Mac, this command will automatically be converted to "Command+Shift+U".
|
||||||
*/
|
*/
|
||||||
browser.commands.onCommand.addListener((command) => {
|
browser.commands.onCommand.addListener((command) => {
|
||||||
console.log("onCommand event received for message: ", command);
|
browser.tabs.create({url: "https://developer.mozilla.org"});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user