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 incur a penalty for transferring the web font over the network whenever your extension uses it, to the point of affecting the performance of my extension. Do I have any option for packaging a font with my extension that will work on all Chrome-supported platforms (Windows/Mac/etc.)? Thanks in advance
相关问题
- How does same-domain policy apply to background sc
- YouTube Data API v3 allowed referers for browser a
- Chrome Extension: How can I get global settings in
- Keep receiving Login Required error when trying to
- chrome.runtime.reload blocking the extension
相关文章
- Progressive web app(PWA) vs Electron vs Browser ex
- Can I set an Access-Control-Allow-Origin header to
- chrome.runtime.getURL vs. chrome.extension.getURL
- Will this hotkey work for Mac users?
- Chrome extension permission for “about:blank” page
- getElementById not working in Google Chrome extens
- Google Chrome extension: How to find out if a user
- How can my Chrome plugin disable itself via Javasc
Asking the user for permissions to access Google Web Fonts is far less effort than embedding them (even if this might make perfect sense for eventual off-line scenarios).
manifest.json
Choose your font. As example I'll take "Stint Ultra Expanded". There is example how to add it to your page:
Take only the
href
and open it in browser. You'll see smth like this:Take first parameter of
url
value fromsrc
property (http://themes.googleusercontent.com/static/fonts/stintultraexpanded/v1/FeigX-wDDgHMCKuhekhedWmdhyVWfbygZe-w47Q2x_f3rGVtsTkPsbDajuO5ueQw.woff).Download this file.
Use parameter of
local
value ofsrc
property as filename (Stint Ultra Expanded)Easy way is to download it is using wget:
Now create css file and add content that you have seen before. But you have to change value of
src
property. Remove alllocal
s and adjusturl
. It should be smth like this:Now add your css file to extension and use the font:
popup.html
If you would like to use this font in content_script you have to adjust
url
in your css:You can add as many
@font-face
rules in your css as you like.Notice:
local
value insrc
property tells you which name should be used to store it. It is good idea to use this name.Second notice: If you are using it like google expected, your browser would check if this font is already available local. If this is not the case, then it would be downloaded and stored. So next time it would use font that was previously stored.
As of Chrome 37 (maybe earlier), you need to mention the font as a web accessible resource in the extension's manifest:
Otherwise you would see an error like:
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.
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.