Custom context menu on a toolbar button?

I’m about to start porting an add-on I inherited, but I’m not sure how it’s going to be able to behave.

It used to provide a button that did something on primary [left] click, but also provided a drop-down menu (a side “v“, also left-click) which the browser managed.

It looks like all I have available now is a single left-click on a button, I can’t see any evidence of being able to add even context menu items to buttons (I was thinking of having the primary action on click and the secondary pop-up as a context menu).

Can I detect where on a button it was clicked? Or style it on hover?

Do we even have the ability to have varied with buttons? An ultimate fall-back might then be to supply two narrow buttons that can go next to each other, and have one for click and one for popup.

For ref., see page for the add-on and its screenshot: https://addons.mozilla.org/en-US/firefox/addon/neo-diggler/

You can create custom context menu items by giving them the “browser_action” context: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/menus/ContextType

If you don’t provide a popup to your button you can detect clicks, else you will have to handle actions when the popup is loaded.

There is a (so far not very successful) bug on providing menu buttons/combo buttons: https://bugzilla.mozilla.org/show_bug.cgi?id=1253419

(personally I’d rather not have them back, but we will see how things go, as I’m just a volunteer who thinks having different UI principles than the main application you’re running in may not be very intuitive to new users…)

OK, thanks; yes, had a bit of a play and that would cover my use-cases.

For anyone following this thread: I hadn’t seen an example of it, but you do get left-click events as you’d expect off the button, and custom context menu entries get added to the top of the stock context menu for browser buttons (“Pin to overflow”, etc.).

Unfortunately, I think one of the key features of this extension isn’t possible now :frowning: — I’ll ask about that separately.