laurentj / slimerjs

A scriptable browser like PhantomJS, based on Firefox
http://slimerjs.org
Other
3k stars 258 forks source link

Added keycodes and support for keyup and keydown in firefox 60 #697

Closed Jtkantor198 closed 6 years ago

Jtkantor198 commented 6 years ago

Quick fixes to get slimerjs working with firefox 60. Patched keydown and keyup events, but took no action on keypress. Open to expansions or modifications, just got this working for my project.

laurentj commented 6 years ago

Thank you. No support of keypress in your sendkeyevent function? Does it pass all tests?

Jtkantor198 commented 6 years ago

Definitely not passing all tests. I can work on adding support for keypress events and getting everything passing, but likely won't get to it today.

Jtkantor198 commented 6 years ago

TLDR: Can't create one to one key event generator with nsITextInputProcessor. Would have to change tests if this is the desired solution.

After some more reading it seems nsITextInputProcessor simply doesn't support directly sending arbitrary keyevents. It tries instead to recreate sensible user input. For instance the keydown function creates a keydown and a keypress event. Also the normal modifiers aren't supported. You have to call keydown on shift, then keydown on another key if you want to generate a keyevent with a modifier shiftKey in the dom. I don't think this will ever be a one to one keyevent generator.

I looked into using https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIDOMWindowUtils#dispatchDOMEventViaPresShell() but haven't had any success yet.

Keeping track of the down/up status of shift, alt, exc. is the only choice if nsITextInputProcessor is the preferred way to go here.

As far as raw keypress events are concerned it might be better to simply not support them unless there is some issue with that. They are being created by nsITextInputProcessor anyways if a keydown is initiated. There is a repeat property that can simulate the multiple keypress events that come from holding down a key. It could just always set it to true.

Either way the tests as is aren't going to pass (they test raw keypress and many shift+char tests expect only one keyevent per sendEvent call). They would have change since behavior would change.

laurentj commented 6 years ago

If we have to change the tests, then it means that this patch will break existing scripts. It is not acceptable from my point of view.

Jtkantor198 commented 6 years ago

That's fair. Like I said I was simply using this for my own scripting purposes with casperjs. I'll simply use mine until you find a more suitable solution.