The default bug view has changed. See this FAQ.

contextMenus.OnClickData should provide selector of the clicked element




WebExtensions: General
3 months ago
17 days ago


(Reporter: kernp25, Unassigned)


Firefox Tracking Flags

(Not tracked)


(Whiteboard: [design-decision-approved][contextMenus] triaged)



3 months ago
I'm developing a WebExtension called "Copy Link Title".

To get the text of the link (if any ofc), i need the element that the user rigth-clicked on (e.g. link)

Now i'm doing this: 
function menuClick(info, tab) {
  let url = new URL(info.linkUrl);
  browser.tabs.executeScript(, {
    code: `
      var link = document.querySelector('a[href="${url.pathname}"]');

This works ok (not always (must modifie this to get this working properlie)) but i think it would be helpful if the info would contain the css selector of the element.

It should have the same CSS Selectors when using the Inspector: Tools -> Web Developer -> Inspector.
Rigth click on element -> Copy -> CSS Selector

Comment 1

3 months ago
But, the code i posted will not work 100% because, if the page contains the same link twice (with different title) then it will not work. That's why i need the css selector from the element.

Comment 2

3 months ago
I can also use:
let clickedEl = null;
document.addEventListener("contextmenu", function(event) {
	clickedEl =;
}, true);

But i think this is ugly. (content-script running in every page, adding contextmenu event listener)


2 months ago
Whiteboard: [design-decision-needed] triaged


a month ago
Whiteboard: [design-decision-needed] triaged → [design-decision-needed][contextMenus] triaged

Comment 3

18 days ago
This has been added to the March 7 WebExtensions Triage mtg. agenda. 


Comment 4

17 days ago
We discussed about this during the last WebExtensions Triage meeting and we decided that we can approve this.
Ever confirmed: true
Priority: -- → P3
Whiteboard: [design-decision-needed][contextMenus] triaged → [design-decision-approved][contextMenus] triaged

Comment 5

17 days ago
As a side note (and as I said during the meeting):

it is possible that the generated CSS selector can be "not valid" anymore when the content scripts receive it (because the content of the page can have been changed in the meantime) and so we have to document this behavior in the MDN docs once this feature has been implemented, but it will be definitely cleaner then the alternative workarounds.
You need to log in before you can comment on or make changes to this bug.