How can I use writeText() and readText() to copy and paste text throughout browsers using my Chrome Extension?

102 views Asked by At
Im trying to create a Chrome extension that's main purpose is to copy and paste text, without using the standard ctrl C and V. Im trying to use writeText() to copy the text into my clipboard which works for the most part. But the issue lies when I try and use readText() to paste that text. When I try writing a line of code using it like, navigator.clipboard.writeText(text); nothing happens (text being the text saved on my clipboard which works).
let text = '';

try{
    text = await navigator.clipboard.readText();
}
catch (err) {
    console.error('Could not read from clipboard', err);
}
if (text) {
    navigator.clipboard.writeText(text);
    alert(text);
}

I've tried everything I could find with no solution, I just need it to paste my clipboard. Using a different method is fine I just need a solution of any kind.

0

There are 0 answers