I am building a browser extension which I eventually will turn into a translator but for its current purpose I just want my extension to console log the word that is clicked on the page. I am using vanilla JS for this part:
window.addEventListener('mouseup', checkWord);
function checkWord() {
console.log('the word is')
let word = window.getSelection().toString();
console.log(word);
}
If I remove the .toString()
method the program will return the entire object to the console. However with the .toString()
method the console log gives me an empty return. Should I be using a different method to extract the actual word clicked on?