Inconsistent text rendering in headless mode
See original GitHub issueEDIT: The fix is to add --font-render-hinting=none
to the launch args. E.g.
var browser = await puppeteer.launch({
headless: true,
args: ['--font-render-hinting=none']
});
Original Comment: Font spacing seems to be inconsistent between headless and non headless mode. This is likely a Chromium bug for Puppeteer versions 1.2.0 and above.
Steps to reproduce
Tell us about your environment:
- Puppeteer version: 1.2
- Platform / OS version: Linux
- URLs (if applicable):
- Node.js version: 8.6.0
What steps will reproduce the problem?
- screenshot.js
'use strict';
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({ headless: true }); // toggle to false
const page = await browser.newPage();
await page.goto('file:///tmp/test.html');
await page.waitFor(5000);
await page.screenshot({path: '/tmp/screenshot.png'});
await browser.close();
})();
- test.html
<html>
<head>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Lato">
<style>
body {
font-family: 'Lato', serif;
font-size: 15px;
}
div.a {
line-height: 0.5;
}
</style>
</head>
<body>
<div class="a">
<div>aaaaa..............................................................................|111</div><br>
<div>qwertyasdfzxcvyuiohjklbnm................................|222</div><br>
<div>longlonglonglonglonglonglonglongshorty......|333</div>
</div>
</body>
</html>
node /tmp/screenshot.js
, then repeat withheadless: false
What is the expected result?
Text is correctly aligned and looks the same as opening the HTML in browser. headless: false
What happens instead?
Text is misaligned with headless: true
Issue Analytics
- State:
- Created 5 years ago
- Reactions:48
- Comments:28 (4 by maintainers)
Top Results From Across the Web
744577 - Headless: Font rendering / line break different from ...
Issue 744577: Headless: Font rendering / line break different from desktop chrome · 1. Start chrome on headless mode on port 9223 google-chrome ......
Read more >How to fix puppeteer font issues - browserless docs
The first thing to try out is to applying a --font-render-hinting flag. This value, which defaults to "full", sets a font render hinting...
Read more >Kerning issues with headless chrome - Stack Overflow
For some reason headless chrome (v69 on ubuntu 16.04) screws up kerning and as a result the screenshots end up being quite different,...
Read more >Fetch Rendered Font Using Chrome Headless Browser
Controlling Font Performance with fontdisplay CSS Variables: Why Should You Care? It's a way to run the Chrome browser in a headless environment....
Read more >Troubleshooting - Puppeteer
Chrome headless doesn't launch on Windows ... Some chrome policies might enforce running Chrome/Chromium with certain extensions. Puppeteer passes --disable- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
--font-render-hinting=none
seems to be the trick for meAfter digging a little bit more, I found that the inconsistency is caused by https://github.com/GoogleChrome/puppeteer/pull/2072
which in turn, is from https://github.com/chromium/chromium/commit/e1b855d4545dc4fff19cee500d7ce105126f3bd2
If I understand correctly the changes to Chromium, Puppeteer’s
Launcher.js
should set DEFAULT_ARGS for--font-render-hinting
tomedium
instead of leaving it at default. Doing so does indeed resolve this issue.I can make a PR if this is an acceptable solution. Any thoughts, @aslushnikov?