Can I tell when a font has been successfully (or otherwise) loaded, and then act on that with JS?
Context
I'm printing a series of documents using playwright. I'm currently loading these fonts https://fonts.googleapis.com/css2?family=Raleway:wght@100;300;600&display=swap and sometimes the waitUntil="networkidle" will complete its ½ second wait before the font has loaded, resulting in the doc being printed in the fallback font.
References
I've had a read of this: Controlling Font Performance with font-display and this: Navigating & waiting, and done a lot of searching, but with no avail.
Possible work arounds
- I could download the font to my computer so that it's a local asset, but that means remembering an extra step if I change my mind about the font in future. It also makes it harder to do on a remote machine.
- I could add in a fat pad of >4 seconds as an explicit wait, but that adds 4×N seconds to the run time if N=the number of documents (6½ per 100 documents)
- I could write a service worker to precache the fonts and then emit an event, but this is way more work than this deserves, and managing its lifecycle seems like a painful future.
Is there an easy way?