dom-to-image icon indicating copy to clipboard operation
dom-to-image copied to clipboard

dataurl is empty for large dom element

Open gamenic-arim opened this issue 2 years ago • 2 comments

image

const imageElement = document.getElementById( "image-container-id" );

const dataUrl = domtoimage.toPng(imageElement); console.log(dataUrl); // got response -> data: ;

when the dom element is usually large data URL response is empty

gamenic-arim avatar Apr 20 '22 04:04 gamenic-arim

cause domtoimage.toPng return a promise, try domtoimage.toPng(imageElement).then(dataUrl => { console.log(dataUrl)} );

arlendp avatar Apr 22 '22 04:04 arlendp

Hi @arlendp I'm having the same issue.

To reproduce it:

I first Go to https://jetrotal.github.io/EasyChar/

then open console, and clean up the div, using DOMPurify:

document.getElementById('charContainer').innerHTML = DOMPurify.sanitize(document.getElementById('charOutput'), 
{ USE_PROFILES: { html: true } });

then, run the toPng function:

var node = document.getElementById('charOutput');

domtoimage.toPng(node).then(function (dataUrl) {

        var img = new Image();
        img.src = dataUrl;
        document.getElementById('header').appendChild(img);
        
    })
    .catch(function (error) {
        console.error('oops, something went wrong!', error);
    });

The result is a broken image with data: ; as its URL

jetrotal avatar Jul 09 '22 21:07 jetrotal