0

I am making a Chrome extension to remove the about tab on the scratch homepage. The executeScript function isn't working. Manifest:

{
  "manifest_version": 2,

  "name": "Scrap",
  "description": "Modifies scratch",
  "version": "1.0",
  "icons": { "19": "icon.png",
            "128": "128icon.png" },
  "browser_action": {
  "default_icon": "icon.png"
  },
  "permissions": [
    "tabs", "<all_urls>", "activeTab"
  ],
  "content_scripts": [
    {
      "matches": ["https://scratch.mit.edu/*"],
      "js": ["background.js"]
    }
  ]
}

background.js

chrome.tabs.executeScript(null, {
    code: 'getElementsByClassName("link about").innerHTML = ""'//this line not working
});
Makyen
  • 31,849
  • 12
  • 86
  • 121
chexbox
  • 28
  • 7
  • 1
    Define "not working" – Joe Niland Mar 07 '17 at 01:38
  • It is a bad idea to call a content script "background". It confuses the issue as to the context in which the script is running for anyone readong your code. – Makyen Mar 07 '17 at 05:27
  • What *exactly* is shown in the [various appropriate consoles for your extension](http://stackoverflow.com/a/38920982/3773011) when you load and execute your extension? – Makyen Mar 07 '17 at 05:27
  • I suggest you read the [Chrome extension overview](https://developer.chrome.com/extensions/overview) (perhaps along with the pages linked from the overview). The [architecture section](https://developer.chrome.com/extensions/overview#arch) has overall architecture information which should help your understanding of how things are generally organized/done. – Makyen Mar 07 '17 at 05:29

1 Answers1

1

I think you have a problem with the script you're trying to run.

"getElementsByClassName" works on a certain object, "document", for example.

Moreover, this method returns an array of elements, so ".innerHTML" will not work since you need to specify which of the elements' innerHTML you're looking for.

If you want to have a piece of code that works, just to understand what I mean, try:

document.getElementsByClassName("link about")[0].innerHTML = ""
yarinsn
  • 78
  • 8