WKWebView viewport shrink-to-fit not working on iOS 9.3

Originator:nicholas.solter
Number:rdar://25774429 Date Originated:3/21/16
Status:Closed Resolved:
Product:iOS SDK Product Version:9.3
Classification: Reproducible:Yes
 
Summary:
In iOS 9.2, a WKWebView rendering HTML with fixed-width tables bigger than the device width could be told to shrink the content to fit by adding a viewport tag like this:

<meta name="viewport" content="width=device-width, shrink-to-fit=YES">

This line caused the WKWebView to effectively zoom out the viewport so that the entire rendered page fit in the view frame without the need for scrollbars. However, this behavior has changed in 9.3. The identical code running in 9.3 renders differently.

For example, consider the following code, when run in viewDidLoad in a vanilla single view app: 

WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
WKWebView *newWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0,40,self.view.frame.size.width, self.view.frame.size.height - 40) configuration:wkWebConfig];
NSString *toRender = @"<head><meta name=\"viewport\" content=\"width=device-width, shrink-to-fit=YES\"></head><body><table width=700 style='background-color: blue; color:white; font-size=20px'><tr><td>this is some text that is long enough to exceed the width of the iphone 6 unless shrink-to-fit is applied</td></tr></table></body>";
[newWebView loadHTMLString:toRender baseURL:nil];
[self.view addSubview:newWebView];

This renders on ios 9.2 and ios 9.3 as shown in the "ios92.png" and "ios93.png" screenshots respectively.

Was this change intentional? If so, is there a workaround to obtain the 9.2 behavior on 9.3?

Steps to Reproduce:
Render HTML with a fixed-width table bigger than the viewport in a WKWebView, with a meta viewport tag specifying width=device-width. 

https://github.com/nsolter/NSWebViewShrinkTest demonstrates the problem.

Expected Results:
WebView should zoom out to fit entire width of html page in device width (pre ios 9.3 behavior).

Actual Results:
The viewport tag seems to be ignored - the view does not shrink the content to fit in the device width. This behavior is new with ios 9.3.

Version:
9.3.1 (13E238)

Notes:
If this is an intentional and permanent change in behavior, please let me know if there is any workaround.

Configuration:
Any hardware/simulator with ios 9.3.

Comments

Response from Apple:

No, we don’t want to maintain shrink-to-fit behavior. The workaround is to use a viewport meta tag that correctly describes the width of the content.

By nicholas.solter at April 21, 2016, 6:01 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!