WkWebView with adaptive width and height

I need to create a WkWebView with adaptive size.(The size will mostly be fixed i.e 300 * 250 and sometimes it could have a dynamic height. It depends on the type of response I get from server)

The initial size of my WkWebView is 300 * 250. To expand the WkWebView frame I calculate height from didFinish callback and updating the frame.

The problem with this solution is that WkWebview updates its frame twice and the user experience is not good. Is there another way to do this?

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let height = webView.scrollView.contentSize.height
webView.bounds = CGRect(x: 0, y: 0, width: self.view.frame.width, height: Double(height))
}
WkWebView with adaptive width and height
 
 
Q