WKWebView occasionally shows white screen and persists until app restart

I am encountering an intermittent issue with WKWebView in my iOS app. The problem occurs infrequently, but when it does, the WKWebView consistently displays a white screen and remains in this state until the app is forcefully terminated and relaunched.

To provide more context, here are the key characteristics of the issue:

  1. The white screen problem occurs sporadically and is not easily reproducible.
  2. The WKWebView remains unresponsive despite attempts to interact with it.
  3. Reloading the webpage or navigating to a different URL does not resolve the white screen issue.
  4. The problem persists until the app is terminated and relaunched.
  5. This issue is specific to the WKWebView; other components of the app function correctly.
  6. The WKWebView renders normally, and the main document synchronously loads resources both offline and online without any issues. The bridge and JavaScript execution also work as expected.
  7. However, when interacting with the WKWebView, it becomes unresponsive to user clicks, and the web inspector fails to respond. Additionally, asynchronous network requests also do not receive any response.
  8. The problem occurs exclusively on HTTPS pages, whereas HTTP pages load without any issues. Other components, such as workers, function correctly.
  9. addUserScript injection during WKWebView creation is effective, and evaluateJavaScript during the page loading process works as expected. However, when the document becomes unresponsive, executing evaluateJavaScript only triggers the callback after the WKWebView is destroyed.

I have discovered a reliable method to reproduce the white screen issue in WKWebView. This method involves the following steps and conditions:

  1. Create a WKWebView instance.
  2. Load an HTML page using the loadRequest method(https url request).
  3. Before the WKWebView is attached to the UI (not yet visible to the user), call the evaluateJavaScript function.

This issue has occurred in almost all iOS versions, including the latest iOS 17.x version.

咋样 老哥 解决了吗~

Can you use an example program to reproduce this problem

when this white screen happen, have you ever tried to connect your iphone to Mac and dig in the console log to see what goes wrong?

WKWebView occasionally shows white screen and persists until app restart
 
 
Q