<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("copy") 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("copy") 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@lists.webkit.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>lgarron@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 "Copy"
Expected:
The text "This text was copied from the permission.site clipboard example." 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("copy") 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("copy", function(e){
e.clipboardData.setData("text/plain", "test");
e.preventDefault();
});
var copyButton = document.createElement("button");
document.body.appendChild(copyButton);
copyButton.addEventListener("click", function() {
document.execCommand("copy");
});
(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>