[Webkit-unassigned] [Bug 156529] document.execCommand("copy") only triggers if there is a selection.
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Fri Sep 23 14:15:45 PDT 2016
https://bugs.webkit.org/show_bug.cgi?id=156529
--- Comment #4 from Lucas Garron <lgarron at chromium.org> ---
Gentle ping. :-)
Since this shipped with Safari 10, I had to add the following workaround to my clipboard shim library [1]:
// Workaround for Safari: https://bugs.webkit.org/show_bug.cgi?id=156529
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] https://github.com/lgarron/clipboard.js
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20160923/5c216122/attachment.html>
More information about the webkit-unassigned
mailing list