Attempting to retrieve all CSS rules using JavaScript has yielded varying results.
For instance, on StackOverflow, the code used is:
console.log(
document.styleSheets[1].href,'rules',
document.styleSheets[1].cssRules,'Should be css rules, and not null'
)
Resulting in:
http://cdn.sstatic.net/stackoverflow/all.css?v=f7d3e9ff74be rules null Should be css rules, and not null
While it works well on some websites, on others it does not function properly.
When attempting this on github.com, the output is:
https://assets-cdn.github.com/assets/github2/index-87247f16e6450ef54cb0eda3f8f1484e33a3f18c7a7d3df1f76f67cba36a8d6d.css CSSRuleList {0: CSSStyleRule, 1: CSSStyleRule, 2: CSSStyleRule, 3: CSSStyleRule, 4: CSSStyleRule, 5: CSSStyleRule, 6: CSSStyleRule, 7: CSSStyleRule, 8: CSSStyleRule, 9: CSSStyleRule, 10: CSSStyleRule, 11: CSSStyleRule, 12: CSSStyleRule, 13: CSSStyleRule, 14: CSSStyleRule, 15: CSSStyleRule, 16: CSSStyleRule, 17: CSSStyleRule, 18: CSSStyleRule, 19: CSSStyleRule, 20: CSSStyleRule, 21: CSSStyleRule, 22:
What steps can be taken to address this issue?
https://i.sstatic.net/fyl7H.png
- Initially, considering if the issue lies with content-type, but it consistently remains as text/css.
- The possibility of CORS being a concern was also explored, however, no evidence points to that being the root cause.