I want to use navigator.clipboard.writeText to copy a link to the clipboard. However, this link must be generated by the server, which is why copying is preceded by a fetch.
Sample code:
<button onclick="onClick()">Copy</button>
<script>
    function onClick() {
        fetchLink()
            .then(function (link) {
                navigator.clipboard.writeText(link);
                alert('Copy ok');
            })
            .catch(function (err) {
                alert('Error: ' + err.message);
            })
    }
</script>
For this reason, copying does not currently seem to work, especially under iOS, since the function is not called directly by the user in an event handler.
How could I solve this problem?
Many Thanks
 
    