|
An example of something to keep in mind with this technique is that you might actually end up causing the browser to render a different font than either you or the user intended. For a practical example: Environment - Latest Firefox on Windows 10.
- Manually installed fonts 'Cascadia Code' and 'JetBrains Mono NL'.
- Firefox default 'monospace' font set to 'JetBrains Mono NL'.
Setting `font-family: monospace;` would end up rendering 'JetBrains Mono NL' - the user-configured default monospace font.Setting `font-family: 'Cascadia Code', monospace;` would also render 'JetBrains Mono NL' - privacy features prevent pages from querying non-standard system fonts and this will also be reflected as a console warning message: 'Request for font "Cascadia Mono" blocked at visibility level 2 (requires 3)".' Now, if you were to use he "Monospace Code" font stack listed on this page `font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace;`, you will render... Yup, 'Consolas'! 1. `ui-monospace` - remains unsupported by Firefox which is lame (would also render 'Consolas').
2. `Cascadia Code` - see above, access denied because it isn't natively available on Windows 10 (also, coding ligatures... more like illigatures, amirite?).
3. `Source Code Pro` - skipped due to unavailability.
4. `Menlo` - skipped due to unavailability.
5. `Consolas` - next option in line, this one is available and is the one that will be chosen.
6. `DejaVu Sans Mono` - skipped, font already determined.
7. `monospace` - skipped, font already determined.
These modern font stacks suck. Please, if you want to render font and it has to be something specific, then use an actual web font and simply fall back to the default 'monospace' which is controlled by the user. |
Also maybe worth noting that we can always force our (three) font faces everywhere simply by unchecking the "Allow pages to choose their own fonts" in settings. Yes, this is nuclear option, but I can attest that I use it time to time, and it is quite usable.
BTW, I have somewhat softer workaround that interestingly makes the (local) Cascadia on modernfontstacks work even in the Strict Tracking Protection mode: I have a "userstyle" [0] (more precisely userCSS in Stylus) that "remaps", among other things, "Consolas" to a @font-face of the same name but loading `src: local("Cascadia Mono")` instead. Not sure why exactly this circumvents that (I don't think that Stylus-injected styles have more privileges than page styles), but I am glad it works nonetheless.
[0] https://userstyles.world/style/23838