New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix JS error on Firefox hidden iframes: verify that getComputedStyle is not returning null before using it #1443
Fix JS error on Firefox hidden iframes: verify that getComputedStyle is not returning null before using it #1443
Conversation
596b787
to
15cc5cf
Compare
…efore using its result (it returns null if it's called inside a hidden iframe).
15cc5cf
to
a01e972
Compare
Hey @felipebrahm - awesome work! I have two hesitations with this though.
|
|
regarding 1. I really don't think it would be terribly complicated to abstract. Just something like
2 - totally understand, however for other sites it may really matter. (see xkcd). I am fine with them "breaking" in the hidden iframe for the moment (as that is better than them flat out breaking like they are currently), however I think an error like the one above would at least help anyone hitting the issue in the future find this and figure out what the hell is going on |
Has any progress been made here? I'm having the same problem where Modernizr completely fails in Firefox. |
I agree with @patrickkettner that adding all those null checks is going to be error-prone for anyone writing a Modernizr detect. Abstracting this into a function would help to centralize the noise. Looking at the current uses, the only complicated case is the one for ruby which already has its own wrapper. Most of the others seem to just need one property off function getStyleProperty( style, pseudo, prop ) {
// IE <= 8 doesn't have getComputedStyle
// Firefox 39+ returns null for styles in hidden iframes
var cs = window.getComputedStyle && window.getComputedStyle( style, pseudo );
if ( !cs ) {
return null;
}
return cs.getPropertyValue( prop );
} There are some differences in usage like vhunit and inputtypes but those should work with When |
thanks for the initial repotr @felipebrahm! With the new helper and associated eslint rule, this shouldn't ever be a problem again |
On Firefox,
getComputedStyle
returnsnull
if it's called inside a hidden iframe. You can see an example here:https://www.groupon.com/deals/butter
Open that URL on Firefox. You'll see several JS errors in the console, the first being
TypeError: window.getComputedStyle(...) is null
. This is happening not on that page, but on a hidden iframe on that page (that iframe is loaded on page load but it's only shown when a user takes certain action, so it's a completely valid use case).So, basically, this code will break:
The solution is to first check for the returned value, like this:
Different files have different coding styles, so I tried to preserve the coding style for each file.