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.

html2canvas promise returned before render complete

See original GitHub issue

Please make sure you are testing with the latest release of html2canvas. Old versions are not supported and issues reported for them will be closed.

Please follow the general troubleshooting steps first:

  • You are using the latest version
  • You are testing using the non-minified version of html2canvas and checked any potential issues reported in the console

Bug reports:

I have a page with several divs. Each of these divs has several react-table elements. I want to take a screenshot of each div and then create a zip file and download all of them at once (as a sort of pseudo powerpoint slide deck). This works perfectly on Mac, however when I’m using Google Chrome on Windows, the divs with several react tables seem to not finish rendering when the screenshot is taken. I’ve confirmed by turning on logging that the render completes in ~1000ms, but the canvas that html2canvas returns appears as though it didn’t finish rendering. The react-tables are rendered, but the rest of the text on the page is somewhat transparent, as if it was halfway finished loading.

I don’t have a jsfiddle repro quite yet, but I’ll work on that to get one added here.

Specifications:

  • html2canvas version tested with:
  • Browser & version: latest Chrome - 77.0.3865.90
  • Operating system: Windows (important, can’t reproduce on a Mac)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:5

github_iconTop GitHub Comments

8reactions
travischamberscommented, Oct 2, 2019

I have been able to get this to work, though it’s not optimal.

html2canvas(div, {
    letterRendering: true,
    onclone: (doc) => {
        // onclone logic to resize div

        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve()
            }, 400)
        })
    }
}).then((obj) => {
    let img = obj.toDataURL()
    // save image to zip file
})

I came to the 400ms timeout through trial and error. Anything less, and I observed the issue with the div not being completely rendered when html2canvas takes the screenshot.

6reactions
gregroyalcommented, Nov 12, 2019

I also ran into this issue and it caused a pretty bad bug on our end. Would like fixed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I know when html2canvas is done? - Stack Overflow
In html2canvas 0.4 and below versions was used callback method onrendered. Old documentation after 0.5 it was rewritten to use Promises New ...
Read more >
html2canvas - npm
The script renders the current page as a canvas image, by reading the ... The function returns a Promise containing the <canvas> element....
Read more >
Options - html2canvas
Name Default Description logging true Enable logging for debug purposes width Element width The width of the canvas height Element height The height of the canvas...
Read more >
How can I properly wait for an svg, that is drawn with D3.js, to ...
js one is finished. Also because of how html2canvas works I need to wait until the svg is rendered & visible, otherwise I...
Read more >
html2canvas | Yarn - Package Manager
... es6-promise before including html2canvas . To render an element with html2canvas, simply call: html2canvas(element[, options]);. The function returns a ...
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