google chrome devtools – Use JavaScript to set value of textbox when .value and events don’t seem to work – Stack Overflow
Posted by jpluimers on 2022/11/29
For my link archive: [Wayback/Archive] google chrome devtools – Use JavaScript to set value of textbox when .value and events don’t seem to work – Stack Overflow
TL;DR
Sometimes fields are blocked from pasting values.
Normally a trick like this works in the chrome development panel console:
document.getElementById('nonPasteElementID').value = 'myValueFromTheClipboard'
With some web development environments this does not work.
For react, after finding the react render name for the input (in the case of the answer, it was “reactNameForInputElement
“) this is a solution:
To make it work you will need this:
const input = document.getElementById('nonPasteElementID'); const event = new Event('reactNameForInputElement', { bubbles: true }); input.value = '1'; input.dispatchEvent(event);
–jeroen
Leave a Reply