[Webkit-unassigned] [Bug 156529] New: document.execCommand("copy") only triggers if there is a selection.

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Apr 12 18:56:09 PDT 2016


https://bugs.webkit.org/show_bug.cgi?id=156529

            Bug ID: 156529
           Summary: document.execCommand("copy") only triggers if there is
                    a selection.
    Classification: Unclassified
           Product: WebKit
           Version: Safari Technology Preview
          Hardware: Macintosh
                OS: OS X 10.11
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: HTML Editing
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: lgarron at chromium.org

Safari 9.1.1 
OSX 10.11.4

1. Visit https://permission.site
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.)

-- 
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/20160413/a5eba25c/attachment.html>


More information about the webkit-unassigned mailing list