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.

Syntax

js
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 listener argument is the listener to remove.

hasListener(listener)

Check whether listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

listener

The function called when a command's shortcut changes. The function is passed these arguments:

changeInfo

object. An object containing the name of the command, its new active shortcut, and its old shortcut.

name

string. Name of the command. This matches the name given to the command in its manifest.json entry.

newShortcut

string. The new active shortcut for this command, or blank if no shortcut is active.

oldShortcut

string. 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:

js
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);

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
onChanged
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 115 (Release date: 2023-07-04)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support