Read clipboard data in Safari using javascript

I am trying to read clipboard data using event.clipboardData.getData('Text') or window.clipboardData.getData('Text').

When I tried manually triggering ctrl+v I was able to access the data using event.clipboardData.getText(), but when I programatically trigger paste event it did not work.


I want a solution where the getData should work without user intervention, provided the user is asked for permission before accessing clipboard, the way it happens in Chrome for navigator.cliboard.readText().

Replies

In the current implementation, user interaction is necessary for clipboard access. When you programmatically triggering the paste, is this under an event (such as click, touchstart, mousedown, etc.)? If so, on Safari 13.1 and later, a "Paste" context menu action should show up, prompting the user to proceed with the paste.

The newer async clipboard APIs in WebKit work the same way — you can read more about it here: https://webkit.org/blog/10855/async-clipboard-api/