0

I'm building a Chrome extension that enables the user to insert canned responses into Youtube comments on their channel. I insert the text using textarea's value property:

getHighlightedComment().querySelector("textarea").value = cannedResponseText

The problem is, the textarea doesn't adapt its size and the submit button doesn't get enabled until I type in another letter manually.

enter image description here

enter image description here

I have a different extension installed that has a similar functionality that doesn't have these problems, so it must be possible.

I already tried sending keypress/keydown/keyup events manually, but they seem to not work inside textareas. Nothing happens in response to them.

Florian Walther
  • 6,237
  • 5
  • 46
  • 104
  • 1
    I don't see any `textarea` element in youtube comment form. They use a `contenteditable` editor. See [Enter data into a custom-handled input field](https://stackoverflow.com/q/57879322). – wOxxOm Mar 18 '22 at 00:08
  • @wOxxOm Thank you! I actually found `execCommand` earlier but didn't use it because of deprecation. So you're saying that is still the right choice now in 2022 until there is an alternative? – Florian Walther Mar 18 '22 at 14:38
  • It works, thank you! Although the element where I input text IS a `textarea` HTML element. – Florian Walther Mar 18 '22 at 14:41
  • 1
    It may be the only choice for the next 20 years, for all I know. – wOxxOm Mar 18 '22 at 14:44

1 Answers1

0

I guess you need to trigger some event on your field after actual change Here is how you can deal with it.

UPD.

I tried sending keypress/keydown/keyup events but it seems they don't work inside textareas. Nothing happens.

I guess it is more about onchange event.

Also you need to check the CSS of your textarea - rows are not hardcoded, height and max-height is not hardcoded (has value 'auto').

Here are some workarounds to update it with JS - https://stackoverflow.com/a/25621277/9994697

Vasily
  • 59
  • 3
  • I tried sending `keypress`/`keydown`/`keyup` events but it seems they don't work inside `textarea`s. Nothing happens. – Florian Walther Mar 17 '22 at 21:13
  • not sure, but are you also tried dispatching input event? – Robbi Mar 17 '22 at 22:05
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 18 '22 at 03:18