<html>
    <head>
      <base href="https://bugs.webkit.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Can not create custom pasteboard types in clipboardData.setData"
   href="https://bugs.webkit.org/show_bug.cgi?id=184271">184271</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Can not create custom pasteboard types in clipboardData.setData
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>Safari 11
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>iPhone / iPad
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>iOS 11
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>WebCore JavaScript
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned@lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>ccorcos@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>It appears that in iOS, only a limited set of pasteboard types are allowed. See the supportedWebContentPasteboardTypes method inside <a href="https://opensource.apple.com/source/WebCore/WebCore-7604.1.38.0.7/platform/ios/PasteboardIOS.mm.auto.html">https://opensource.apple.com/source/WebCore/WebCore-7604.1.38.0.7/platform/ios/PasteboardIOS.mm.auto.html</a>

Whereas on desktop, you can create whatever pasteboard types that you want.

This is very important in rich text applications that rely on copy-paste of structured content that needs to be treated differently when pasting inside the application vs outside the application.

I've created a simple demonstration of this in a CodePen which you can open in iOS Safari and I've copied the source code below: <a href="https://codepen.io/ccorcos/pen/KooVZB?editors=1010">https://codepen.io/ccorcos/pen/KooVZB?editors=1010</a>

When you create a selection in the contenteditable input and select copy, we save some structured information in a custom pasteboard type, and when we paste, we parse it back out. This works fine in desktop Safari, but does not work on iOS.

```html

<div id="input" contenteditable>Hello world</div>

```


```js

const input = document.getElementById("input")

window.addEventListener("copy", event => {
  event.preventDefault()
  const data = JSON.stringify({data: input.textContent})
  console.log("copy", data)
  event.clipboardData.setData("app/custom-key", data)
})

window.addEventListener("paste", event => {
  event.preventDefault()
  console.log(event)
  const data = event.clipboardData.getData("app/custom-key")
  console.log("pasteData", data)
  if (!data) {
    console.log("no data")
    return
  }
  const result = JSON.parse(data)
  input.innerHTML = result.data
})

```</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>