Open Bug 1341804 Opened 7 years ago Updated 2 years ago

Support of CSS-Selectors in contexts of context-menus

Categories

(WebExtensions :: Frontend, enhancement, P5)

enhancement

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: hbeck1974, Unassigned)

References

Details

(Whiteboard: [triaged])

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:51.0) Gecko/20100101 Firefox/51.0
Build ID: 20170127092049

Steps to reproduce:

I tried to port an addon to Webextensions, that uses context-menus, that only appear in certain CSS-Selector contexts like div#1234.  


Actual results:

WebExtensions does not support this yet.
Component: WebExtensions: Frontend → WebExtensions: Untriaged
Priority: -- → P5
Whiteboard: [triaged]
Severity: normal → enhancement
Component: WebExtensions: Untriaged → WebExtensions: Frontend
As a possible reimplementation of support for this bug, but in a manner with broader utility, I'd like to see the old Add-ons SDK behavior of having a `context` event which was supplied the given node and whose return value could be used to indicate whether the item should be shown or not.

I'm looking to reimplement my "Open Wiki Edit Page" add-on which looks for "/wiki/" within the URL, and I'd like to avoid having my add-on clutter the context menu for any URLs except those matching the Mediawiki wiki pattern...

Thanks!
(In reply to Brett Zamir from comment #2)
> As a possible reimplementation of support for this bug, but in a manner with
> broader utility, I'd like to see the old Add-ons SDK behavior of having a
> `context` event which was supplied the given node and whose return value
> could be used to indicate whether the item should be shown or not.
> 
> I'm looking to reimplement my "Open Wiki Edit Page" add-on which looks for
> "/wiki/" within the URL, and I'd like to avoid having my add-on clutter the
> context menu for any URLs except those matching the Mediawiki wiki pattern...
> 
> Thanks!

Can't you use targetUrlPatterns [1]?

https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/menus/create#Parameters
Oops--thank you for pointing that out to me for my use case... I missed it because when I saw "src" mentioned first in the docs, I just dismissed it thinking that was about the document being part of an image source (I edited MDN to put the info on href first given the greater ubiquity of links). Good to know!
In considering my case further, it turns out I need something more sophisticated than match patterns (negative lookahead to exclude "Special:" in the URL) but `targetUrlPatterns` would meet my needs were bug 1385073 implemented (allowing for exclusion patterns).

It looks, however, like `onShown` (at https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/menus/onShown ) might be leveragable for the old SDK behavior I mentioned (i.e., one would destroy the menu item if the conditions on `info.linkUrl` were not adequate).

While this would work for my case, in order for `onShown` to meet the use case mentioned by the original filer, bug 1325814 exposing more of the old SDK's info (e.g., an element reference or at least a selector path) would be needed. Besides this use case, that bug has many positive applications, so I am quite eager for it to be implemented!
Product: Toolkit → WebExtensions
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.