views:

55

answers:

2

I'm developing a "content script" Chrome extension. I'm trying to use a CSS files to style some existing elements on a page and to style elements that I create dynamically with JavaScript.

I've specified my CSS file in the manifest.json file:

{
    ...
    "content_scripts": [
        {
            "matches": [ ... ],
            "js": [ ... ],
            "css": [ "style.css" ]
        }
    ]
    ...
}

And then if I put something like below into my style.css nothing happens:

body {
    background-color: red;
}

I've also put some rules in the form of:

#MyInsertedEl {
    color: red;
}

And then inserted (using jQuery) a element with the id of MyInsertedEl (anchor link) into the page but it's colour is not red (the element is inserted and visible in the page).

So what gives? What am I doing wrong? According to the docs I've got everything as I should, and google does not return anything useful.

edit: this code is run on facebook's pages if that is relevant in any way ...

A: 

Is your javascript getting injected (match rule is correct)? Try adding !important to your css rules:

color: red !important;
serg
The rule is correct. JS files under the same rule are executing. !important does not help.
Jan Hančič
@Jan have you tried to open debug console and inspect your element to see what kind of stylesheets are applied to it? Extensions's css should be displayed in "user stylesheet" section.
serg
@serg no styles are applied (apart from what the page defines) and there is no "user stylesheet" section :\
Jan Hančič
+1  A: 

Well, apparently, there's a bug in Chrome. If you have a ? in your matches expression CSS files will not be loaded. I've filed a bug report with more details here.

Jan Hančič