Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

desktop browsing in iOS 13 with WKWebView?

According to WWDC 2019 video 203, I should be able to see desktop browsing in a full-screen WKWebView on an iPad. But I'm not seeing it. For example, when I go to google in my WKWebView, I'm clearly seeing the mobile version of the site.

I've tried everything the video suggests. I've set the applicationNameForUserAgent, and the web inspector shows that it is being set as they advise in the video:

"5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/1.0 MyBrowser/1.0"

I've also implemented the navigation delegate to request .desktop mode:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, preferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {
    preferences.preferredContentMode = .desktop
    print("asking for desktop version")
    decisionHandler(.allow, preferences)
}

That method is being called. But I'm still seeing the mobile version of the site.

When I go to the same site in Safari on the same iPad, or if I use an SFSafariViewController, I do see the desktop version of the site, as advertised. How can I get that version of the site in my WKWebView?

like image 483
matt Avatar asked Sep 05 '25 22:09

matt


1 Answers

I was able to get it to work by using "Version/13.0.1 Safari/605.1.15" as my applicationNameForUserAgent string.

(Where did I get that string? Basically I simply stole it from the SFSafariViewController.)

This seems like a bug. Apple's video implies that I should not have to lie about who the user agent is in order to get desktop browsing.

like image 149
matt Avatar answered Sep 09 '25 21:09

matt