Bug 221279

Summary: [iOS] window.screen.{width, height} are incorrect on iPhone 12 in WKWebView
Product: WebKit Reporter: Ali Juma <ajuma>
Component: Layout and RenderingAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: bfulgham, kirill.kandalov, simon.fraser, thorton, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.chromium.org/p/chromium/issues/detail?id=1172787
Attachments:
Description Flags
Test case from crbug.com/1172787
none
screenshot WebKit ToT none

Description Ali Juma 2021-02-02 12:09:38 PST
Created attachment 419046 [details]
Test case from crbug.com/1172787

On iPhone 12 on iOS 14.4, window.screen.{width, height} is incorrect in non-Safari WKWebView, but correct in Safari.

Specifically, in WKWebView (tested in Chrome, Edge, and Firefox on iOS):
window.screen.width is 375 and window.screen.height is 812

But in Safari:
window.screen.width is 390 and window.screen.height is 844

This bug was originally reported at https://crbug.com/1172787
Comment 1 Radar WebKit Bug Importer 2021-02-09 12:10:12 PST
<rdar://problem/74152923>
Comment 2 zalan 2021-05-13 10:56:27 PDT
Created attachment 428532 [details]
screenshot WebKit ToT

I am seeing 375x812 on trunk WebKit.
Comment 3 zalan 2021-05-13 10:56:47 PDT
(In reply to zalan from comment #2)
> Created attachment 428532 [details]
> screenshot WebKit ToT
> 
> I am seeing 375x812 on trunk WebKit.
In Safari that is.
Comment 4 kirill.kandalov 2021-05-25 06:55:17 PDT
Do you check with "Zoom" feature on or off? As it affects the values that you'll see.

Check this article that states when each resolutions should appear:
https://hacknicity.medium.com/how-ios-apps-adapt-to-the-various-iphone-12-screen-sizes-e45c021e1b8b
"Standard Zoom
Unlike the iPhone 12 mini, the iPhone 12 and 12 Pro introduce a completely new resolution of 390×844 points at their native resolution"
And
"Apps built with Xcode 12.0 or earlier will see a zoomed up iPhone 11 Pro resolution of 375×812 when run on the iPhone 12 or 12 Pro at its native resolution"

BTW all the internet is full of claiming that iOS window should be 390x844.
E.g. https://yesviz.com/devices/iphone-12/
https://useyourloaf.com/blog/iphone-12-screen-sizes/

Back to the bug, is the wrong resolution in non-Safari WKWebView due to compilation with old XCode or for other reason (i.e. bug)?
Comment 5 Tim Horton 2021-05-25 10:51:52 PDT
<rdar://78465520>
Comment 6 Ali Juma 2021-05-26 05:26:30 PDT
I re-tested on the currently shipping versions of Chrome, Firefox, and Edge on iOS, and they all now show the same result as Safari on iOS 14.5 (390x844).

For Chrome at least, this seems to have been fixed by building with Xcode 12.1+ rather than Xcode 12.0.

I think the only thing remaining to figure out here is Comment 2, that is, why trunk WebKit is reporting 375x812 rather than 390x844.