After clicking on the button, the input new value returns to the old value

I need advice, I’m doing such an extension JS, but maybe I’m making a mistake in that the app runs on Angular

var input1 = document.getElementsByClassName("vypln")[0];

var enter = new CustomEvent('keyup');
enter.which = 13;
enter.keyCode = 13

input1.focus();input1.value="";
document.execCommand('insertText', false, 4);
input1.dispatchEvent(enter);

document.getElementsByClassName('buttons')[0].querySelector('button').click();

The data is written to the input, … but after clicking on the button, the old value is set. I want value to stay there and do it.
Interestingly, if I use this code and then click (mouse / manually) anywhere and then call document.getElementsByClassName('buttons')[0].querySelector('button').click(); so it works fine.
Thank you all for the advice)