title: Copy selected text via a context menu option in a Chrome extension
body: <p>I am trying to create a context menu option which copies some  text to the system clipboard. </p>
  
  <p>Currently, I am just copying a hard-coded string literal, but I am wondering how it could be changed to copy selected text.  Specifically, I don't know how to properly create the <code>createProperties</code> object (see bottom)</p>
  
  <p>It is my understanding that this can only be done through a background page. </p>
  
  <p>I have the following background page:</p>
  
  <p><code>background.html</code></p>
  
  <pre><code>&lt;textarea id="temp"&gt;&lt;/textarea&gt;
  &lt;script src="context.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <hr>
  
  <p><code>context.js</code> is as follows:</p>
  
  <pre><code>chrome.contextMenus.create({
      "title": "Freedom",
      "contexts": ["editable"],
      "onclick" : copyToClipboard
    });        
  
  function copyToClipboard()
  { 
      var tempNode = document.getElementById("temp");
      tempNode.value = "some text";
      tempNode.select();
      var status = document.execCommand('copy',false,null);
  
      if(status) alert('successful');
  
      else alert('unsuccessful');
  }    
  </code></pre>
  
  <hr>
  
  <p>my <code>manifest.json</code> is as follows:</p>
  
  <pre><code>{
      "manifest_version": 2,
  
      "name": "Freedom",
      "description": "Provides users useful and fun context menu options that they can access from anywhere.",
      "version": "1.0",
  
      "permissions": [
          "contextMenus",
          "clipboardWrite"
          ],  
  
      "background": {
          "page": "background.html"
      }   
  
  }    
  </code></pre>
  
  <hr>
  
  <p>I am apparently declaring the chrome.contextMenus.create() function incorrectly. I have read the docs for it and I can only imagine that I am not properly creating the <code>createProperties</code> object. </p>
  
  <p>I have been trying to mimic these sources: </p>
  
  <p><a href="https://stackoverflow.com/questions/14452777/is-that-possible-calling-content-script-method-by-context-menu-item-in-chrome-ex">Is that possible calling content script method by context menu item in Chrome extension?</a></p>
  
  <p><a href="http://paul.kinlan.me/chrome-extension-adding-context-menus/" rel="nofollow noreferrer">http://paul.kinlan.me/chrome-extension-adding-context-menus/</a></p>
  
  <p>some other related questions are:</p>
  
  <p><a href="https://stackoverflow.com/questions/3436102/copy-to-clipboard-in-chrome-extension/12693636#12693636">Copy to Clipboard in Chrome Extension</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5235719/how-to-copy-text-to-clipboard-from-a-google-chrome-extension">How to copy text to clipboard from a Google Chrome extension?</a></p>