-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to use custom font on startup, often shows the browser's default font #15
Comments
derolf
changed the title
Trying to use Robot on startup, often it shows the browser default font
Trying to use custom font on startup, often shows the browser's default font
Aug 16, 2021
Possible solution from https://stackoverflow.com/a/64192936: export async function waitForFontLoad(
font: string,
timeout = 1000,
interval = 10
) {
return new Promise((resolve, reject) => {
// repeatedly poll check
const poller = setInterval(async () => {
try {
await document.fonts.load(font);
} catch (err) {
reject(err);
}
if (document.fonts.check(font)) {
clearInterval(poller);
resolve(true);
}
}, interval);
setTimeout(() => clearInterval(poller), timeout);
});
} |
Recommendation to use document.fonts.onloadingdone instead. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am loading the
Roboto
font inindex.html
:Then trying to use it in a
TextSprite
:Sometimes, the
TextSprite
renders the browser's default font instead ofRoboto
. Any idea to safely wait forRoboto
?The text was updated successfully, but these errors were encountered: