I have a chrome extension. Its code has a method getSelectionFromPage()
which catches the text selected on the webpage and always returns true
like below:
function getSelectionFromPage() {
window.selected = true;
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, function(selection) {
if (selection[0] != '') {
window.selected = true;
}else{
window.selected = false;
}
});
return true
}
On the same window context, I ran the following commands on the console.
The result can be seen as follows:
I am writing the same commands here also:
getSelectionFromPage() //-> true
window.selected //-> false
(getSelectionFromPage() && window.selected) //-> true
The (getSelectionFromPage() && window.selected)
should be false
. I have tried checking typeof(window.selected)
and typeof(getSelectionFromPage())
and both are returning boolean
. I don't understand why it is happening.