I was wondering what is the easiest way to get selected text from tab and put string into a variable
My Popup html code
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button id="clickme">click me</button>
<canvas id="myCanvas" width="300" height="300"></canvas>
<textarea id="output"> </textarea>
<script src = "popup.js"></script>
</body>
</html>
My javaScript
chrome.tabs.executeScript( {
code: "window.getSelection().toString();"
}, function(selection) {
document.getElementById("output").value = selection[0];
});
I tried this but got an error
*
Error in response to tabs.executeScript: TypeError: Cannot read property '0' of undefined at Object.callback (chrome-extension://nnhcblfafgjjoolcnjckidjgjcmmgnlp/popup.js:4:54) at chrome-extension://nnhcblfafgjjoolcnjckidjgjcmmgnlp/popup.js:1:13
*