I'm currently trying to trigger a trusted textInput TextEvent from a Chrome extension.
In Chrome ≤ 52 I could do the following thing:
const textEvent = document.createEvent('TextEvent')
document.execCommand('insertText', false, 'myString')
I confirm it does not work in Chrome 54 anymore. However, I have found a solution. I now use the clipboard API. To be more precise:
I create a temporary text area and focus it
I paste the current content of the clipboard to the text area, then save it to a variable
I then put the text I want to write in the text area, select it, and copy it
I put the focus back in the element I want to write to, and paste
I then reselect the text area, re-copy to put back the original stuff in the clipboard, and finally put the focus back in the element I'm writing to.
Some more trickery with the selection ranges goes on in my case, because I need to replace the selection text programatically, not only insert text, but I have explained all the main steps :) It's the only solution I have found that works everywhere, in ContentEditable divs and Inputs alike, with react or not. Good luck!