tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.32k stars 1.68k forks source link

Error when using Canary 66 #191

Open caiofcm opened 6 years ago

caiofcm commented 6 years ago

Hi,

I am using the package for the first time and when applying the simple sample from README:

var node = document.getElementById('my-node');

domtoimage.toPng(node)
    .then(function (dataUrl) {
        var img = new Image();
        img.src = dataUrl;
        document.body.appendChild(img);
    })
    .catch(function (error) {
        console.error('oops, something went wrong!', error);
    });

I am getting the error when using Chrome Canary (Version 66.0.3355.4 (Official Build) canary (64-bit)) - the error is kinda unpredictable, some times it shows the error and outputs the image to the document:

Uncaught TypeError: Cannot read property 'split' of null
    at FileReader.encoder.onloadend (dom-to-image.js:504)

When running in Chrome Version 64.0.3282.167 (Official Build) (64-bit) everything goes OK.

Thank you

Syndesi commented 6 years ago

Hi,

the error happend on line 504:

var encoder = new FileReader();
encoder.onloadend = function () {
    var content = encoder.result.split(/,/)[1];     // line 504
    resolve(content);
};
encoder.readAsDataURL(request.response);

Therefore it seems that the FileReader-object returns just null which shouldn't be the case at all, see MDN's documentation. Maybe it s due to some problem with the async-code, but I would rather assume that's a small bug - Canary is not without reason a development version. But it's weird that such a bug is included after all :/

caiofcm commented 6 years ago

From your link I understood it can return null (the result attribute) . Thank you for your reply.