intoli / remote-browser

A low-level browser automation framework built on top of the Web Extensions API standard.
Other
1.73k stars 105 forks source link

How can we simulate typing? #59

Open timwis opened 6 years ago

timwis commented 6 years ago

I'm really excited about this project. A potential gotcha was pointed out in the hn thread, so I thought I'd take the conversation here since that thread seems to have lost momentum.

How can we simulate typing using remote-browser? Technically we can set an input element's value to something, or create keypress, keydown, etc. events. But it seems that webdriver takes a different approach that's closer to true user input. I don't know how webdriver does it, but the use case is a website that, say, auto-formats a phone number or credit card number as you type it. Sometimes these don't work when you set the value of the input field. Another example is JS-based validations. The type method on puppeteer and selenium seem to fool the browser into thinking a user is typing. How might we achieve this in remote-browser?

sangaline commented 6 years ago

This is a great question, and it's definitely something that we've been thinking about quite a bit. The philosophy of the project is heavily centered around the idea of things being implemented in vanilla JavaScript using existing browser APIs, so simulating the JavaScript key events is really the closest that we'll be able to get. My understanding is that this should be realistic enough for the vast majority of testing and web scraping tasks, but I would be curious to hear about edge cases where it wouldn't be if you're aware of any.

Simulating key presses like this manually is clearly a bit cumbersome, and our intention isn't that each user should be hacking something like this together themselves. We have some higher-level tooling in the works that will facilitate these sort of interactions, and you can expect an update in the near future that provides similar functionality to that of the type() methods provided by Puppeteer and NightmareJS. This might be implemented as a separate library, but it will be designed to work seamlessly with Remote Browser.

blueberryman commented 6 years ago

Is there any reason why simulating the full event cycle of a keyboard type shouldn't work? See a demo taken from here.

klaussa commented 5 years ago

By any chance has any update of this topic been released ?

Kind Regards