cssRules/rules are null in Chrome

前端 未结 2 973
一整个雨季
一整个雨季 2020-12-09 08:42

My chrome extension needs to modify certain css rules on user\'s page. Accessing styles via document.styleSheets only gives access to styles linked from within

2条回答
  •  萌比男神i
    2020-12-09 09:04

    Content scripts don't have any cross-domain privileges comparing to a regular javascript, so any limitations are carried over. See related question #1, question #2.

    You can inject your own css style in the manifest:

    "content_scripts": [
        {
          "matches": ["http://www.google.com/*"],
          "css": ["mystyles.css"]
        }
    ]
    

    where you can try to overwrite original styles by defining rules with higher specificity.

    You can also just tweak concrete element styles through javascript:

    document.getElementById("id").style.property="value";
    

提交回复
热议问题