Copying asynchronous text

The Clipboard API spec says in 5.3.1:

Event handlers may write to the clipboard if any of the following is true:

  • The action which triggers the event is invoked from the user-agent’s own user interface, e.g. from a “Copy” menu entry or shortcut key.
  • The action which triggers the event is invoked from a scripting thread which is allowed to show a popup.

You are hitting the second case. The part for “allowed to show a popup” is not very easy to understand, but I follow from that that it definitely needs to be triggered from inside the trusted handler.

This basically makes sure that scripts on a website can’t just copy arbitrary content to the system clipboard. I might have misunderstood something from the spec, but I’m quite confident this is why this is the case. Hope this helps.

What use case do you have specifically that you can’t use a button with a click handler?