[Webkit-unassigned] [Bug 244812] New: navigator.clipboard.write() rejects with NotAllowedError after an async call

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Sep 5 08:02:11 PDT 2022


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

            Bug ID: 244812
           Summary: navigator.clipboard.write() rejects with
                    NotAllowedError after an async call
           Product: WebKit
           Version: Safari 15
          Hardware: All
                OS: iOS 15
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: DOM
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: christian at liebel.org

I'm using the Async Clipboard API (roughly) like this:

button.addEventListener('click', async () => {
  const blob = await getBlobFromSelection(context, selection);
  await navigator.clipboard.write([new ClipboardItem({
    [blob.type]: blob
  })]);
};

When the user clicks the button, the blob to copy is asynchronously resolved. (In my particular scenario, the selected part of an image gets cropped and converted to PNG.)

Expected behavior:

The blob's content should be copied to the clipboard.

Actual behavior:

The call to navigator.clipboard.write() is rejected with the following error message: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

Context:

I suspect this is related to the user gesture policy. After the asynchronous call, the call to the write() method is not seen as part of a user gesture anymore. If I omit the asynchronous call, everything works as expected. I think this scenario should be supported because certain asynchronous operations (like preprocessing images) are sometimes necessary. It's working fine in Blink.

Steps to reproduce:
- Open https://paint.js.org
- Click Edit > Select All
- Click Edit > Copy
- The error mentioned above is logged to the console. The user's drawing is not written to the clipboard.

-- 
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/20220905/b9f3dc20/attachment-0001.htm>


More information about the webkit-unassigned mailing list