-
-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Add an option to pass custom browser arguments to Playwright when launching the browser #137
Labels
enhancement
New feature or request
Comments
nielthiart
added a commit
to nielthiart/shot-scraper
that referenced
this issue
Dec 18, 2023
Ref simonw#137 This change adds `--browser-args` option to the CLI, then passes a list of arguments to the browser launch function. The argument can be included multiple times to list multiple arguments. This enables users to pass flags to the browser, such as `--font-render-hinting=none`, `--disable-gpu`, etc. These flags can have an effect on how screenshots are captured across different platforms. Detailed reason here: simonw#137
simonw
pushed a commit
that referenced
this issue
Feb 5, 2024
Ref #137 This change adds `--browser-args` option to the CLI, then passes a list of arguments to the browser launch function. The argument can be included multiple times to list multiple arguments. This enables users to pass flags to the browser, such as `--font-render-hinting=none`, `--disable-gpu`, etc. These flags can have an effect on how screenshots are captured across different platforms. Detailed reason here: #137
simonw
added a commit
that referenced
this issue
Feb 5, 2024
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 cc199c4. Will fix that now. |
simonw
added a commit
that referenced
this issue
Feb 5, 2024
simonw
added a commit
that referenced
this issue
Feb 5, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
shot-scraper "https://www.bellingcat.com/resources/2016/12/06/vacuuming-image-metadata-wayback-machine/" \ -w 1200 -h 800 \ -o examples/1-bellingcat-default.png
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.
The text was updated successfully, but these errors were encountered: