0

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.

Edit:

manifest.json file

{
  "manifest_version": 3,
  "version": "1.0",
  "name" : "Teams",
  "permissions": [
    "activeTab"
  ]
}

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

Kindly help me to simulate keystroke. Thanks.

  • Your question is similar to this. [Send delete key in Chrome Input.dispatchKeyEvent API?](https://stackoverflow.com/questions/75373336/send-delete-key-in-chrome-input-dispatchkeyevent-api) – Norio Yamamoto Feb 08 '23 at 06:13
  • @NorioYamamoto I tried it, but getting error "VM6592:1 Uncaught TypeError: Cannot read properties of undefined (reading 'sendCommand')". Code: "chrome.debugger.sendCommand(element, "Input.dispatchKeyEvent", { type: 'rawKeyDown', code: 'KeyH' })". – Aamod Thakur Feb 08 '23 at 06:52
  • Maybe there is a problem with manifest.json, please post it. yeah? No way, it's not a chrome extension? – Norio Yamamoto Feb 08 '23 at 07:08
  • manifest.json "{ "manifest_version": 3, "version": "1.0", "name" : "Teams", "permissions": [ "activeTab" ] }" -- I wanted to directly paste javascript code in chrome console, I don't want to add that code in javascript file. – Aamod Thakur Feb 08 '23 at 08:18
  • It's hard to read, so please add it to the question instead of commenting. – Norio Yamamoto Feb 08 '23 at 08:28
  • Your extension is missing the "debugger" permissions – Ben Bracha Aug 21 '23 at 12:00

0 Answers0