Apply activeTab to child frame when contextMenus is triggered in a child frame
Categories
(WebExtensions :: General, enhancement, P3)
Tracking
(Not tracked)
People
(Reporter: robwu, Unassigned)
References
Details
(Whiteboard: [addons-jira])
In MV2, the activeTab feature grants host permissions to a document, and all initially existing frames (this extra condition was introduced in bug 1396399).
In MV3, the feature has been restricted further, by only extending the activeTab permission to documents that are same-origin to the top-level document (in bug 1774642).
The idea behind that design is that activeTab is typically granted for the "current tab", i.e. the active tab of the window that the user is interacting with:
- action/browserAction/pageAction button clicked: current tab
- keyboard shortcut triggered: current tab
- contextMenus, menu item clicked:
- action/browserAction/pageAction button: current tab
- tools menu: current tab (for the lack of anything better)
- on the tab browser UI element: that tab (NOT "current tab")
- in content area: tab where context menu is opened, usually "current tab"
Of that whole list, the "contextMenus in content area" scenario should can reasonably be expected to involve interaction with the frame's document, if the context menu was opened from a child frame. For example, the menus.getTargetElement offers an identifier that extensions can use to look up the clicked element in the document in a content script: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/menus/getTargetElement#examples
To allow extensions to do something meaningful with their context menu, without requiring <all_urls>, we should allow extensions to access the target frame upon clicking the context menu. This grant should be expire as soon as the frame is navigated or removed.
Similar feature request on Chromium's issue tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=523572
| Reporter | ||
Comment 1•3 years ago
|
||
Here is an example of an extension developer getting confused and trying to document the behavior:
Thanks, Rob.
In Chrome access to the frame where context menu was opened is less useful because it lacks the getTargetElement API. Of course, some heuristics may be based on document.activeElement, window.getSelection() or lookup for images having the same URL as in the event handler argument. It is unfortunate that giving permission to a specific frame will cause greater divergence of WebExtensions in Chrome and Firefox.
Access to all frames besides ones created by the extension itself is discussed in https://crbug.com/826433 The use cases are ads blockers and extensions like dark reader.
It is a subject for discussion, but I do not like that commands.onCommand event does not provide info on currently focused frame if user interacts with this specific frame. Obtaining it requires excessive privileges: combined <all_urls> and webNavigation. Since keyboard shorcut may be bound to _execute_action, perhaps even browser action should allow to get the frame and permission to inject scripts. It might require a separate permission "active content". For keyboard navigation requiring context menu is a kind of limitation. (Does macOS have a keyboard shortcut for context menu?)
Roots of my confusion are in the following corner case. Unsure if it should be considered as a bug.
When context menu is opened inside add-on preferences tab in the extension manager (not as a separate tab) then top-level tab returned by tabs.query({currentWindow: true, active: true}) is not accessible by an extension for which the contextMenus.onClicked event is fired. Scripting availability may be disregarded, since it is a privileged page, but url and title propertied are missed.
In Firefox undefined is passed as the tab argument of the context menu listener.
In Chrome the listener receives another tab with id: -1 making things more confusing. Similar behavior may be observed for <object> and <embed> elements, frames containing PDF files.
Since frame content is quite special in all these cases, it seems add-ons can not benefit from additional permissions granted in response to context menu. It is another exception from the rule that a context menu gives access to the top level tab.
Updated•3 years ago
|
Updated•3 years ago
|
Description
•