Programatically show default context menu from Chrome content script - javascript

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).

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.

Related

Switching touch events to mouse events by using Chrome Extension API

I am developing a Chrome Extension as panel in dev console for mobile interface testing and I need to pick elements (Similar to element picker in Dev Console) and process things according to picked element.
User should be able to use responsive or any other mobile interface. Changing to a custom device does not work for me.
I should be able to listen MouseEvents like mousemove instead of pointermove. Because, user should move mouse cursor over the site and catch elements as they move. Pointer events does not provide this.
It would be also OK, if i could initialise The Element Picker programatically and listen events from it.
I am not expecting someone to share a code sample. Check this API or naming correction is also welcome.
Thanks in advance

Electron app interacting with WebView drag-drop

I'm developing a (desktop) application in Electron (v1.6.2) that has a <webview> element (hosting 'guest' web pages) and a number of text fields, both <textarea> and <input type="text">.
We would like the user to be able to select text within the guest page inside the WebView and drag-and-drop it into the application's fields -- but, this isn't working.
Without doing anything special, I can select text in the guest page and drag-and-drop it into other applications outside of Electron.
E.g. -
Dropping it into a text editor, a text-field in a web-browser or my terminal window works fine.
It even works dropping it into a field in a different instance of my Electron application.
I can also drag text that is in the application, but not inside the WebView, and drop that in the fields Ok.
However, when dragging the text selected in the WebView, the fields in the application are not sensitive to events -- i.e. they receive no dragover or drop events, and focus does not switch to them as you would expect.
I've tried adding event handlers to the <webview> to intercept the mouse events (mosedown, mousemove, mouseup) in order to manually control things and tried to use event.preventDefault = true to disable the events from passing down to the guest page.
Everything behaves as I would expect util the moment when it is recognised that you are dragging text. Visually, this is the moment when the pointer switches to a closed fist and a ghostly rectangle appears showing the selected text. At that moment all mouse events cease to be received by the <webview> event handlers. It seems that the application is 'frozen' when text is being dragged.
Is there anything I can do about this?
It would work either to: -
- prevent the WebView from actually dragging text, and for me to simulate it programmatically;
- or to find a way to 'unfreeze' the application during the text-dragging, so that the fields are active, can see events and can receive dropped text.
This is a bug present in Electron v1.6.2.
It is fixed in Electron v1.6.5, released at the end of March 2017.
I've now updated to the latest stable release, v1.6.11, and the issue is fixed.

Using JavaScript to change the scroll mode of the BROWSER?

From JavaScript, how can I change the scroll mode of the browser to put it into the user-controlled autoscroll mode? (Note: I'm not asking how to use JavaScript to automatically scroll browser content.)
Example scenario: From within a Greasemonkey script, I'm using a 'click' event listener to intercept middle-clicks on links that I want to prevent opening in another tab. This works fine. But I also want those middle-clicks to result in the browser going into the user-controlled autoscroll mode, like it does whenever a non-link is middle-clicked.
Is this even possible?

Override site specific JavaScript right click context menu with browser specific right click context menu

Is there a way in Mozilla Firefox, Internet Explorer and/or Google Chrome to override the site specific right context menu (launched via JavaScript) so that the browser context menu shows instead? I want to be able to use the browser add-on options in the context menu, but some sites don't allow this. If you have any experience with any of these browsers, please respond and I will up-vote you.
One example:
Open Google Mail and right click a message in your inbox.
The site admins generally do this for security reasons. However, you can get around this easily if you know bit of HTML / JavaScript. Just tweak your 'mousedown' / 'click' handler. In case of jQuery, you might want to disable 'contextmenu' event.
There are some browser extensions to achieve this, according to http://www.techpanache.com/how-to/enable-right-click-menu-on-chrome-and-firefox/:
Allow Right Click fro Chrome
RightToClick for FireFox

Is it possible to generate a right click event using a character key in a browser in order to access the context menu?

This is something like simulating the mouse right click to a keyboard key in javascript so as to obtain the context menu and navigate through it to launch the console(Inspect Element).
What i am able to do is.. I can simulate the right click event but it does not generate the context menu on the keypress. When mouse right click is used, it shows the event phase as the bubbling phase whereas on the keypress it shows the event phase as the target phase. Can someone throw any light on this??
What you really want to do is call a function that initiates the (Firebug?) inspect element function. There is no standard javascript function to access the context menu, nor does it seem like a good idea for browsers to allow scripts in web pages access to it, though it might be an extension available in specific browsers for enterprise or controlled environment applications.
For completeness, you can dispatch a click event into the DOM with parameters to emulate a right mouse button click, but that will not open the context menu.

Categories