Hi developers,
I'm looking for some opinions and / or suggestions.
Is there a way to get mouse coordinates when user activate the contextMenu on a selection?
I'd like to create a small div near the position where the user clicks to open the context menu and then clicks on an item within the same menu.
The contextMenu is not activated on an extension page, but instead on a content page.
I'm talking more specifically about manifest V3 and programmatically injected scripts (with chrome.scripting).
When the script is injected (only if necessary) I have not the possibility to read the event object which contains the mouse position.
Or rather, by injecting a mouseup handler into the page together with the script, this is (rightly) activated from the second event onwards.
In practice, the first event is lost, which is the one that triggers the contextMenu and injects the script into the page.
I hope I was clear.
Obviously this happens if I decide to inject the script programmatically and not declaratively (which I would like to avoid)
I don't know if there is a way to do this, but I was thinking that it would be useful to have the "event" object in response to the "click" event of the contextMenu which it would seem is not expected.
The event handler returns only two objects "info" and "tab".
If there was also "event" I would have solved my problems because at this point
I would pass the mouse coordinates contained in event object to my content script as parameters (feature not yet implemented)
or I would store these coordinates in a chrome.storage var to be read by the other side.
chrome.contextMenus.onClicked.addListener((info, tab, ?_event_?) => {
let tp = info.menuItemId;
let ist = info.selectionText;
...
});
This instead is essentially the manifest
{
"manifest_version": 3,
"minimum_chrome_version": "89.0.0.0",
"background": {
"service_worker": "worker_wrapper.js"
},
"web_accessible_resources": [
{
"resources": [
"img/pinNote.png"
],
"matches": ["https://*/*", "http://*/*", "file://*/*"]
}
],
"permissions": [
"contextMenus",
"activeTab",
"scripting"
]
...
}
Thank you.