niklasvh / html2canvas

Screenshots with JavaScript
https://html2canvas.hertzen.com/
MIT License
30.48k stars 4.8k forks source link

HTML2CANVAS making the webpage unresponsive #3119

Open BISWAJITABISWAL opened 1 year ago

BISWAJITABISWAL commented 1 year ago

Dear Team,

I am facing issue with HTML2CANVAS, when i click on button the following function get called its take 10 to 15 seconds for the window to open with canvas image in it if element is too large then it take much more time, is there any way to handle this

` const exportAsPicture = async () => {

    try {
        present();
        var data = document.getElementById('print-area')
        const canvas = await htmlToImage.toCanvas(data)
        var win = window.open();
        var style = win.document.createElement('style');
        style.innerHTML = `
            body {
                margin: 0;
                padding: 0;
            }
        `;
        win.document.head.appendChild(style);
        win.document.body.appendChild(canvas);
        win.print();
        win.close();
        dismiss();
    } catch (error) {
        console.log(error);
        dismiss();

    }

}`