I'm messing around with chrome extensions, and I'm trying to inject some JS into the page. (I want to, for example, make the main page popup a box saying something). Here's my JS file:
//Function to be called:
function setText() {
var text = document.getElementById("titleinput").value;
var myCode="alert('Test');";
chrome.tabs.executeScript(null, {code:myCode});
}
//Makes it run above code when a button is pressed:
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('button').addEventListener('click', setText);
});
And here's my manifest file:
{
"name": "Tester",
"version": "1.0",
"manifest_version": 2,
"description": "description",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
]
}
I know the setText() is being called (I tried putting an alert directly in there), but for some reason the main page isnt making a popup saying 'Test' like it should. What am I doing wrong?