Created
February 23, 2020 03:32
-
-
Save Nooshu/c0c6dbeaad55a438ec30849bf8be1d96 to your computer and use it in GitHub Desktop.
Simplified script for injecting fonts into WebPageTest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// this will trigger a font load | |
var customFont1 = new FontFace('custom font name', 'url([FONT_URL_HERE])', { | |
display: 'block', // display setting to test here | |
weight: '700' // font-weight | |
// other font properties here | |
}); | |
// IMPORTANT: add the font to the document | |
document.fonts.add(customFont1); | |
// monitor the font load (optional) | |
customFont1.loaded.then((fontFace) => { | |
// log some info in the console | |
console.info('Font status:', customFont1.status); // optional | |
// log some info on the WPT waterfall chart | |
performance.mark('wpt.customFont1Loaded'); // optional | |
}, (fontFace) => { | |
// if there's an error, tell us about it | |
console.error('Font status:', customFont1.status); // optional | |
}); | |
// repeat above for multiple fonts | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment