Как я могу использовать writeText() и readText() для копирования и вставки текста в браузерах с помощью моего расширения Chrome?

      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);
}

Я перепробовал все, что смог найти, но решения не нашел, мне просто нужно вставить его в буфер обмена. Использование другого метода - это нормально, мне просто нужно какое-то решение.

0 ответов

Другие вопросы по тегам