This is probably a very beginner question, but I'm about to pull my hair out because I can't figure out what I'm doing wrong. At this point, all I'm trying to do is get the selected text to print in an alert or the console (for testing). I've made sure .toString()
method has been added to the returned Object from window.getSelection().
No matter what I do, the console and alerts display blank. Could anyone explain why?
I'm doing this in a local Chrome extension.
manifest.json
{
"manifest_version": 2,
"name":"Testing",
"version": "0.1",
"icons": {
"48":"48.png"
},
"background": {
"scripts": [ "background.js" ]
},
"permissions":[ "tabs" ],
"browser_action": {
"default_icon": { "19":"img19.png" }
}
}
JavaScript
chrome.browserAction.onClicked.addListener(function(tab) {
var selObj = window.getSelection();
var selectionText = selObj.toString();
alert(selectionText); // displays a blank alert
console.log(selectionText); // adds a blank line in the console
});
I'm learning. Thanks in advance.