title: Get selected text in a chrome extension
body: <p>I wanna make an extension that takes the selected text and searches it in google translate
  but I can't figure out how to get the selected text.</p>
  
  <p>Here is my manifest.json</p>
  
  <pre><code>{
  "manifest_version": 2, 
  "name": "Saeed Translate",
  "version": "1",
  "description": "Saeed Translate for Chrome",
   "icons": {
      "16": "icon.png"
    },
  "content_scripts": [ {
        "all_frames": true,
        "js": [ "content_script.js" ],
        "matches": [ "http://*/*", "https://*/*" ],
        "run_at": "document_start"
     } ],
  "background": {
      "scripts": ["background.js"]
    },
  "permissions": [
  "contextMenus",
  "background",
  "tabs"
  ]
  
  }
  </code></pre>
  
  <p>and my background.js file</p>
  
  <pre><code>var text = "http://translate.google.com/#auto/fa/";
  function onRequest(request, sender, sendResponse) {
     text = "http://translate.google.com/#auto/fa/";
     text = text + request.action.toString();
  
   sendResponse({});
  };
  
  chrome.extension.onRequest.addListener(onRequest);
  chrome.contextMenus.onClicked.addListener(function(tab) {
    chrome.tabs.create({url:text});
  });
  chrome.contextMenus.create({title:"Translate '%s'",contexts: ["selection"]});
  </code></pre>
  
  <p>and my content_script.js file</p>
  
  <pre><code>var sel = window.getSelection();
  var selectedText = sel.toString();
  chrome.extension.sendRequest({action: selectedText}, function(response) {
    console.log('Start action sent');  
  });
  </code></pre>
  
  <p>How do I get the selected text?</p>