Closed Bug 1392568 Opened 7 years ago Closed 7 years ago

Dispatch node in contextMenus.onClicked

Categories

(WebExtensions :: Untriaged, enhancement)

57 Branch
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1325814

People

(Reporter: yfdyh000, Unassigned)

References

Details

If you're asking for the same thing as the chromium bug you cited, this isn't feasible.  Background scripts (where an onClicked handler can run) and content pages run in different processes (and in different security contexts).
If you're actually asking for something else, please clarify the request?
Flags: needinfo?(yfdyh000)
I hope it dispatches an object information in callback of onClicked, maybe cloneInfo() of document.activeElement. Then the background script can send message to content script to manipulates the element with the information.
Flags: needinfo?(yfdyh000)
Specifically, what information do you need which is not available in the contextMenus.OnClickData[1] object?

[1] https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData#Type
Get the context menus was open in which element, use the context menus to insert text to the element.
This is not practical for the reasons described in comment 1
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → WONTFIX
<del>Why, only clone element information does not involve the element itself.</del>

Well, I think I understand, so the context menu is also generated in chrome instead of the content context, not being involved for the content context.
Status: RESOLVED → VERIFIED
I don't see how this can work given all of this is asynchronous and cross-process -- the background process can't have a handle to a node which exist in a content process.

Cloning the node into background process-side is not going to accomplish anything more than say using a xpath as reference. It seems what you are asking is a whole infrastructure to be added so that background process can manipulate a DOM node in a content process, all of this in a transparent way -- in short going backward to old ways API-wise with all the bad consequences.

I (roughly) suggest an approach which does not involve any API change (regression).

- Content script-side: detect "mousedown" events (optionally narrow to right-click events):
    - Store node locally somehow, let's call this "content script data registers".
    - Send message to background page of extension that a node was clicked, along with whatever information you may required in order to act on the node later.
- Background process-side: receive message from content process about a node being clicked:
    - Store all information needed to be able later to tell the content script to act on whatever node was clicked -- let's call this "background process data registers":
         - Whatever information about the node passed by content script
         - Tab id
         - Frame id

- Background process-side: contextmenus.OnClicked event handler called
    - Take the event handler being triggered as a mere signal to act upon the information currently sitting in the background process data registers.
    - Send text to be inserted through a message at the tab id/frame id registers.
    - Clear background process data registers.
- Content process-side: receives message about text to-be-inserted in currently locally stored node.
    - Insert text.
    - Clear content script data registers.

The only thing I see would help here is that the content script would be given a way to detect when the context menu is *about to be opened* for a specific node -- currently need to rely on "mousedown" event.
(In reply to R. Hill from comment #7)
> I don't see how this can work given all of this is asynchronous and
> cross-process -- the background process can't have a handle to a node which
> exist in a content process.
> 
> Cloning the node into background process-side is not going to accomplish
> anything more than say using a xpath as reference. It seems what you are
> asking is a whole infrastructure to be added so that background process can
> manipulate a DOM node in a content process, all of this in a transparent way
> -- in short going backward to old ways API-wise with all the bad
> consequences.

I think getting an unreliable element reference is acceptable for me, I assume and accept the page content is generally not changed when the context menu is open.

I tried some ways but have not yet succeeded and I will continue to try.
Status: VERIFIED → RESOLVED
Closed: 7 years ago7 years ago
Resolution: WONTFIX → DUPLICATE
I just figured out the problem for me, I actually did not need to handle elements in background script, just send message (like clearing active input), storing and handling elements within content script is good, although it may have a little uncertainty due to the asynchronous.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.