0

I am writing a Chrome Extensions for reddit.com and would like to read the contents of a CSS file that website has already loaded.

In my research I've come across two methods:

  1. document.styleSheets

When I console.log( document.styleSheets ) however, the "cssRules" and "rules" are both "null" for some reason, however if I load the css file url in the browser, there are plenty of rules:

https://b.thumbs.redditmedia.com/qFTJmHhu1fP0DVZHvATz60WXl-MhvSmCFoByN26OkoU.css

As you can see though, the css is hosted at redditmedia.com, so is this a cross-domain issue?

  1. $.get

When I try to do an ajax call to read the contents of the file, it's giving me a "No 'Access-Control-Allow-Origin' header is present" message, which makes sense. It's hosted at a different domain.

Is there any way I can get the contents of this file?

Thanks for your help!

TyGoss
  • 157
  • 1
  • 1
  • 7
  • 1
    possible duplicate of [Accessing cross-domain style sheet with .cssRules](http://stackoverflow.com/questions/3211536/accessing-cross-domain-style-sheet-with-cssrules) – wOxxOm Sep 08 '15 at 14:48

1 Answers1

0

So I ended up using an ajax call to my server which does a file_get_contents() on the css file, and pass the contents back.

TyGoss
  • 157
  • 1
  • 1
  • 7