bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.4k stars 505 forks source link

Getting stuck on generation while in a loop #374

Open Smokovsky opened 1 year ago

Smokovsky commented 1 year ago

Current Behavior

I'm using html-to-image to generate images of the data tables in the loop (Let's say I've got 300 tables I need to make a screenshot of). The issue is sometimes it gets stuck without getting into then() or catch(). I couldn't find any pattern when it's happening. When it gets stuck once, I wiped the data, and in another run, it got stuck at other table. Sometimes It happens that whole 300 will run without a stuck, but sometimes it got frozen even at the beginning.

Steps To Reproduce

This is the code. When it gets stuck, the last thing in the console is 'generate stats'.

async generateImage() {
    await new Promise(async resolve => {
        var node: any = document.getElementById('image-section');
        console.log('generate stats');

        await htmlToImage.toBlob(node).then((dataUrl) => {
            console.log('stats generated');
            // ...
        }).catch(() => {
            console.log('stats not generated');
        });
    }
}

Additional info

It happens no matter the image size (I was console.loging size of the area before running generation). If the image would be too big (or got too many elements), then it's going to the catch(). But why does it get stuck? Seems completely random.

Your Environment

vivcat[bot] commented 1 year ago

👋 @Smokovsky

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.