WKWebview displays blank page intermittently on iOS and macOS

Our app connects to the headend to get a IDP login URL for each connection session, for example: “https://myvpn.ocwa.com/+CSCOE+/saml/sp/login?ctx=3627097090&acsamlcap=v2” and then open embedded webview to load the page. (Note: the value of ctx is session token which changes every time). Quite often the webview shows blank white screen. After user cancel the connection and re-connect, the 2nd time webview loads the content successfully.

The working case logs shows:

  • didReceiveAuthenticationChallenge is called
  • decidePolicyForNavigationAction is called twice
  • didReceiveAuthenticationChallenge is called
  • decidePolicyForNavigationResponse is called
  • didReceiveAuthenticationChallenge is called

But the failure case shows:

  • Filed to terminate process: Error Domain=com.apple.extensionKit.errorDomain Code=18 "(null)" UserInfo={NSUnderlyingError=0x11461c240 {Error Domain=RBSRequestErrorDomain Code=3 "No such process found" UserInfo={NSLocalizedFailureReason=No such process found}}}
  • didReceiveAuthenticationChallenge is called
  • decidePolicyForNavigationAction is called
  • decidePolicyForNavigationResponse is called

If we stop calling evaluateJavaScript code to get userAgent, the blank page happens less frequently. Below is the code we put in makeUIView():

func makeUIView(context: Context) -> WKWebView
{
        if let url = URL(string: self.myUrl)
        {
            let request = URLRequest(url: url)
            webview.evaluateJavaScript("navigator.userAgent")
            {
                result, error in
                if let error = error
                {
                    NSLog("evaluateJavaScript Error: \(error)")
                }
                else
                {
                    let agent = result as! String + " " + self.myUserAgent
                    webview.customUserAgent = agent
                    webview.load(request)
                }
            }
        }
      return self.webview

}

Found some posts saying call evaluateJavaScript only after WKWebView has finished loading its content. However, it will block us to send the userAgent info via HTTP request. And I don’t think it is the root cause since the problem still occurs with less frequency.

There is no problem to load same web page on Windows desktop and Android devices. The problem only occurs on iOS and macOS which both use WKWebview APIs.

Is there a bug in WKWebview?

Thanks, Ying

WKWebview displays blank page intermittently on iOS and macOS
 
 
Q