question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent text rendering in headless mode

See original GitHub issue

EDIT: 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?

  1. 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();
})();
  1. 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>
  1. node /tmp/screenshot.js, then repeat with headless: false

What is the expected result? Text is correctly aligned and looks the same as opening the HTML in browser. headless: false

headless_false

What happens instead? Text is misaligned with headless: true

headless_true

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:48
  • Comments:28 (4 by maintainers)

github_iconTop GitHub Comments

84reactions
jmjprocommented, Dec 2, 2019

--font-render-hinting=none seems to be the trick for me

24reactions
Minscommented, Apr 19, 2018

After 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 to medium 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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found