Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKWebView not loading content from iframe on a webpage

Tags:

ios

I have a WKWebView where a user goes through several pages to reach a page which contains a video from lesson.ly.

The problem is that the video will not show up at all within the webview, there is just a blank gap in the page where the video would be. However, if I open chrome on iOS, it loads just fine.

I've pinpointed the issue by debugging the HTML code. Here is a screen shot of the HTML on the webview: enter image description here

And Here's a picture of the HTML on Chrome for Mac: enter image description here

If you noticed, there is nothing within the iframe for the webview. I have no idea why it's not loading the data. I have enabled 'Allows Arbitrary Loads' for App Transport Security to no avail.

Any help appreciated, thanks.

like image 741
johnslay Avatar asked Oct 17 '25 18:10

johnslay


1 Answers

Alternatively, instead of allowing specific URLs, you can check if request in question is targeting main frame or not:

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void) {
    // Allow navigation for requests loading external web content resources.
    guard navigationAction.targetFrame?.isMainFrame != false else {
        decisionHandler(.allow)
        return
    }

    ...
}
like image 117
Alex Staravoitau Avatar answered Oct 20 '25 08:10

Alex Staravoitau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!