<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>177715</bug_id>
          
          <creation_ts>2017-09-30 23:28:32 -0700</creation_ts>
          <short_desc>clipboardData.setData() fails on iOS with certain kind of selections.</short_desc>
          <delta_ts>2017-10-31 01:14:46 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>HTML Editing</component>
          <version>Safari 11</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 11</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Lucas Garron">lgarron</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>rniwa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1354979</commentid>
    <comment_count>0</comment_count>
    <who name="Lucas Garron">lgarron</who>
    <bug_when>2017-09-30 23:28:32 -0700</bug_when>
    <thetext>As documented in https://bugs.webkit.org/show_bug.cgi?id=156529 , Safari doesn&apos;t allow document.execCommand(&quot;copy&quot;) 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(&quot;copy&quot;) returns true and a function registered using document.addEventListener(&quot;copy&quot;, ...) fires. *However*, `event.clipboardData.setData()` has no effect.

Consider the following sample:

    &lt;script&gt;
    document.addEventListener(&quot;copy&quot;, function(e) {
      e.clipboardData.setData(&quot;text/plain&quot;, &quot;This is plain text.&quot;);
      console.log(e.clipboardData.getData(&quot;text/plain&quot;));
      e.preventDefault();
    });

    function copy() {
      var sel = document.getSelection();
      var range = document.createRange();
      range.selectNodeContents(document.body);
      sel.removeAllRanges();
      sel.addRange(range);
      document.execCommand(&quot;copy&quot;);
      window.getSelection().removeAllRanges();
    }
    &lt;/script&gt;
    &lt;button onclick=&apos;copy()&apos;&gt;Copy text (plain)&lt;/button&gt;

The `console.log(...)` line prints &quot;This is plain text.&quot; on desktop Safari, but a blank string on iOS.
Consequently, the clipboard is emptied (even if it contained something before).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1354980</commentid>
    <comment_count>1</comment_count>
    <who name="Wenson Hsieh">wenson_hsieh</who>
    <bug_when>2017-09-30 23:35:27 -0700</bug_when>
    <thetext>(In reply to Lucas Garron from comment #0)
&gt; As documented in https://bugs.webkit.org/show_bug.cgi?id=156529 , Safari
&gt; doesn&apos;t allow document.execCommand(&quot;copy&quot;) when there is no selection.
&gt; It is possible work around this but by creating a temporary selection:
&gt; https://bugs.webkit.org/show_bug.cgi?id=156529#c4
&gt; 
&gt; However, this workaround is broken on iOS. After the temporary selection is
&gt; selected, document.queryCommandEnabled(&quot;copy&quot;) returns true and a function
&gt; registered using document.addEventListener(&quot;copy&quot;, ...) fires. *However*,
&gt; `event.clipboardData.setData()` has no effect.
&gt; 
&gt; Consider the following sample:
&gt; 
&gt;     &lt;script&gt;
&gt;     document.addEventListener(&quot;copy&quot;, function(e) {
&gt;       e.clipboardData.setData(&quot;text/plain&quot;, &quot;This is plain text.&quot;);
&gt;       console.log(e.clipboardData.getData(&quot;text/plain&quot;));
&gt;       e.preventDefault();
&gt;     });
&gt; 
&gt;     function copy() {
&gt;       var sel = document.getSelection();
&gt;       var range = document.createRange();
&gt;       range.selectNodeContents(document.body);
&gt;       sel.removeAllRanges();
&gt;       sel.addRange(range);
&gt;       document.execCommand(&quot;copy&quot;);
&gt;       window.getSelection().removeAllRanges();
&gt;     }
&gt;     &lt;/script&gt;
&gt;     &lt;button onclick=&apos;copy()&apos;&gt;Copy text (plain)&lt;/button&gt;
&gt; 
&gt; The `console.log(...)` line prints &quot;This is plain text.&quot; on desktop Safari,
&gt; but a blank string on iOS.
&gt; Consequently, the clipboard is emptied (even if it contained something
&gt; before).

This is working for me using ToT WebKit, on iOS 11.

I&apos;m pretty sure Ryosuke and I fixed this with recent work around enhanced pasteboard/DataTransfer support in WebKit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1354981</commentid>
    <comment_count>2</comment_count>
    <who name="Wenson Hsieh">wenson_hsieh</who>
    <bug_when>2017-09-30 23:39:01 -0700</bug_when>
    <thetext>&gt; This is working for me using ToT WebKit, on iOS 11.
&gt; 
&gt; I&apos;m pretty sure Ryosuke and I fixed this with recent work around enhanced
&gt; pasteboard/DataTransfer support in WebKit.

...more specifically: &lt;https://trac.webkit.org/changeset/222228/webkit&gt;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355280</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2017-10-02 10:20:18 -0700</bug_when>
    <thetext>Marking resolved per the above comment.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1355281</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2017-10-02 10:20:55 -0700</bug_when>
    <thetext>&lt;rdar://problem/34769566&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1363810</commentid>
    <comment_count>5</comment_count>
    <who name="Lucas Garron">lgarron</who>
    <bug_when>2017-10-24 12:33:26 -0700</bug_when>
    <thetext>Thanks for the response!

Is there a way for me to test the latest behaviour on a (non-beta) iOS device?

Thanks,
»Lucas</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1366343</commentid>
    <comment_count>6</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2017-10-31 01:14:46 -0700</bug_when>
    <thetext>(In reply to Lucas Garron from comment #5)
&gt; Thanks for the response!
&gt; 
&gt; Is there a way for me to test the latest behaviour on a (non-beta) iOS
&gt; device?

You&apos;d have to build WebKit&apos;s iOS port on iOS simulator. Follow instructions on https://github.com/WebKit/webkit</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>