Clipboard API `writeText()` fails in Safari due to User Activation API, but works in Firefox and Chrome

Hi,

I'm encountering an issue with the Clipboard API's writeText() method in Safari. It throws a NotAllowedError even when triggered by a user action (selecting an option from a <select> element). Is this expected?

This issue seems specific to Safari, as the same code works perfectly in Firefox and Chrome.

Perhaps I should send feedback to Apple, but I'd like to post it here first in case I misunderstand something.

Problem

In Safari, when I try to copy text to the clipboard using navigator.clipboard.writeText() within an input event listener attached to a <select> element, it fails with the following error:

NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

Environment

  • Safari
    • 18.2 (20620.1.16.11.8)
    • Technology Preview 210
  • macOS Sequoia 15.2 (24C101)

Example

I've created a minimal reproducible example on CodePen: https://codepen.io/mshibanami/pen/LEPdxXZ

Here's the relevant JavaScript code from the example:

selectElement.addEventListener('input', async (event) => {
  const selectedText = event.target.options[event.target.selectedIndex].text;

  try {
    await navigator.clipboard.writeText(selectedText);
    alert(`Text copied to clipboard: ${selectedText}`);
  } catch (err) {
    alert('Failed to copy text to clipboard: ' + err);
  }
});

Firefox and Chrome handle this code without any issues, successfully copying the text to the clipboard, but not Safari.

Possible Cause

I suspect this issue might be related to WebKit's User Activation API. It seems like Safari is not correctly recognizing the input or change event on a <select> element as a valid user activation for the Clipboard API, even though it is initiated by a user gesture.

Questions

Is this behavior unexpected? Should Safari allow the Clipboard API to work in this context?

(Technically, this might be expected as of now, as such events are not explicitly described in https://webkit.org/blog/13862/the-user-activation-api/.)

Any insights or suggestions would be greatly appreciated. Thanks!

Clipboard API `writeText()` fails in Safari due to User Activation API, but works in Firefox and Chrome
 
 
Q