title: Chrome extension - how to select all text of tab and copy
body: <p>Can anyone tell how to copy entire page similar to pressing Ctrl+A and then copying of current tab to clipboard.</p>
  
  <p>Currently i have this but it is doing nothing though extension is successfully added to chrome:</p>
  
  <p><strong>manifest file</strong></p>
  
  <pre><code>"permissions":
  [
     "clipboardRead",
     "clipboardWrite"
  ],
  // etc
  </code></pre>
  
  <p><strong>content script</strong></p>
  
  <pre><code>chrome.extension.sendRequest({ text: "text you want to copy" });
  </code></pre>
  
  <p><strong>background page</strong></p>
  
  <pre><code>&lt;html&gt;
   &lt;head&gt;
   &lt;script type="text/javascript"&gt;
     chrome.extension.onRequest.addListener(function (msg, sender, sendResponse) {
  
        var textarea = document.getElementById("tmp-clipboard");
  
        // now we put the message in the textarea
        textarea.value = msg.text;
  
        // and copy the text from the textarea
        textarea.select();
        document.execCommand("copy", false, null);
  
  
        // finally, cleanup / close the connection
        sendResponse({});
      });
    &lt;/script&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;textarea id="tmp-clipboard"&gt;&lt;/textarea&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>popup</strong></p>
  
  <pre><code>&lt;textarea id="tmp-clipboard"&gt;&lt;/textarea&gt;
  &lt;input type="button" id="btn" value="Copy Page"&gt;
  </code></pre>
  
  <p>I cannot get this to work, wonder what I am missing here.</p>
  
  <p>Can anyone please guide on how to mimic <kbd>Ctrl</kbd>+<kbd>A</kbd> followed by <kbd>Ctrl</kbd>+<kbd>C</kbd> for current tab so that it stores in clipboard ?</p>