I want to simulate a set text in a react form page similar to this page (the source of the page is not available to me).
I'm using the following code, which works for me in non-react forms, but it seem to not update the react model in the above case - manual click on the form after the set text clears the input for some reason.
Note that I'm running my code as a content script from an extension, so I can't change the implementation of the app. This is my sample JS code:
var e = document.body.querySelector("[placeholder='Your name']");
e.value = "my new value";
e.dispatchEvent(new Event('change', {bubbles: true, cancelable: false}));
Some clarifications:
I have no problem injecting code to the page, however I don't own the page, and my solution needs to be robust - fit as many pages as possible.
The code I wrote above runs in the original page's context, and not the extension's sandbox, so this is not a concern here.
What I'm looking for is a code snippet in the spirit of the above code that doesn't rely on a specific react form implementation, and uses native events to apply text to the input field.