<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - document.execCommand(&quot;copy&quot;) only triggers if there is a selection."
   href="https://bugs.webkit.org/show_bug.cgi?id=156529">156529</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>document.execCommand(&quot;copy&quot;) only triggers if there is a selection.
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Safari Technology Preview
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>OS X 10.11
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>HTML Editing
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>lgarron&#64;chromium.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Safari 9.1.1 
OSX 10.11.4

1. Visit <a href="https://permission.site">https://permission.site</a>
2. Click on &quot;Copy&quot;

Expected:
The text &quot;This text was copied from the permission.site clipboard example.&quot; is placed on the clipboard.

Actual:
No change in the clipboard.

However, if you select (any) text on the page before step 2, then step 2 will result in the expected behaviour.

It appears that document.execCommand(&quot;copy&quot;) does not fire a copy event if there is no selection on the current page.
Thus, the following idiom does not work as expected if there is no selection at the time you copy:

      document.addEventListener(&quot;copy&quot;, function(e){
            e.clipboardData.setData(&quot;text/plain&quot;, &quot;test&quot;);
            e.preventDefault();
      });

      var copyButton = document.createElement(&quot;button&quot;);
      document.body.appendChild(copyButton);

      copyButton.addEventListener(&quot;click&quot;, function() {
        document.execCommand(&quot;copy&quot;);
      });

(Firefox, Chrome, Opera, and IE/Edge all trigger the copy event even when there is no selection.)</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>