WKWebView dismiss its entire view controller when presented modally

Number:rdar://34547298 Date Originated:09/20/2017
Status:Open Resolved:
Product:WebKit Product Version:iOS 11.0
Classification:Bug Reproducible:Always

On iOS 11.0, "WKWebView"s which are presented modally will dismiss their view controller when a callout is dismissed (both "UIPopoverPresentationController" and "UIAlertController").

Steps to Reproduce:
1. Create a view controller containing a "WKWebView" loading some URL
2. Present modally the view controller of the previous step
3. Tap and hold on a link in the web page to present the callout (popover or alert)
4. Dismiss the callout (popover or alert)

or you can download my sample project (https://github.com/matteomatassoni/ModalWebViewiOS11Bug), run it and then follow step 3 and 4

Expected Results:
Dismiss of callout of step 3 and 4

Actual Results:
Dismiss of presented view controller of step 2

iOS 11.0



Temp solution

We currently fix this be disabling callout on iOS 11 by injected javascript and CSS

WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init]; if (!self.calloutEnabled) { // Javascript that disables callout by inserting the HTML viewport meta tag into NSString *source = @"var style = document.createElement('style'); style.type = 'text/css'; style.innerText = '*:not(input):not(textarea) { -webkit-user-select: none; -webkit-touch-callout: none; }'; var head = document.getElementsByTagName('head')[0]; head.appendChild(style);"; WKUserScript *script = [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];

    // Create the user content controller and add the script to it
    WKUserContentController *userContentController = [[WKUserContentController alloc] init];
    [userContentController addUserScript:script];

    // Add the user content controller to the configuration
    configuration.userContentController = userContentController;

// Create the web view with the configuration
self.webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];

Encountered this problem as well. Hope we can have a fix soon.

Any news on this one?

Not yet

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!