Closed nielthiart closed 5 months ago
Thanks for this, it's a really neat (and cleanly implemented) new feature.
Documentation is here: https://shot-scraper.datasette.io/en/latest/screenshots.html#browser-arguments
My bad, I messed up my change in https://github.com/simonw/shot-scraper/commit/cc199c4e38b288acc8ec3c46bdbef255c1e4a103. Will fix that now.
Here are the examples files that were created by the last GitHub Action CI run:
font-hinting-default:
font-hinting-none:
I had the need to pass command line arguments to Playwright when launching a browser.
Chromium has a long List of Chromium Command Line Switches that users might find useful.
Why I use browser arguments: font render hinting
Font rendering in headless chrome is inconsistent between different platforms. When testing on a mac, font rendering is good, but on GitHub's action runners (Linux) the kerning is off, which affects line lengths. Some fonts at smaller sizes also appear a few pixels too high or low.
One solution to fix this, is to pass the
--font-render-hinting=none
argument when callingchromium.launch()
.This solution comes up when users ask for help with font rendering in headless chrome, puppeteer, etc.
Examples
Here's an example of a page captured in a GitHub action with and without font render hinting:
Default font render hinting
The kerning is incorrect on small font sizes and lines wrap earlier.
With font-render-hinting=none
The kerning looks much better here.
Alternative solution: Unrelated to browser arguments
As a workaround, we can achieve similar font rendering results by using CSS to add
text-rendering: geometricPrecision
to all elements:I'd prefer not to add CSS if we can launch the browser with an argument that fixes font rendering instead.