Chart.js: Firefox: document.defaultView.getComputedStyle is null

Created on 26 Feb 2018  ·  6Comments  ·  Source: chartjs/Chart.js

It's difficult to produce a codepen for this one since it involves loading an iFrame with display: none, but the bug is pretty much what the title says. This is a documented issue in Firefox.

See https://bugzilla.mozilla.org/show_bug.cgi?id=548397

To workaround the issue, you need to account for the fact that getComputedStyle can potentially return a null value

The following function is in core.helpers.js

    helpers.getStyle = function(el, property) {
        return el.currentStyle ?
            el.currentStyle[property] :
            document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
    };

This will be fixed if that function is changed to something like the following

    helpers.getStyle = function(el, property) {
                if(el.currentStyle) return el.currentStyle[property];
                var computedStyle = document.defaultView.getComputedStyle(el, null);
                if(computedStyle) return computedStyle.getPropertyValue(property);
                return 0;
    };

I'm not keen on the specifics of what returning 0 would mean, but hopefully you get the gist of the problem

bug

All 6 comments

since it is unlikely that firefox will fix this in a timely manner, it would be nice if we could find a solution for ChartJS in the meantime.

Do we have news here? Some prevision?

Hit the same error - would be nice to find a fix for this!

This bug has been fixed in FireFox -- https://bugzilla.mozilla.org/show_bug.cgi?id=1467722
I tested on 62.0b17 and it finally works like in all the other browsers.
This issue should be closed as soon as FireFox 62 is released, which should be on the 05.09.2018.

Firefox-ESR users will have to wait some more, but ESR is not actually very wide-spread, even companies have the "normal" Firefox most of the time. (09.07.2019)

@simonbrunel @kurkle @nagix @benmccann seems like this can be closed as resolved?

Agreed

Was this page helpful?
0 / 5 - 0 ratings