commands

Type Object
Mandatory No
Manifest version 2 or higher
Example
json
"commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y",
      "linux": "Ctrl+Shift+U"
    },
    "description": "Send a 'toggle-feature' event"
  }
}

Use the commands key to define one or more keyboard shortcuts for your extension.

Each keyboard shortcut is defined with a name, a combination of keys, and a description. After defining commands in your extension's manifest.json, you can listen for their associated key combinations with the commands API.

Syntax

The commands key is an object, and each shortcut is a property of it. The property's name is the name of the shortcut.

Each shortcut's value is an object with up to 2 properties:

  1. suggested_key Optional: the combination of keys that activate the shortcut.
  2. description Optional: a string that describes the shortcut, i.e., what it does.

The suggested_key property is an object with any or none of these properties (all strings):

  • "default"
  • "mac"
  • "linux"
  • "windows"
  • "chromeos"
  • "android"
  • "ios"

The value of each property is the keyboard shortcut for the command on that platform, as a string containing keys separated by +. The value for "default" is used on all platforms that aren't explicitly listed. If "default" isn't included, the command doesn't have a keyboard shortcut on any platform not included, unless a shortcut is configured by the user or through the commands.update API.

For example:

json
"commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Alt+Shift+U",
      "linux": "Ctrl+Shift+U"
    },
    "description": "Send a 'toggle-feature' event to the extension"
  },
  "do-another-thing": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  },
  "do-something-else": {
    "suggested_key": {
      "linux": "Ctrl+Shift+P"
    }
  },
  "do-nothing-yet": {}
}

This JSON defines these shortcuts:

  1. "toggle-feature", accessed with Ctrl + Shift + U on Linux, and Alt + Shift + U on all other platforms.
  2. "do-another-thing", accessed with Ctrl + Shift + Y on all platforms.
  3. "do-something-else", accessed with Ctrl + Shift + P on Linux only, and no default shortcut on other platforms.
  4. "do-nothing-yet", sets no keyboard shortcut but enables a shortcut to be set by the user or with the commands.update API.

You can listen for the commands with code like this, in this case for the "toggle-feature" command:

js
browser.commands.onCommand.addListener((command) => {
  if (command === "toggle-feature") {
    console.log("Toggling the feature!");
  }
});

Special shortcuts

There are 4 special shortcuts with default actions for which the commands.onCommand event doesn't fire:

The availability of these special shortcuts varies between manifest versions and browsers, like this:

Manifest V2 Manifest V3
_execute_browser_action Yes No
_execute_action No Yes
_execute_page_action Yes Firefox only
_execute_sidebar_action Firefox only Firefox only

Note: If the user changes the shortcut of the _execute_browser_action command, it is automatically carried over to the _execute_action command when the extension migrates from Manifest V2 to V3. This was implemented in Chrome 111 and Firefox 127.

For example, this JSON defines a key combination that clicks the extension's browser action:

json
"commands": {
  "_execute_browser_action": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  }
}

Shortcut values

There are two valid formats for shortcut keys: as a key combination or as a media key.

Key combinations

Note: On Macs, "Ctrl" is interpreted as "Command", so if you actually need "Ctrl", specify "MacCtrl".

Key combinations must consist of 2 or 3 keys:

  1. modifier (mandatory, except for function keys). This can be any of: "Ctrl", "Alt", "Command", or "MacCtrl".
  2. secondary modifier (optional). If supplied, this must be either "Shift" or (for Firefox ≥ 63) any one of "Ctrl", "Alt", "Command", or "MacCtrl". Must not be the modifier already used as the main modifier.
  3. key (mandatory). This can be any one of:
    • the letters A – Z
    • the numbers 0 – 9
    • the function keys F1 – F12

      Note: From Firefox 135, users can assign the F13 to F19 keys to an extension using Manage Extension Shortcuts. Your extension can't assign these keys from the manifest file. However, it can assign them using commands.update.

    • Comma, Period, Home, End, PageUp, PageDown, Space, Insert, Delete, Up, Down, Left, Right

The key is then given as a string containing the set of key values, in the order listed above, separated by +. For example, "Ctrl+Shift+Z".

If a key combination is already used by the browser (like "Ctrl+P") or by an existing add-on, then you can't override it. You can define it, but your event handler will not be called when the user presses the key combination.

Media keys

