caniuse icon indicating copy to clipboard operation
caniuse copied to clipboard

Safari iOS does support clipboard read

Open foolip opened this issue 1 year ago • 0 comments

https://caniuse.com/async-clipboard treats Safari iOS support as partial with the note "Supports writing to clipboard but not reading." This was added in https://github.com/Fyrd/caniuse/commit/be0e5093a419a89f2918be50d0e2d2b94112394d and I can't find any discussion related to it.

In some testing I find that Safari iOS does support reading from the clipboard, i.e. pasting into the web site. The commit message of https://github.com/WebKit/WebKit/commit/a1d6921df0793765bf78a1876b83ba7f453b0052 explains how it works:

In order to make it possible for web pages to programmatically paste without opening the door to privacy and security issues, we make paste commands triggered from bindings present platform UI on iOS, in the form of a callout bar with the single option to paste. This UI is dismissed upon any user interaction; furthermore, any user interaction short of explicitly triggering the "Paste" action subsequently prevents the page from executing the paste (and causes execCommand to return false). However, if the paste action is chosen by the user, we instead follow through with the programmatic paste command.

That was about document.execCommand('Paste') at the time, but testing navigator.clipboard.readText() I saw the same callout bar, so I think the same rules are used there.

I don't know which version of Safari introduced this or exactly what the rules are. @whsieh @rniwa from that WebKit review might know more.

Ideally the note should say what developers needs to know. Mentioning the callout bar would make sense, I think.

foolip avatar Jul 10 '24 11:07 foolip