Closed Bug 1071620 Opened 10 years ago Closed 9 years ago

window.innerWidth/innerHeight return incorrect values during "DOMContentLoaded" event on page with <meta name="viewport">

Categories

(Firefox for Android Graveyard :: Toolbar, defect)

32 Branch
All
Android
defect
Not set
normal

Tracking

(p11+, firefox41 fixed, fennec+)

RESOLVED FIXED
Firefox 41
Tracking Status
p11 + ---
firefox41 --- fixed
fennec + ---

People

(Reporter: damien.derouet, Assigned: esawin)

References

Details

Attachments

(2 files)

Attached file bugInnerHeight.html
User Agent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36

Steps to reproduce:

Using window.innerHeight on DOMContentLoaded event.

user-agent:
Mozilla/5.0 (Android; Mobile; rv:32.0) Gecko/32.0 Firefox/32.0


Actual results:

If window.innerHeight is called  on DOMContentLoaded event, the returned value is incorrect. When called after load event, the returned value is OK. (see the testsheet attached to reproduce)


Expected results:

The value should be the same before and after the load event
OS: Windows XP → Android
Hardware: x86 → All
Component: General → Graphics, Panning and Zooming
I'm also hitting this problem.

This is impacting mobile Wikipedia - the mobile site renders as if treated as if it is a tablet (all sections are open by default, table of contents shows and code that doesn't work so well on smaller screen is loaded that shouldn't be loaded!)

We had a bug reported at https://bugzilla.wikimedia.org/show_bug.cgi?id=70277
tracking-fennec: --- → ?
Kats & Mike, is this us or them?
Flags: needinfo?(miket)
Flags: needinfo?(bugmail.mozilla)
Probably us. This could happen if the DOMContentLoaded event is dispatched before we update the CSS viewport properties in the before-first-paint event handler.
Flags: needinfo?(bugmail.mozilla)
Summary: window.innerWidth/innerHeight return incorrect values during "load" event on page with <meta name="viewport"> → window.innerWidth/innerHeight return incorrect values during "DOMContentLoaded" event on page with <meta name="viewport">
Status: UNCONFIRMED → NEW
Ever confirmed: true
This seems like Bug 771575, no?
Assignee: nobody → nchen
tracking-fennec: ? → +
Some remarks when investigating the problem. I checked with FF32 and the problem wasn't there. I tried to get a regression window by going through the nightlies, but abandon that because all builds (I've tried) failed.

Also the values can still be wrong on onload. I noticed this issue with a giant codebase and there wrong values were still present on the onload event. I have to use a setTimeout on the onload event before the proper values are used.
I believe this bug is responsible for us getting tablet-sized content on the Google Inbox homepage. See https://bugzilla.mozilla.org/show_bug.cgi?id=1091683#c3.
This bug affects document.documentElement.clientWidth, too. I've attached a test-case to another bug that probably has the same cause: https://bugzilla.mozilla.org/show_bug.cgi?id=908568#c3
This bug still affects Firefox Android 36.

You can see the error on this jsBin: http://jsbin.com/feditadufo/2
to see the code: http://jsbin.com/feditadufo/2/edit?html
I get two different screen sizes, 
the first is during the Dom content loading and the second one is after the resize event.

The deal is that I can't wait the resize event,
my page depends on the size to define what will do on the first scroll.
Waiting for the resize event would delay the first scroll rendering.
Still affects Firefox 37 and 38 beta for Android.

This totally throws off Google AdSense’s responsive ads and cause site-compatibility issues on all sites that use it. It causes AdSense to serve too large ad units and often ends up covering page.

Have had to stop using Firefox for Android as may sites I visit regularly are covered up by skyscraper ads instead of cute and small mobile ads.
Is there someone that can work on this, Kats?
Assignee: nchen → nobody
Flags: needinfo?(bugmail.mozilla)
I suspect this bug is behind the issue at https://github.com/webcompat/web-bugs/issues/1025 (an important site for Japan compat).
Unfortunately I don't have cycles for working on this at the moment. Eugen has worked in related code before, so he might be a good person to tackle this.
Flags: needinfo?(bugmail.mozilla) → needinfo?(esawin)
tracking-p11: --- → +
This bug has an interesting history (bug 759678 -> bug 771575 -> bug 1046631), we should find a way break out of the circle.

I will look into it.
Flags: needinfo?(esawin)
With this patch, we update meta data when handling DOMMetaAdded to set the proper CSS viewport metrics before DOMContentLoaded is fired. However, we exit early before updating the zoom/resolution in this case to prevent overriding the zoom factor which is yet to be restored (so we do not regress on bug 1046631).

This also fixes https://github.com/webcompat/web-bugs/issues/1025 and https://github.com/webcompat/web-bugs/issues/930.

However, it might not completely fix bug 908568, as the script in https://bugzilla.mozilla.org/show_bug.cgi?id=908568#c3 would return the correct values for "Load" and "DOMContentLoaded", but would still show the default 980 for "Initial". Fixing this is out of scope of this bug.
Assignee: nobody → esawin
Status: NEW → ASSIGNED
Attachment #8606327 - Flags: review?(bugmail.mozilla)
I cannot verify whether it fixes bug 1091683 because of bug 1165350.
Comment on attachment 8606327 [details] [diff] [review]
0001-Bug-1071620-Update-meta-data-on-DOMMetaAdded-before-.patch

Review of attachment 8606327 [details] [diff] [review]:
-----------------------------------------------------------------

I can't think of anything that this will break but I'm like 80% sure something will break because this code is a minefield. Let's see what happens!
Attachment #8606327 - Flags: review?(bugmail.mozilla) → review+
I'm assuming this fix will also fix any other width-related properties from being way-off during DOMContentLoaded, such as document.documentElement.clientWidth.
It should, yes. Those values are all computed based on the innerWidth.
https://hg.mozilla.org/mozilla-central/rev/864fbcaaff7e
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 41
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: