I'm trying to inject a font-face into pages using the page-mod module in Firefox Addon SDK. Here is the string I've constructed:
var fontString = "@font-face{" +
"font-family:'Glyphicons Halflings';" +
"src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + ");" +
"src:url(" + data.url('fonts/glyphicons-halflings-regular.eot') + "?#iefix) format('embedded-opentype')," +
"url(" + data.url('fonts/glyphicons-halflings-regular.woff') + ") format('woff')," +
"url(" + data.url('fonts/glyphicons-halflings-regular.ttf') + ") format('truetype')," +
"url(" + data.url('fonts/glyphicons-halflings-regular.svg') + "#glyphicons-halflingsregular) format('svg');}";
and I log the string to console after it's created and it outputs:
@font-face{font-family:'Glyphicons Halflings';src:url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.eot);src:url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.eot?#iefix) format('embedded-opentype'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.woff) format('woff'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.ttf) format('truetype'),url(resource://jid1-sqpdj54n2pcvoq-at-jetpack/firefoxaddon/data/fonts/glyphicons-halflings-regular.svg#glyphicons-halflingsregular) format('svg');}
I've tested that this output CSS works by copy and pasting it into a panel page and it works fine. The resources urls are correct. However, when I try and inject it into other pages as a contentStyle rule the page doesn't recognize the font. Here is my code:
require("sdk/page-mod").PageMod({
include: "*",
contentScriptFile: [...],
contentStyle: fontString,
onAttach: function (worker) {
console.log('Attached');
}
});
I've verified that onAttach
is being called after each page loads. Also, all the scripts that I am injecting with the same page mod (I didn't include them in the code snippet for brevity) are being injected and work fine. Also, if I change fontString
to something simple like body{background-color:red;}
it also works fine. Why doesn't the page recognize the font?