[NOTE]: I've checked SO answers which might have worked 5 years ago which don't seem to work. Please don't copy-paste that junk. thank you.
task:
Take a string, conver it into sequece of keystrokes, do something with that sequence and ultimately come to the conclusion that the webpage you want to put that string in has gone through everything it needs to go through as if the string characters were sequentially pressed by a human through a keyboard.
Question:
How the hell is this done?
element.value = 'test123' // BAD EXAMPLE
if you don't know why this is a bad example, don't answer this question.
element.dispatchEvent(/*event for keydown*/)
element.dispatchEvent(/*event for textInput*/)
element.dispatchEvent(/*event for keyup*/)
^ this... this should technically work, however I've not found a working example.
Additionally apparently there may be some issues with event.isTrusted which I don't know how to get around.
... maybe I'm not using the right tools...
chrome.input.ime ... this seems to be related to chromiumOS and chrome doesn't react to it. (at least to what i wrote (i'm using windows) )
maybe chrome.debugger.... ??? though I can't figure out how to dispatch a keyboard event to an element through this api
TL/DR
Please post a valid example (which works beyond element.onkeydown(***)); which results in a keystroke being registered by a webpage as if it originated from a keyboard (or OS) when in fact it's from javascript.