Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fonts not working in chrome extension

I'm 99.9% certain I have this right, but for some reason it isn't working.

I'm making a chrome extension that injects CSS onto a page, and my CSS has been working fine right up until I wanted to change the fonts.

So my manifest has this...

"css": ["css/my-custom.css"],
"js": [ "js/jquery.js", "js/my-custom.js", "js/jquery.cookie.js"],
"web_accessible_resources": ["css/my-custom.css", "fonts/Roboto-Regular.ttf", "images/*.*"]

...and my CSS has this...

@font-face {
    font-family: 'RobotoLtRegular';
    src: url('chrome-extension://__MSG_@@extension_id__/fonts/Roboto-Regular.ttf');
    font-weight: normal;
    font-style: normal;
}

body {
    background: #f1f1f1 !important;
    font-size: 1.2em !important;
    font-family: RobotoLtRegular !important;
}

p {
    font-family: RobotoLtRegular !important;
}

...and yet when I reload my extension I don't see the new font. The chrome element inspector also shows that this font should be the one shown on body and p (there are no other fonts overriding RobotoLtRegular.

FYI my fonts are stored in the css directory of the extension, so the path is correct.

I'm at a complete loss.

Any suggestions would be helpful.

UPDATE: If it helps to know, I am loading it as an unpacked extension.

like image 779
User_FTW Avatar asked Sep 27 '15 01:09

User_FTW


People also ask

Why is my font messed up in Chrome?

Go to Control Panel > Appearance and Personalization > Display > Adjust ClearType text (on the left). Check the box entitled “Turn on ClearType.” After going through a short wizard, this will fix some of the text rendering issues in Chrome. Enable "Disable accelerated 2D Canvas" in Chrome.

Is there a Chrome extension for fonts?

With over one million downloads on the Chrome Web Store, you just can't go wrong with WhatFont. The extension does what it does best, which is to identify fonts quickly and efficiently. Just click on the WhatFont extension icon, and point the cursor at a word.

How do I fix Chrome extensions not working?

Head to More tools > Extensions. Use the toggle for each extension to turn it off. Restart Chrome and go back to the extensions list. Re-enable the extensions.


1 Answers

The solution was to add web_accessible_resources into the manifest (works for manifest version 2):

"web_accessible_resources": ["*.ttf" ]

To include any other file types you can comma separate them as such:

"web_accessible_resources": [ "*.png", "*.ttf" ]

Works perfectly.

like image 64
User_FTW Avatar answered Nov 21 '22 22:11

User_FTW