title: Document.execCommand() works only in developer tools
body: <p>I'm trying to copy all the links of a web page to clipboard. I'm trying to join all the anchor tags into a string, putting that string into a input field and then copying it by <code>document.execCommand("copy")</code> but somehow <code>document.execCommand("copy")</code> only works in browser developer tools. I want it to work in a script loaded in web page. Kindly Help me, Thanks in advance.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var
  body = document.querySelector("body"),
  input = document.createElement("textarea"),
  a = document.getElementsByTagName("a"),
  list = [],
  anchor = document.createElement("a");
  for (let i = 0; i &lt; a.length; i++){
      list.push(a[i]);
  };
  list = list.join("\r\n");
  input.value = list;
  input.setAttribute("readonly", "");
  input.style = "position: absolute; left: -9999px;";
  body.appendChild(input);
  input.select();
  document.execCommand('copy');
  body.removeChild(input);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="ie=edge"&gt;
      &lt;title&gt;test&lt;/title&gt;
      &lt;/head&gt;
  &lt;body&gt;
      &lt;a href="http://ali.com"&gt;sample link&lt;/a&gt;
      &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>