Firefox: document.defaultView.getComputedStyle is null
See original GitHub issueIt’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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
479698 - document.defaultView.getComputedStyle doesn't return ...
defaultView.getComputedStyle! Actual Results: It returned an empty string. Plese note that I had set this property in the head of the HTML document....
Read more >"TypeError: c.defaultView.getComputedStyle(...) is null" error ...
I'm making a page with some iframes in and I keep getting this "TypeError: c.defaultView.getComputedStyle(...) is null" error when loading the ...
Read more >document.defaultView.getComputedStyle(div, null) is null (FF ...
This is an issue I ran into while working on the default display bug. Firefox will not render "presentation" (ie. computed styles) in...
Read more >Window.getComputedStyle()
The Window.getComputedStyle() method gives the values of all the CSS properties of an element after applying the active stylesheets and ...
Read more >Get Styles - JavaScript - QuirksMode
else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);. Finally return y to whichever function ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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)
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.