Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-136029

navigator.clipboard.write() API doesn't work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.8, 6.9
    • WebEngine
    • None

    Description

      The `window.navigator.clipboard.write()` API seems to fail with the error NotAllowedError: Failed to execute 'write' on 'Clipboard': Invalid Blob types., at least for text/plain.

      https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write

      You can test this in the wild on discord.com (account required) by selecting "Copy Text" from the three dot menu from a text message in a channel.

      Edit: discord has switched back to using writeText() now

      Here's a test script:

      <script type='text/javascript'>
      function copy(text) {
        console.log(text)
        // This doesn't work.
        // Fails with NotAllowedError: Failed to execute 'write' on 'Clipboard': Invalid Blob types.
        // But ClipboardItem.supports('text/plain') returns true!
        window.navigator.clipboard.write(
          [
            new ClipboardItem(
              {
                ["text/plain"]: text
              }
            )
          ]
        )
      }
      
      function copytext(text) {
        // This works.
        navigator.clipboard.writeText(text)
      }
      </script>
      <div onclick="copy('Text One')">Text One</div>
      <div onclick="copy('Text Two')">Text Two</div>
      <div onclick="copytext('Text writeText')">Text writeText</div>
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kchehlarski Kaloyan Chehlarski
            toofar toofar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes