Domain exclusion from content_scripts in manifest.json not working for CSS files?

I want to write a chrome extension to force all websites to use this CSS style except the Gmail page. However, the following code from the content scripts in manifest.jsondoes not work (the Gmail page will still use the style specified in font.css).

"content_scripts":  [{
    "matches":  ["http://*/*", "https://*/*"],
    "exclude_matches": ["*://mail.google.com/*"],
    "css":  ["font.css"]
}]

This cannot be fixed even when using the strategy here , replacing exclude_matcheswith exclude_globs.

I know this error, existing for some time, the so-called Error No. 100106 . Any idea on how to fix this? Or are there alternative ways that I can use to achieve my goal?

0
source share
1 answer

You can filter the pages manually if you inject CSS from some JavaScript content code. I just did a quick test and the following works on Chrome 31.0.1650.63:

manifest.json:

{
    "manifest_version": 2,
    "name": "My Style",
    "description": "Insert custom CSS",
    "version": "0.1",
    "content_scripts": [{
        "matches":  ["http://*/*", "https://*/*"],
        "js": ["font.js"],
        "run_at":"document_start"
    }],
    "web_accessible_resources": ["font.css"]
}

font.js

if (location.hostname.indexOf(".google.com") == -1) {
    var link = document.createElement("link");
    link.href = chrome.extension.getURL("font.css");
    link.type = "text/css";
    link.rel = "stylesheet";
    document.documentElement.insertBefore(link);
}

font.css

body {
    color: red;
}

Thus, the font.css script is entered on all pages other than Google.

+1
source

All Articles