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.

Abnormal letter spacing in Chrome / Chromium

See original GitHub issue

When calling:

html2canvas(document.getElementsByClassName('console'), {
      onrendered: function(canvas) {
        var img = canvas.toDataURL()
        var iframe = '<iframe src="' + img + '" frameborder="0" style="border:0; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%;" allowfullscreen></iframe>'
        var x = window.open();
        x.document.open();
        x.document.write(iframe);
        x.document.close();
      },
      letterRendering: true,
    });

Both with or without letterRendering, this is what Chrome outputs:

html2canvasbug

When the output in Firefox is:

screenshot-2017-11-19 http localhost

Any specific reason why it renders it like that?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:4
  • Comments:26 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
maaouicommented, Feb 13, 2019

I have fixed this also by going to the div I want to screenshot and then I set the " font-variant: normal; " this has worked for me hope it helps .

3reactions
christopherkadecommented, Dec 30, 2017

I have found a workaround for the matter (and it’s not very clean):

// Package used to detect the browser used by the user
const browser = detect();
const element = document.getElementById('console');

// Set up my options
let options = {};
// For some reason foreignObjectRendering solves the spacing issue on Chrome but gives an error on Firefox, so I detect the browser and apply the adequate options.
if (browser && browser.name === 'chrome') {      
  options = {
    useCORS: true,
    foreignObjectRendering: true
  };  
}

// Open the canvas in a new window
html2canvas(element, options).then(function(canvas) {
  const url = canvas.toDataURL();
  const img = '<img src="' + url + '" style="border:0;"></img>'
  const x = window.open();
  x.document.open();
  x.document.write(img);
  x.document.close();
});

Note that the error I get on Firefox when using the second option is as follows:

Uncaught (in promise): [Exception… "Method not implemented" …

Read more comments on GitHub >

github_iconTop Results From Across the Web

380298 - Fonts are suddenly larger and letter spacing uneven
Most text is much larger (especially address bar), and letter spacing is incredibly uneven in proportional fonts, with some letters being ...
Read more >
Change the spaces between text - Microsoft Support
Change spacing between characters, kern fonts, stretch or scale text, and set line spacing.
Read more >
font character spacing issue - Google Chrome Community
I am using a Chromebook and I am having a problem with font character spacing. The spacing is fine on webpages but the...
Read more >
The best web browsers for 2022 - Digital Trends
We pitted Chrome, Firefox, Opera, and Microsoft Edge against one another ... rewrote Edge using the open-source Chromium web browser engine.
Read more >
insufficient disk space for mega running in chrome
Now most of the disk is free versus having zero disk space …. Whether you're running the Teams desktop app or the Teams...
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