Closed Bug 1547534 Opened 6 years ago Closed 6 years ago

WebExtensions: add a «blank» context for menus.overrideContext()

Categories

(WebExtensions :: General, enhancement)

67 Branch
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED WORKSFORME

People

(Reporter: aria, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0

Steps to reproduce:

I wanted to display a context menu on right-click of a «New Tab» button to open the new tab in a container.

Actual results:

I had to use the «tab» context and provide a tabId:

browser.menus.overrideContext({
context: "tab",
tabId: tabId
});

But using this trick, addons could add an entry that would effectively use this tabId and would make no sense in the context of a «New Tab» context menu.

Expected results:

I want to be able to trigger the context menu without the possibility for an addon to add an unrelated entry for what I’m trying to do.

For example:

browser.menus.overrideContext({
context: "blank"
});

or more simply:

browser.menus.overrideContext();

Product: Firefox → WebExtensions

Hi ariasuni,

I will set this up as an enhancement and move it over to the component. Not sure if there are any similar improvements suggested but developers will take a look over it.

Thanks for the report!

Status: UNCONFIRMED → NEW
Type: defect → enhancement
Component: Untriaged → General
Ever confirmed: true
Flags: needinfo?(mconca)
Flags: needinfo?(mconca) → needinfo?(rob)

If you don't want menu items from other add-ons, don't set the context property. This property's main purpose is to allow other extensions to add context-specific menu items.

The documentation states that all properties are optional, so you can just call browser.menus.overrideContext({}) (with {}).
Without context, the default context is used.
Without showDefaults:true, the defaults (from the browser and other extensions) are not included - so you only have your extension's own menu items in the menu.

Status: NEW → RESOLVED
Closed: 6 years ago
Flags: needinfo?(rob)
Resolution: --- → WORKSFORME

OK, I got what was wrong with my code: I had set menu items to context tab so I needed to use context: "tab" to make them appear. Removing the context from both my menu items and browser.menus.overrideContext works perfectly.

I think I’ll try to improve the documentation so that other people don’t fall into the same trap.

You need to log in before you can comment on or make changes to this bug.