cssRules/rules are null in Chrome

前端 未结 2 946
一整个雨季
一整个雨季 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条回答
  • 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";
    
    0 讨论(0)
  • 2020-12-09 09:19

    I fixed my version of the issue by changing the url from http:// to https://. Doh!

    0 讨论(0)
提交回复
热议问题