I have this chrome script which works fine in my extension:
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, function(selection) {
document.getElementById("output").innerHTML = selection[0];
});
But for some reason, why I try to make a function out of it, it just returns undefined.
/**
* returns currently highlighted text
*/
function get_highlighted() {
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, function(selection) {
return selection[0];
});
}
// var to hold highlighted text
highlighted_text = get_highlighted();
// update HTML with highlighted text
document.getElementById("output").innerHTML = highlighted_text;
I'm having trouble debugging since no error is coming up in chrome://extensions and the console doesn't log an error.