<html>
<head>
<base href="https://bugs.webkit.org/" />
</head>
<body>
<p>
<div>
<b><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#c4">Comment # 4</a>
on <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">bug 156529</a>
from <span class="vcard"><a class="email" href="mailto:lgarron@chromium.org" title="Lucas Garron <lgarron@chromium.org>"> <span class="fn">Lucas Garron</span></a>
</span></b>
<pre>Gentle ping. :-)
Since this shipped with Safari 10, I had to add the following workaround to my clipboard shim library [1]:
// Workaround for Safari: <a class="bz_bug_link
bz_status_NEW "
title="NEW - document.execCommand("copy") only triggers if there is a selection."
href="show_bug.cgi?id=156529">https://bugs.webkit.org/show_bug.cgi?id=156529</a>
function bogusSelect() {
var sel = document.getSelection();
// If "nothing" is selected...
if (!document.queryCommandEnabled("copy") && sel.isCollapsed) {
// ... temporarily select the entire body.
//
// We select the entire body because:
// - it's guaranteed to exist,
// - it works (unlike, say, document.head, or phantom element that is
// not inserted into the DOM),
// - it doesn't seem to flicker (due to the synchronous copy event), and
// - it avoids modifying the DOM (can trigger mutation observers).
//
// Because we can't do proper feature detection (we already checked
// document.queryCommandEnabled("copy") , which actually gives a false
// negative for Blink when nothing is selected) and UA sniffing is not
// reliable (a lot of UA strings contain "Safari"), this will also
// happen for some browsers other than Safari. :-()
var range = document.createRange();
range.selectNodeContents(document.body);
sel.addRange(range);
_bogusSelection = true;
}
};
This feels very fragile. :-(
[1] <a href="https://github.com/lgarron/clipboard.js">https://github.com/lgarron/clipboard.js</a></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>