0

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?

1 Answer 1

2

Make sure you are running it on a website and not chrome://extensions. You can't inject scripts into chrome://* pages. If it still isn't working use the popup debugger to look for errors.

Sign up to request clarification or add additional context in comments.

1 Comment

The popup debugger helped, got it fixed :P

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.