0

I'm building a chrome extension which includes a content script that is linked to a CSS file. That's my manifest file:

{
  "manifest_version": 2,
  "name": "Cool name",
  "version": "1.0",
  "permissions": [
    "http://*/*",
    "https://*/*",
  ],
  "content_scripts": [
    {
      "matches": [
        "http://*/*",
        "https://*/*"
      ],
      "js": [
        "jquery.js",
        "contentScript.js"
      ],
      "css": [
        "styles.css"
      ]
    }
  ],
  "web_accessible_resources": [
    "styles.css"
  ]
}

These are the contents of styles.css:

@import url(http://fonts.googleapis.com/css?family=Pacifico);

.testClass {
  font-family: Pacifico;
}

As you can see, i'm trying to import a google font into my CSS file. However, the font doesn't seem to get loaded, because when I try to use this font, by applying testClass to some text element using the content script, nothing changes (If I use any other standard web font it works).

May it be that chrome won't let @import to execute in the extension context?

I tried to add the following line to my manifest file:

"content_security_policy": "script-src 'self' http://fonts.googleapis.com; object-src 'self'"

But it didn't help.

What am I doing wrong?

Thanks.

gipouf
  • 1,221
  • 3
  • 15
  • 43
  • You should put `@import` at the top of the style block or else it won’t work. It turns out that avoiding `@import` is better for performance, too. Instead of that using `` tag over `@import`. http://www.stevesouders.com/blog/2009/04/09/dont-use-import/ – Dayton Wang May 29 '15 at 16:47
  • It is atthe top of the style block... or am i missing something? – gipouf May 29 '15 at 16:49
  • 1
    possible duplicate of [How to load google fonts into chrome packaged apps without download?](http://stackoverflow.com/questions/19991814/how-to-load-google-fonts-into-chrome-packaged-apps-without-download) – Blaise May 29 '15 at 16:56
  • 1
    Have you tried of changing the `@import` to use `https` or `//` instead of `http` or using `` – Dayton Wang May 29 '15 at 17:00

0 Answers0