0

I'm trying to find a way to open the default context menu on a [X,Y] viewport position inside a Chrome extension (content script). Is it possible? How can I do it?

The thing is, I've handlers on mouseup, mousemove mousedown and contextmenu which inhibit context menu and do some magic (gestures) so it'd be nice if I could just open the default context menu if no gesture was detected in mouseup. (i.e. if there was just single RMB click.)

I'm actually trying to fix this neat looking extension https://github.com/RyutaKojima/simpleGestures for the Gtk+ version of Chrome where the context menu is shown on mouse down.

Without this ability I guess I'll have to do temporarily disable mouse(up|down) and contextmenu handlers and somehow simulate RMB click in mouseup (if I won't get stuck on another limitation).

woky
  • 4,686
  • 9
  • 36
  • 44
  • 1
    See this quesion http://stackoverflow.com/questions/1241478/how-do-i-trigger-the-browser-context-menu-on-an-element-as-if-the-user-right-c, it seems it can't be achieve via JavaScript. – Haibara Ai Jun 22 '16 at 02:12

1 Answers1

1

Context menu invocation is a "user gesture" (Chrome uses it to allow an extension access a set of otherwise restricted functionality like reading/writing of clipboard or DOM of the active page in case only activetab permission is given in the extension's manifest). Thus your only way out is to make an accompanying crossplatform native app that can send a rightclick mouse event. It will be installed separately and communicate with your extension via Native Messaging API.

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • Whoa. Thanks. That seems like a possible route. I think it'll be better to focus on implementing this https://crbug.com/28226 though. Dev on IRC said that simple function for displaying context menu could make it in. – woky Jun 23 '16 at 10:39