I am trying to write a simple Chrome extension that copies some information from one webpage and fills the appropriate input fields on another. The input field’s value is (visibly) set by JavaScript: inputField.value = "some value"
in a content script injected into the webpage. Then, when I click on other input fields, its value changes back to its original value (which is not desirable). I am trying to find the cause of this.
(The website is https://mojezasielky.posta.sk/#dashboard – you would probably have to register – specifically "Balík -> Nová zásielka".)
I tried adding
inputField.dispatchEvent(new Event("input", {bubbles: true}));
inputField.dispatchEvent(new Event("change", {bubbles: true}));
expecting that maybe something listens for these events, but it still behaves the same.
What could be the cause of this behavious? How can I prevent this?
2
Answers
The solution for this answer worked for me. Specifically, I had to add:
I still don't know why, but it seems understandable that something is listening for this event.
After registering and opening the dashboard, I cannot find "Nová zásielka" after clicking on "Balík". So I could not test my ideas directly.
The ideas:
el.setAttribute('value','your value');
defaultValue
field, maybe you could also try setting that?