Just started my experimentation with Chrome extensions and got stuck at this point: chrome.tabs.executeScript will just not work!
In the Chrome error console I kept getting this error:
Error during tabs.executeScript: Cannot access contents of url “http://google.com”. Extension manifest must request permission to access this host.
I went through the documentations but, just kept missing the point. And the point is Chrome extensions need to be given explicit permission to access any piece of information whether it is tab data or web page data.
This is the manifest.json which caused the error:
{
“name”: “Gayatri Tab”,
“description”: “Gayatri Tab Tests”,
“version”: “0.1″,
“permissions”: ["tabs"],
“background_page”: “background.html”,
“browser_action”: {
“default_icon”: “testing123.png”,
“default_title”: “test tabs – gayatri”
}
}
And this is the manifest.json that works!
{
“name”: “Gayatri Tab”,
“description”: “Gayatri Tab Tests”,
“version”: “0.1″,
“permissions”: ["tabs", "http://*/", "https://*/"],
“background_page”: “background.html”,
“browser_action”: {
“default_icon”: “testing123.png”,
“default_title”: “test tabs – gayatri”
}
}
See the areas marked yellow. In the working manifest.json we have explicitly given the extension permission to “http://” and “https”//” content.
This is the complete test extension:
manifest.json
{
“name”: “Gayatri Tab”,
“description”: “Gayatri Tab Tests”,
“version”: “0.1″,
“permissions”: ["tabs", "http://*/", "https://*/"],
“background_page”: “background.html”,
“browser_action”: {
“default_icon”: “testing123.png”,
“default_title”: “test tabs – gayatri”
}
}
background.html
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
alert(tab.id + ‘: ‘ + tab.url);
chrome.tabs.executeScript(tab.id, {file: ‘myscripts.js’});
});
</script>
myscripts.js
function myname()
{
alert(‘hello’);
}
myname();







