I want to be able to mimic the events of a user typing on a keyboard within a Google Chrome Extension in much the same way that one can do it with puppeteer such that it generally fires all the same events as would a user typing manually.
Are there methods available in Google Chrome libraries to facilitate this? I have tried using JavaScript and DOM manipulations client side directly including firing off events for mouse clicks etc... This works on some pages in lieu of manual events but on a few pages that are crafty only manual and puppeteer library keyboard/mouse events accurately mimic and fire off all events.
If there is a library that facilitates this for Google Chrome Extensions I’d really appreciate someone pointing me in the right direction.
Related
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
There has been a lot of discussions on Stack Overflow about how to dispatch a keyboard event programmatically with JavaScript. However, they are not simulating 'real' key presses in the sense that they merely fire a predefined event handler.
What I want is to simulate CTRL+F to bring up the browser search box. Is that possible at all?
window.find(…) does that.
In general, you're out of luck though trying to orchestrate native browser functionality from within a webpage. Browser extensions can do more.
My iOS app uses a WKWebView with contenteditable = true on a specific div. I'd like to have code to make the keyboard show up for the web view, so the user can just start typing. Things I've tried that have had no effect:
Telling the web view to becomeFirstResponder (a long shot, because the web view wouldn't know what div to use).
Injecting JS to tell the div to focus(). (This works in other browsers, but sadly not in WKWebView)
Simulating touch events in JS via TouchEvent and dispatchEvent() in the hope of making it seem that the user had tapped on the div.
In the third case I also used addEventListener() to observe the simulated touches and compare them to real touch events from tapping the screen. It looks like the key difference is that the event's isTrusted value is false for the simulated touches.
I get that it's a potential security issue to let apps simulate touch events, but I didn't have any other ideas. I'm trying to get the keyboard to appear, what the user types is up to them and not something I want to mess with. Basically I want the same thing as calling becomeFirstResponder() on a UITextView.
This is very similar to a WebKit issue 142757 but I haven't figured out how to use the suggested workaround linked from there.
Clarification: I can set up and use an editable web view, but the keyboard doesn't appear until I tap on the web view. I'm trying to make the keyboard appear automatically, without requiring a tap to initiate editing.
I tried this in an iPad playground, and it works without any action on my part. It’s possible there is another view that is capturing touches, or “contenteditable” is misspelled, or something else?
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
I've some very old Flash applications, which we don't want to rebuild to add a new feature. We simply need to detect when the user has become idle. So, if the Flash application receives no key or mouse events after 3 minutes, we want to track that time till the user interacts with the application again.
We've considered wrapping the applications in newer Flash applications to include the key/mouse event tracking; however, early research shows that some of our apps are so old that they use event systems or AVM's (ActionScript Virtual Machines) that are incompatible. Also, it seems that mouse events on the inner application don't bubble up to the outer application. (I think the direction of event processing is backwards in versions of Flash prior to 8)
Anyhow, the next idea on the table is to see if we can determine when the user stops interacting with the old Flash applications using JavaScript. Can anyone confirm whether or not it is possible to detect, using JavaScript only, when a swf in an HTML document loses focus or key and mouse events stop and start occurring on the swf?
Without rebuilding you can't get any events from old swf file. But you can wrap swf up and get mouse events using jQuery:
$('#swfDiv').bind("mouseenter",function(){
$('#swfDiv').show();
}).bind("mouseleave",function(){
$('#' + divCursor).hide();
});