How to open toolbar popup programmatically

Hi, I’ve a working toolbar popup like described here:
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/user_interface/Popups

I’d like to open it with a keyboard shortcut.

The problem: I don’t know how to open this popup programmatically.
I searched the docs but haven’t found anything so far.

Is there any way to achieve this?

If you want to open it by keyboard shortcut, the easiest way that involves 0 code is to declare a _execute_browser_action command:

There is an API method to open the popup from user interaction events, too:

(which seems to be missing from the docs index sidebar, btw @caitmuenster)

1 Like

So solution one
manifest.json

{
    ...
    "commands": {
        "_execute_browser_action": {
            "suggested_key": {
                "default": "Ctrl+Shift+F"
            },
            "description": "Toggle View"
        }
    },
   ...
}

Or solution two
manifest.json

{
    ...
    "commands": {
        "toggle-view": {
            "suggested_key": {
                "default": "Ctrl+Shift+F"
            },
            "description": "Toggle View"
        }
    },
   ...
}

background.js

browser.commands.onCommand.addListener((command) => {
    if (command === 'toggle-view') {
        browser.browserAction.openPopup();
    }
});