Packaging a font with a Google Chrome extension

前端 未结 3 1073
后悔当初
后悔当初 2020-12-12 22:24

I want to use something other than the standard fonts with my Chrome extension. I was excited about the possibility of using the Google Web Fonts, but it seems that could i

3条回答
  •  再見小時候
    2020-12-12 23:07

    This is quite old but for anyone still having issues with this, it is possible to load the font file with javascript. I had trouble getting a font-face declaration to work within shadow dom; all styles would load but chrome would just ignore the font-face declaration completely.

    let font = new FontFace("yourFontName", "url('path/to/font/file.woff')");
    document.fonts.add(font);
    

    This works beautifully for me. Using font-face is probably preferred but I'm pretty sure my use case is a bug in chrome. Here's the spec for it.

提交回复
热议问题