Why does `navigator.clipboard.writeText` not copy text to clipboard if it is proceeded by alert() on android
Because the navigator.clipboard.writeText method returns a promise and your code does not wait for its result. If you correct code as shown below then it should be fine: function myFunction() { var copyText = document.getElementById(“myInput”); copyText.select(); copyText.setSelectionRange(0, 99999); navigator.clipboard .writeText(copyText.value) .then(() => { alert(“successfully copied”); }) .catch(() => { alert(“something went wrong”); }); } For … Read more