I did simple example page redder as given in chrome api page example. There, they used background script to change the background color via executeScript. I don't want to do that, I want to use content script only (easier access to DOM). Here is my code: 1) manifest.json
{
"manifest_version": 2,
"name": "Modified page redder example",
"version": "1.0",
"icons": { "16": "icon_16.png",
"48": "icon_48.png",
"128": "icon_128.png" },
"permissions": [
"activeTab"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"content_scripts" : [
{
"matches" : [ "<all_urls>" ],
"js" : [ "contentscript.js" ]
}
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Load apps"
}
}
2) myscript.js
document.getElementById('btchange').onclick=function(){
chrome.runtime.sendMessage('red');
}
3) popup.html
<html>
<body>
<input type='button' value='change' id='btchange'>
<script src='myscript.js'></script>
</body>
</html>
4) contentscript.js
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse){
//chrome.tabs.executeScript({code: 'document.body.style.backgroundColor = "'+request+'"'});
alert(request);
}
);
I don't receive the result as I want. No error. No promt (by alert red).