OK. So I've read up on content scripting and the like, including several other SO articles that I'll add below, but this still isn't working!
My _manifest.json_
:
{
"name": "name",
"version": "1.0",
"description": "desc",
"browser_action": { "default_icon": "icon.png" },
"permissions": [ "tabs", "http://*/*" ],
"background_page": "background.html",
"content_scripts": [ {
"all_frames": true,
"js": [ "content.js" ],
"matches": [ "http://*/*", "https://*/*" ]
} ]
}
My _background.html_
:
<!doctype html>
<html>
<head>
<title>Background Page</title>
<script src="jquery.min.js"></script>
<script src="content.js"></script>
</head>
<body>
<script>
chrome.browserAction.onClicked.addListener(function(tab)
{
chrome.tabs.executeScript(null, {file:"content.js"});
});
</script>
</body>
</html>
My _content.js_
:
$('body').prepend('<h1>Testing!</h1>');
$('body').css('background', '#f00 !important');
For now, I'm just trying to modify the background color of the body of a tab. I've added the click listener to run my background.html file, but it doesn't work. I've breakpointed on the script call in the background.html file when debugging and the executeScript event is hit, but my content.js file breakpoint doesn't get hit. I thought having the content.js file under the "content_scripts" in my manifest.json file was enough, but if I remove my background.html file nothing happens.
Can anyone help me modify the content of a tab in any way?! It feels like I'm missing something, because I feel like I'm making this harder than it is. If there is an easier way than what I'm trying to do, I'm open to any suggestions/best practices.