title: Chrome Extension - Get entire text content of the current tab
body: <p>I'm developing an extension where I need to get the entire text content on the current tab. Now I've a plugin which retrieves selected text from the current tab. So, in essence I'm looking for the ctrl-A version of it :). This is what I've done so far taking the hint from @Derek.</p>
  <p>This is in my event handler(this is just one, there are other listeners too for <code>onUpdated</code> etc):</p>
  <pre><code>chrome.tabs.onSelectionChanged.addListener(function(tabId,changeInfo,tab) {
    chrome.tabs.getSelected(null,function(tab) {
      chrome.tabs.sendRequest(tab.id, {method: &quot;getSelection&quot;}, function (response) {
        selectedtext = response.data;
      });
      chrome.tabs.sendRequest(tab.id, {method: &quot;getText&quot;}, function (response) {
        alltext = response.data;
      });
    });
  });
  </code></pre>
  <p>This is what I've written in the content script:</p>
  <pre><code>chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    if (request.method == &quot;getSelection&quot;)
      sendResponse({data: window.getSelection().toString()});
    else if (request.method == &quot;getText&quot;)
      sendResponse({data: document.body.innerText});
    else 
      sendResponse({});
  });
  </code></pre>
  <p>However the <code>document.body.innerText</code> is returning undefined. I need the entire text of the current tab in <code>alltext</code>. Can someone help me out on this?
  Thanks.</p>