In the following example, highlight and copy “this is text”. That is what should be added to the clipboard. However [object Promise] is added instead. readText() is awaited so this is the incorrect result. How do I make this work?
<html>
This is text
<script>
document.addEventListener('copy', function (e) {
var result = textCopied();
e.clipboardData.setData('text/plain', result);
e.preventDefault();
});
async function textCopied() {
var clipboardContents = await navigator.clipboard.readText();
return clipboardContents
}
</script>
</html>