Interact with DOM node via a contextmenu entry

Hi,

is it possible for a Webextension to interact with a DOM node via a contextmenu entry?

The API looks pretty limited to me: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData

Well, following the click you could inject a content script.

The major problem I see is that you obviously don’t get a reference to the target element, but you don’t even get the coordinates and frameId of the clicked element …

WebExtensions unfortunately doesn’t implement anything equivalent to Add-on SDK’s SelectorContext. I was able to hack something equivalent using HTML5’s <menu type="context"> feature (which works on Firefox but not on Chromium). My implementation of it starts here. Admittedly it’s not very readable. Basically it’s a text highlighter add-on. The hiliteNode function wraps each marked text node in a <span class="prostetnic" contextmenu="prostetnic-###"> element. It then creates a context menu for each such span. This HTML5 context menu appears separately from the WebExtensions context menu, which is confusing. It’s the best I could do, that I’ve figured out so far, anyway. Yeah, I miss SDK.

I opened https://bugzilla.mozilla.org/show_bug.cgi?id=1357651

I have also tried find a workaround with HTML5 context menus. But it looks like this works not on iframes. I have placed the menu in the tree above the Iframe and below, but i get never the menu items visible by click on iframes.

Did you set "all_frames": true in manifest.json?

"content_scripts": [
  {
    "all_frames": true,
    "js": [
      ...
    ]
  }
]

Is already set. But you need also no addon to test this. Some pice of code on jsfiddle give the same result. As soon you click on a iframe the HTML5 contextmenu is not showed.

I get the menu only if i place it into the iframe. But the content will be loaded later so i need to catch if the iframe is loaded, insert the menu and on click my event must bubble to the parent of the iframe (if bubble up works here).