title: Copy to clipboard as plain text
body: <p>I'm using this code in <code>background.js</code> in a Chrome extension to copy text to the user's clipboard:</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
      function(request, sender, sendResponse) {
          if (request.command == "copy") {
              executeCopy(request.text);
              sendResponse({farewell: "copy request received"});
          }
      }
  );
  
  function executeCopy(text){
      var copyDiv = document.createElement('div');
      copyDiv.contentEditable = true;
      document.body.appendChild(copyDiv);
      copyDiv.innerHTML = text;
      copyDiv.unselectable = "off";
      copyDiv.focus();
      document.execCommand('SelectAll');
      document.execCommand("Copy", false, null);
      document.body.removeChild(copyDiv);
  }
  </code></pre>
  
  <p>It copies the text with formatting. How can I copy the text in plain text with no formatting?</p>