I am trying out a simple chrome extension where I select some text and press the button and the selected term is googled.
Below is my background.html
<script>
function Req() {
var str=document.getSelection().toString(); //window.getSelection().toString() tried both
alert(str);
var Call =' http://www.google.com/search?q='+str;
alert(Call)
chrome.tabs.create({url: Call});
}
</script>
</head>
<body onload="Req()" >
</body>
</html>
Below is my manifest.json
{
"background_html":"background.html",
"name": "goog app",
"description": "googles selected term",
"browser_action": {
"default_icon": "icon.png",
"popup":"background.html"
},
"permissions": ["tabs","http://www.google.com/","https://www.google.com/"],
"version": "1.0"
}
I have tried everything but the window.getSelection().toString() does not return any value.
Please help me figure out the problem.
You have a lot of errors
"background_html":"background.html""popup":"background.html"– popup page does not have access to the content scriptsvar str=document.getSelection().toString();– you will receive selected block of the page “background.html”, but not content page