2

Recently I decided to write a very simple Google Chrome extension. All it's going to do is to hide some DOM-elements from the web-page using JavaScript when user presses the extension's button.

Since I knew nothing about Chrome extensions, I started reading tutorials, and I came across this Google's sample: A browser action with no icon that makes the page red

This sample is really close to what I want to make. The problem is that I can't make it work. Whenever I load the extension in Chrome, I can see the button of this extension, but when I press it - nothing happens. Sample doesn't work, probably I should know something I don't know yet.

And before you started asking me:

  • Yes, I tried restarting the browser;
  • I use the newest version of Chrome.

Thanks for help.

2 Answers2

5

If you open up the sample zip... find backgrond.js... edit. Find the line that says:

null, {code:"document.body.style.background='red !important'"});

and remove the "!important". so it should read:

null, {code:"document.body.style.background='red'"});

That is it. just save and reload the extension, should work (unless the page has an !important flag set to the background).

I am afraid I don't know why the "!important" tag doesn't work but I have never been able to get it to work in an extension. Hopefully someone else here will be able to give an explanation and maybe a work around.

Gravitate
  • 2,885
  • 2
  • 21
  • 37
0

I think I can help bring some clarification to the "!important" override attribute causing the extension to break. Though I am not 100% I believe that this attribute is not allowed for issues involving security complications. I have a link to another SO thread that may help clarify this as well.

My CSS is not getting injected through my content script

I'm assuming from reading this article that you must either use the !important override when content scripts specified in the manifest file. Otherwise if the css is being injected !important is not required. Again not 100% on this.

Community
  • 1
  • 1