Javascript how to simulate keystroke for {IsTruested:true}?

Feb 8 2023 6:08 AM

I wanted to automate in 3rd party site using chrome console. For that I required to enter strings in a input field(its actually a

para which is being used as input).

For that I am using the below to simulate keystroke.

Code:
element.dispatchEvent(new KeyboardEvent('keydown', {'key': 'a'}));

But got the below error.

Error:
[{"isTrusted":true}]
console.error @ ?agent=web&version=23010100913:98
handleError @ ?agent=web&version=23010100913:109

I also tried element.value += "a" but the value is not getting changed.
After searching on internet (How to trigger an ‘isTrusted=true’ click event using JavaScript?) I tried the below code.

chrome.debugger.attach(element, "1.2", function() {
    chrome.debugger.sendCommand(element, "Input.dispatchKeyEvent", arguments)
})

But got the error "Uncaught TypeError: Cannot read properties of undefined (reading 'attach')". I think I haven't given permission or something, I am unable to figure it out.

I am not a developer, hence do not have a good understanding to chrome.debugger.

Kindly help me to simulate keystroke. Thanks.

 

 

 


Answers (1)