I'm developing a chrome extension where I can insert text inside github web editor. The inserted text should be at the caret position, which I can't figure out how get it.

The github editor, which is an ace editor, has this HTML code:
<div class="commit-create">
<textarea id="blob_contents"
      class="file-editor-textarea js-blob-contents js-code-textarea"
      rows="35" name="value"
      data-filename="README.md"
      data-language="Markdown"
      data-ace-mode="markdown"
      data-allow-unchanged=""
      data-test-id="blob-file-editor"
      placeholder="Enter file contents here"
      spellcheck="false"
      autofocus>
Line 1
Line 2
Line 3
Line 4
</textarea>
</div>
In my manifest.json, I included ace.js (obtained from here, I hope it's the correct .js file)
...    
"content_scripts": 
      [{
        "matches": ["*://*.github.com/*/edit/*"],
        "js":      ["ace.js", "content.js"]
      }],
...
here's the javascript code provided by a user:
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) 
{
    ...
    var editor = document.querySelector(".ace_editor").env.editor;
    var cursor = editor.selection.getCursor() // returns object like {row:1 , column: 4}
    editor.insert("text") // insert string at cursor
    ...
}
I get this error
Error in event handler for runtime.onMessage: TypeError: Cannot read property 'editor' of undefined
=== edit 1 ====
Thanks to a user I did a little bit progress. The code works on chrome console, but it doesn't work on content.js, it might be a security issue which I don't understand why.
 
     
     
    