JSFiddle - React, Tailwind, and code Playground

HTML

<html>
<body >
    <ul>
        <li>Try typing text in the textarea to see if the capture works. </li>
        <li>Try clicking the button to see if simulation changes the textarea</li>
    </ul>
    <textarea></textarea>
    <button>Insert text</button>
</body>
</html>

JavaScript

$("button").click(function () {
    try {
        var textEvent = document.createEvent('TextEvent');
        textEvent.initTextEvent ('textInput', true, true, null, "testing 1 2 3 ", 9, "");
        
        var textarea = $("textarea").get(0);
        textarea.selectionStart = 0;
        textarea.selectionEnd = 0;
        
        textarea.dispatchEvent(textEvent);
    }
    catch (e) {
        alert ("Not supported by browser");
    }
});

var textarea = $("textarea").get(0);
if (textarea.addEventListener) {
    function onTextInput (event) {
        alert ("Captured text event: " + event.data);
    }

    // Google Chrome and Safari
    textarea.addEventListener ('textInput', onTextInput, false);
    // Internet Explorer from version 9
    textarea.addEventListener ("textinput", onTextInput, false);
}