[Webkit-unassigned] [Bug 177715] New: clipboardData.setData() fails on iOS with certain kind of selections.
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Sat Sep 30 23:28:32 PDT 2017
https://bugs.webkit.org/show_bug.cgi?id=177715
Bug ID: 177715
Summary: clipboardData.setData() fails on iOS with certain kind
of selections.
Product: WebKit
Version: Safari 11
Hardware: iPhone / iPad
OS: iOS 11
Status: NEW
Severity: Normal
Priority: P2
Component: HTML Editing
Assignee: webkit-unassigned at lists.webkit.org
Reporter: lgarron at chromium.org
CC: wenson_hsieh at apple.com
As documented in https://bugs.webkit.org/show_bug.cgi?id=156529 , Safari doesn't allow document.execCommand("copy") when there is no selection.
It is possible work around this but by creating a temporary selection: https://bugs.webkit.org/show_bug.cgi?id=156529#c4
However, this workaround is broken on iOS. After the temporary selection is selected, document.queryCommandEnabled("copy") returns true and a function registered using document.addEventListener("copy", ...) fires. *However*, `event.clipboardData.setData()` has no effect.
Consider the following sample:
<script>
document.addEventListener("copy", function(e) {
e.clipboardData.setData("text/plain", "This is plain text.");
console.log(e.clipboardData.getData("text/plain"));
e.preventDefault();
});
function copy() {
var sel = document.getSelection();
var range = document.createRange();
range.selectNodeContents(document.body);
sel.removeAllRanges();
sel.addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
}
</script>
<button onclick='copy()'>Copy text (plain)</button>
The `console.log(...)` line prints "This is plain text." on desktop Safari, but a blank string on iOS.
Consequently, the clipboard is emptied (even if it contained something before).
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20171001/4ac1ccac/attachment-0001.html>
More information about the webkit-unassigned
mailing list