I want to verify how my app handles webViewWebContentProcessDidTerminate
.
I can call my delegate's webViewWebContentProcessDidTerminate
directly, but this does not give me full confidence that it behaves as it would in real life.
How can I terminate a WKWebView, causing this callback to be triggered?
If you may know webViewWebContentProcessDidTerminate
will be called when com.apple.WebKit.WebContent will be terminated by operating system.
In most cases it will be caused by Out Of Memory issues. Personally I have been facing when WkWebView used a lot of memory but not at not critical level to terminate at the same time another view has been placed over Webview (it means that com.apple.WebKit.WebContent goes to background).
If you are interested how to realistically trigger calling this method, try to crash it by OOM error:
load a HTML page with next JS string in the body:
const OOMString = Array(1024 * 1024 * 1000).fill('A').join(''));
if you are going to do so from your native side (ObjectiveC/Swift), here is another example:
[wkWebView evaluateJavaScript:@"window.OOMString = Array(1024 * 1024 * 1000).fill('A').join(''));" completionHandler:nil];
You need to take into account that webViewWebContentProcessDidTerminate
will be called by operating system decides to terminate your process. For different devices will be different size of memory allowed to occupy.
I'm highly not recommend you to load memory this way because it can impact your user experience or clients experience. the best approach here is to do as much as you can to do not allow system to call this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With