question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firefox: document.defaultView.getComputedStyle is null

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
robske110commented, Aug 16, 2018

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)

1reaction
robske110commented, May 13, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found