I have an area in my app where I load local HTML strings in WKWebView. Loading is fast on iOS. These local HTML strings are small.
On Mac Catalyst I added the ability to open this area of the UI in a new window scene (new window). And for some reason sometimes when I do this these simple HTML strings can take 10-15 seconds to load in the WKWebview in the new window.
These HTML strings are super small. I key value observed the loading property of the WKWebview and I hold the current date just before calling -loadHTMLString:baseURL:
Then when the web view completes loading I see how much time passed:
-(void)observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey,id>*)change
context:(void*)context
{
if (object == self.webview
&& [keyPath isEqualToString:@"loading"])
{
if (!self.webview.isLoading)
{
NSTimeInterval timeInterval = [NSDate.date timeIntervalSinceDate:self.loadStartDate];
NSLog(@"Web view took %f seconds to load",timeInterval);
}
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
Sometimes it is taking as long as 5 seconds to load a tiny HTML string. When opening these WKWebviews in the same window I don't get these long load times. But when I kick of WKWebView inside a new window scene I often do.