Back to Content

getAll()

files/en-us/mozilla/add-ons/webextensions/api/commands/getall/index.md

latest1.3 KB
Original Source

Gets all commands for the extension that you have registered using the commands manifest.json key.

The commands are returned as an array of {{WebExtAPIRef('commands.Command')}} objects. Alternately, if you are using the promise-based version of the API, browser.commands.getAll(), the commands are passed into the onFulfilled argument to Promise.then().

Syntax

js-nolint
let getCommands = browser.commands.getAll();

Parameters

None.

Return value

A Promise that will be fulfilled with an array of {{WebExtAPIRef('commands.Command')}} objects, one for each command registered for the extension. If no commands were registered, the array will be empty.

Examples

js
function logCommands(commands) {
  commands.forEach((command) => {
    console.log(command);
  });
}

let getCommands = browser.commands.getAll();
getCommands.then(logCommands);

{{WebExtExamples}}

Browser compatibility

{{Compat}}

[!NOTE] This API is based on Chromium's chrome.commands API.