Bug 151384 - window.innerWidth seems to return something other than the viewport width
Summary: window.innerWidth seems to return something other than the viewport width
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: Safari 9
Hardware: iPhone / iPad iOS 9.0
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-18 03:56 PST by Tobi Reif
Modified: 2016-01-07 04:57 PST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobi Reif 2015-11-18 03:56:15 PST
Please load this page

http://tobireif.com/non_site_stuff/copy_of_tobireif_com_startpage_for_webkit_bugreport_innerWidth/

in the iPhone 4s (iOS 9.1) simulator. The "stamp" (circle) should be centered.

Change the function getViewportWidth to always return window.innerWidth, then view the page in the iPhone simulator. The contact stamp is off-center (but in eg Firefox with the ~same window size it's centered as intended).

I'd like to be able to use the simple version of the function for all browsers & OSs & devices.
Comment 1 Tobi Reif 2015-11-18 05:10:53 PST
When I load the page in the Android stock browser (uses WebKit?), then rotate, then rotate again/back, the stamp is off-center.
Comment 2 Simon Fraser (smfr) 2015-12-03 16:13:10 PST
innerWidth is indeed changing as the page loads, and doesn't stabilize until after the load event fires.
Comment 3 Simon Fraser (smfr) 2015-12-03 16:13:14 PST
innerWidth is indeed changing as the page loads, and doesn't stabilize until after the load event fires.
Comment 4 Tobi Reif 2016-01-07 04:23:40 PST
I'll try running the adjust-layout func on load.

(Related:
https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html
"load": "Deprecated, use pageshow instead."
So "pageshow" is to be used instead it seems.)
Comment 5 Tobi Reif 2016-01-07 04:57:13 PST
In an old Dolphin (uses WebKit it seems) on Samsung Galaxy S3 the width still isn't correct.

I had to force a redraw using a hack:

body.style.display = "none";
setTimeout(actuallyAdjustLayout, 0);

function actuallyAdjustLayout() {
  body.style.display = "block";
  // ...
}