Pasting custom text using the new clipboard API

Hi Guys,

I’m trying to intercept the paste event and update the clipboard text using navigator.clipboard.writeText(). But it is not pasting the updated text. I have tried a lot of ways but the result it is same. it seems like even though the clipboard is updating, it is pasting the old text. I provided the code I’m using below. Any help would be highly appreaciated. Thank you

handlePaste = async (event) => {
if(!this.haveClipboardAccess) {
event.preventDefault();
event.stopPropagation();
} else {
event.preventDefault();
try {
await navigator.clipboard.writeText(this.clipboard);
const updatedClipboard = await navigator.clipboard.readText();
console.log(“updated clipboard”, updatedClipboard);
return true;
} catch (err) {
console.error(“Can’t access clipboard.”,err);
event.preventDefault();
event.stopPropagation();
}
}
}