Hi all. I'm having a hell of a time trying to insert text into an HTML textarea, or grab data from the clipboard with a Chrome extension (using a context menu). My elementary javascript skills almost seem not to apply once thrown into a Chrome extension. I currently have these permissions in my manifest.json file:
"permissions": [  "contextMenus",  "clipboardRead",  "clipboardWrite"],
It seems like document.execCode('paste') and setting up a listener might be the way to go, but it looks like security issues prevent direct paste, and I'm confused by syntax and what code goes where. Programatically this is what I'd imagine the function would do:
  1. Get the selected string in the current textarea and copy to a variable "orig_str".
  2. If a string, get the current clipboard and store it in a variable "clip_str". If not, set variable to nothing.
  3. Overwrite the original selected string in the current textarea with "orig_str + clip_str".
So if the textarea contained:
I eat peas
and the clipboard contained:
 and cook
and the user selected "eat", then the function was activated, the string in the textarea would be changed to read:
I eat and cook peas
Any help down the right path would be appreciated, preferably with straight JS rather than JQuery. My code as it exists can be found here.