Я разработал плагин для Firefox, у которого есть файл manifest.json, присоединенный к файлу javascript.который запускает поиск по выбору текста и правой кнопкой мыши.Мне нужно скопировать выбранный текст.
console.log("hello hi")
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
function handleRightClick(click_event) {
if (getSelectionText() !== "") {
console.log(JSON.stringify(click_event, null, 4))
click_event.preventDefault()
console.log("selection text: "+getSelectionText())
var base_url1 = "https://www.google.com/search?safe=off&hl=en&source=hp&ei=s0b9W4PmIIaCyAOZwrawAw&q="+getSelectionText().replace(" ","+")
window.open(base_url1, 'ab');
}
}
document.addEventListener('contextmenu', event => handleRightClick(event));
Теперь, как это реализовать >> document.execCommand ("copy");я получаю ошибку в Firefox