1

I'm facing the issue with getting content Height of WebView by Whooshkaa playlist link https://player.whooshkaa.com/player/playlist/show/2321?sharing=true.

The WKWebView inside custom View and I'm gonna recalculate frame view after loading WebView success.

I've tried 3 ways:

  • Create an observer when the webView contentSize changed like this Example.
  • EvaluateJavaScript like this:
  func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {

    webView.evaluateJavaScript("document.body.offsetHeight") { [weak self] (height, _) in
        guard let height = height as? CGFloat else { return }
        // Still 200
    }
}

---> But all the cases return offsetHeight only 200px. As you can see it's still missing the playlist content bellow.

enter image description here

Is there another way/trick that I can get offsetHeight correctly?

Canh Tran
  • 298
  • 1
  • 14

1 Answers1

1

200px is min height for the page you have shared. You might need to check your webview frame.

Do not use CGRect.zero for the initial frame, this might cause error loading page. I have added simple code example and it works as it should.

enter image description here

enter image description here

ymutlu
  • 6,585
  • 4
  • 35
  • 47
  • 1
    Your answer seems like I have to minus the webView frame? I create the WebView with WKWebView(frame: CGRect.zero). My goal is I need to set the frame of webView based on the webView's content size after loading finish. – Canh Tran Jun 01 '18 at 06:09