How do I access the contents of WordPress Classic editor in admin area with JavaScript?

To get the editor content as a string in the classic editor use this:

content = tinymce.activeEditor.getContent();

Taken from https://stackoverflow.com/a/5843951/57482

Note that you should use the APIs provided rather than directly modifying the DOM if you want to modify the content. If you don’t, you won’t update plugins local states in javascript causing problems. Modifying the DOM should be a last resort.

Also note that this will not work for the block editor. The block editor requires a completely different approach, and you can’t then edit the content and put it back without breaking the blocks or turning everything into a custom HTML block causing other issues.