Alternatively, the shortcut can be specified as one of these media keys:

  • "MediaNextTrack"
  • "MediaPlayPause"
  • "MediaPrevTrack"
  • "MediaStop"

Updating shortcuts

In Firefox, your extension can update shortcut key settings using commands.update(). Users can update shortcuts using the Manage Extension Shortcuts option at about:addons, as shown in this video. Your extension can open this option using commands.openShortcutSettings().

In Chrome, extensions can't programmatically update shortcut keys. Users can change shortcuts at chrome://extensions/shortcuts, which can be opened using tabs.create().

Safari doesn't support programmatic modification of extension shortcut keys. From Safari 26, users can change an extension's shortcuts in Safari's extensions settings.

Example

Define a keyboard shortcut using only the default key combination:

json
"commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    },
    "description": "Send a 'toggle-feature' event"
  }
}

Define two keyboard shortcuts, one with a platform-specific key combination:

json
"commands": {
  "toggle-feature": {
    "suggested_key": {
      "default": "Alt+Shift+U",
      "linux": "Ctrl+Shift+U"
    },
    "description": "Send a 'toggle-feature' event"
  },
  "do-another-thing": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y"
    }
  }
}

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
commands
Chrome – Full support
Chrome 25 (Release date: 2013-02-21)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Partial support
Safari 14 – 18.6 (Release date: 2020-09-16)
footnote Partial support
footnote Changing the keyboard shortcut for a command is not supported.
Safari – Full support
Safari 26 (Release date: 2025-09-15)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote
footnote Changing the keyboard shortcut for a command is not supported.
F1-F12
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 53 (Release date: 2017-04-19)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
MediaNextTrack
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote
footnote macOS support requires the global command feature which isn't supported yet. See Bug 1251795.
footnote Can only register one Media* command at a time. See Bug 1251795.
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full 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
MediaPlayPause
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote
footnote macOS support requires the global command feature which isn't supported yet. See Bug 1251795.
footnote Can only register one Media* command at a time. See Bug 1251795.
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full 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
MediaPrevTrack
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote
footnote macOS support requires the global command feature which isn't supported yet. See Bug 1251795.
footnote Can only register one Media* command at a time. See Bug 1251795.
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full 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
MediaStop
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 57 (Release date: 2017-11-14)
footnote
footnote macOS support requires the global command feature which isn't supported yet. See Bug 1251795.
footnote Can only register one Media* command at a time. See Bug 1251795.
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full 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
Secondary modifier other than Shift
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 63 (Release date: 2018-10-23)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote Full support
_execute_action
Chrome – Full support
Chrome 88 (Release date: 2021-01-19)
footnote
footnote Available for use in Manifest V3 or later.
Edge – Full support
Edge 88 (Release date: 2021-01-21)
footnote
footnote Available for use in Manifest V3 or later.
Firefox – Full support
Firefox 91 (Release date: 2021-08-10)
footnote
footnote Available for use in Manifest V3 or later.
Opera – Full support
Opera 74 (Release date: 2021-02-02)
footnote
footnote Available for use in Manifest V3 or later.
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote
footnote Available for use in Manifest V3 or later.
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote
footnote Available for use in Manifest V3 or later.
_execute_browser_action
Chrome – Full support
Chrome 25 (Release date: 2013-02-21)
footnote
footnote Available for use in Manifest V2 only.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote Available for use in Manifest V2 only.
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote
footnote Available for use in Manifest V2 only.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote Available for use in Manifest V2 only.
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote
footnote Available for use in Manifest V2 only.
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote
footnote Available for use in Manifest V2 only.
_execute_page_action
Chrome – Full support
Chrome 25 (Release date: 2013-02-21)
footnote
footnote Available for use in Manifest V2 only.
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote
footnote Available for use in Manifest V2 only.
Firefox – Full support
Firefox 48 (Release date: 2016-08-02)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote Available for use in Manifest V2 only.
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote
footnote Available for use in Manifest V2 only.
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – Full support
Safari on iOS 15 (Release date: 2021-09-20)
footnote
footnote Available for use in Manifest V2 only.
_execute_sidebar_action
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 54 (Release date: 2017-06-13)
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
global
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full 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
Partial support
Partial support
No support
No support
See implementation notes.
Has more compatibility info.