Skip to content

Instantly share code, notes, and snippets.

@Nooshu
Created February 23, 2020 03:32
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Nooshu/c0c6dbeaad55a438ec30849bf8be1d96 to your computer and use it in GitHub Desktop.
Simplified script for injecting fonts into WebPageTest
(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