-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent support for [context]menus.getTargetElement() #716
Comments
Last discussion related to |
@fregante Thanks! I hadn't seen that one. I'm actually not sure how to word that in the post, so I'll say here (just generally speaking) - Given the examples listed, and the desire for in-page actions based on a menu item click to be (I'd think) common enough, I'd say its addition to the ContextMenu APIs would be largely beneficial. I definitely can't comment on other Menus v ContextMenus differences though! |
Note: I designed and implemented
Originally I wanted to put it behind the "menus.getTargetElement" permission to minimize exposure in content scripts, because the "contextMenus" permission is very commonly requested. Ultimately the permission was dropped because it was not really necessary. |
I see, that certainly does make sense. I apologise, I hadn't considered that aspect of it. Thanks for explaining |
Oh, it just occured to me that perhaps coordinates could work? Then a user can pass those to the page, and (in the example cases) pass to document.elementFromPoint and get the element that way. That can be done via dynamic injection. Perhaps it could enable some new functionalities as well, for devs wanting to chart/mark points in the viewport. Though I realise that's a bit of a stretch, and: it's yet another property, and can definitely be considered niche. But still, thoughts on that? |
I miss
The question was raised earlier on the chromium-extension mailing list: How to get the field where a keyboard shortcut or context menu was called from? Mon, 12 Feb 2024 04:53:35 -0800 (PST) (handling subframes using It should work for purely keyboard navigation aka caret browsing ( Coordinates of click position are unreliable. During time interval between opening menu and selection of an item more images may be loaded causing reflow and shifting of target element to another position. (Side note: even user gesture timeout may be expired in DOM context in the case of delay after opening a menu.) Since To avoid issues with |
I'm supportive of adding |
Sorry for insistence, what is you opinion concerning either expanding the |
@maxnikulin Good point re: coordinates, agree that it certainly falls short in some instances (which isn't optimal!) As an end-user/dev I'd be happy to see any implementation that addresses the target retrieval, so for me personally I'll put my 👍 on any suggestion/issue |
@oliverdunk
follow-up: chrome
|
There are cases where an extension might need the element a contextMenu was opened (and actioned) on.
A classic example case might be to block/remove said element
Another, might be "Copy this element".
For this, Firefox has implemented getTargetElement(), paired with targetElementId.
For browsers without this, the best current solution (from what I've found) is to inject a content script with a contextMenu listener and get the target, i.e.
The inherent problem with this is the necessity for global content script injection, preventing dynamic injection based on user action.
Another solution is injection onClicked, retrieving the activeElemet, but for the above cases, this wouldn't suffice (with non-focusable elements and such).
As for implementation, I believe Firefox's approach is great for this.
Note - I'm not sure whether this falls under inconsistency or Feature request, though I believe it's implementation is warranted, so I've gone with inconsistency.
The text was updated successfully, but these errors were encountered: