0

I am trying to make an chrome extension that removes element right clicked on using contextMenu, including elements nested within iframes.

chrome.contextMenus.create({
  title: 'test',
  contexts: ['all'],
  onclick: function(info, tab){
    console.log(info)
    // console.log(tab)
  }

}, function(){})

However, the only data I am getting back from my info object is the frameID, and not the element inside of the frame initially clicked on. How would you return the element clicked on from the contextMenu, regardless if it is nested in a frame?

moishinetzer
  • 113
  • 1
  • 1
  • 9
  • This API can't do this so in addition to API you'll have to use a content script with a `contextmenu` event listener. – wOxxOm Jan 20 '21 at 17:29
  • If I were to go about that, how do you select elements inside iframes in general? The mousedown event doesnt capture clicks @wOxxOm – moishinetzer Jan 20 '21 at 17:30
  • Not mousedown, but `contextmenu`. – wOxxOm Jan 20 '21 at 17:30
  • Can this post please be reopened? This is not a duplicate of the post listed as it is asking about elements unaccessable to it, i.e. a frame. This question is explicitely in the context of a frame and not a generic element – moishinetzer Jan 20 '21 at 17:48
  • An iframe is a standard page so the same approach will work without any change. The only addition you may need is `"all_frames": true` and maybe `"match_about_blank": true` in your declaration of the content script in manifest.json. – wOxxOm Jan 20 '21 at 17:52
  • I've updated that answer to support frames. – wOxxOm Jan 20 '21 at 17:57

0 Answers0