tsayen / dom-to-image

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

Katex (MathML-Library) creates the error "target is undefined" #182

Closed Syndesi closed 6 years ago

Syndesi commented 6 years ago

Hi,

I'm using Katex to display mathematical expressions and I wan't to save them as images, but dom-to-image crashes with the error "target is undefined". I found out that it's happening in this function:

function cloneStyle() {
    copyStyle(window.getComputedStyle(original), clone.style);

    function copyStyle(source, target) {
        if (source.cssText) target.cssText = source.cssText;
        else copyProperties(source, target);

        function copyProperties(source, target) {
            util.asArray(source).forEach(function (name) {
                target.setProperty(
                    name,
                    source.getPropertyValue(name),
                    source.getPropertyPriority(name)
                );
            });
        }
    }
}

Basically clone is a <mi /> Element from MathML which doesn't have a style-attribute, therefore the target.setProperties()-function is executed on an undefined attribute and crashes.

Here is a simple demo project. Run npm install, npm run start to start it.