skip to Main Content

I am getting an "Incompatible Browser" error when trying to load a website using WKWebview. The same website loads fine using the Safari browser. I have also tried setting the user agent of my webview using the customUserAgent method to "Mozilla/5.0 (iPhone; CPU iPhone OS 15_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Mobile/15E148 Safari/604.1" (which is the one used by Safari), but I’m still seeing the same issue.
My viewcontroller code is fairly simple and just loads the wkwebview using a url:

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
    var webView: WKWebView!

    override func loadView() {
        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 15_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Mobile/15E148 Safari/604.1"
        webView.navigationDelegate = self
        view = webView
    }
    


    override func viewDidLoad() {
        super.viewDidLoad()
        let url = URL(string: "http://whatsmyuseragent.org/")!
        webView.load(URLRequest(url: url))
    }
}

Other than the user agent, is there anything else that I could be missing out while configuring the wkwebview?

Thanks!

PS- The whatsmyuseragent url works after adding NSAppTransportSecurity to info.plist as suggested by @Desmond. But my client’s website (which is https) still does not work and shows an Incompatible Browser issue.

2

Answers


  1. Chosen as BEST ANSWER

    The issue was in the info.plist. My client's website asks for media permissions such camera/microphone/etc. Their site's logic was to show the "Incompatible Browser" page if they detect that the webview does not have the media permissions. Adding these Privacy permissions to the info.plist along with a sample string value fixed the issue (important to add a sample string in the Value column for these permissions, as leaving them blank also resulted in an incompatible browser page).

    Thanks @Desmond for the suggestion to add NSAppTransportSecurity for allowing http websites.


  2. If the URL start with HTTP, please add this property to your info.plist

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoadsInWebContent</key>
        <true/>
    </dict>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search