I am creating a context menu item in Google chrome like so:
chrome.contextMenus.create({
"title":"My Context Menu Item",
"contexts":["editable"],
"onclick": onClick
});
The onClick callback receives two arguments: an OnClickInfo object and a tab object. Neither object appears to contain a reference to the DOM element that was right-clicked when invoking the context menu. I have console.logged both of these objects but don't see any reference to the targeted element anywhere.
The desired outcome:
onClick callback, have my extension search for a parent 'form' element relative to the targeted right-click elementAs it stands right now, it doesn't look like Chrome offers any reference to the targeted element. Has anyone found a way around this limitation?
You must inject a content script in each page and listen for mousedown event and log the last clicked element. Then, when a context menu callback is called you must sendRequest to the tab to get the info about that last clicked element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With