onChanged
Fired when the keyboard shortcut for a command is changed.
The listener is passed an object containing the name of the command, its new active shortcut, and its old shortcut.
In this article
Syntax
browser.commands.onChanged.addListener(listener)browser.commands.onChanged.removeListener(listener)browser.commands.onChanged.hasListener(listener)Events have three functions:
addListener(listener)Adds a listener to this event.
removeListener(listener)Stop listening to this event. The
listenerargument is the listener to remove.hasListener(listener)Check whether
listeneris registered for this event. Returnstrueif it is listening,falseotherwise.
addListener syntax
>Parameters
listenerThe function called when a command's shortcut changes. The function is passed these arguments:
changeInfoobject. An object containing the name of the command, its new active shortcut, and its old shortcut.namestring. Name of the command. This matches the name given to the command in itsmanifest.json entry.newShortcutstring. The new active shortcut for this command, or blank if no shortcut is active.oldShortcutstring. The shortcut that was active for this command, or blank if no shortcut was active.
Examples
You could log changes to command shortcuts like this:
function handleChanged(changeInfo) { console.log(`Shortcut for: ${changeInfo.name} changed`); console.log(`From: ${changeInfo.oldShortcut}`); console.log(`To: ${changeInfo.newShortcut}`);}browser.commands.onChanged.addListener(handleChanged);