Is there a way to get the FULL URL loaded by a WKWebView for every request?
webView:didFinishNavigation:
Works only for
This is Yuichi Kato's answer for Swift 4. It retrieves the full URL from the request property of the navigation action in the webView(_:decidePolicyFor:decisionHandler:) method of WKNavigationDelegate.
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let urlStr = navigationAction.request.url?.absoluteString {
//urlStr is what you want
}
decisionHandler(.allow)
}
Don't forget to conform your class to WKNavigationDelegate and set your web view's delegate accordingly:
class WebViewController: UIViewController, WKNavigationDelegate
[...]
webView.navigationDelegate = self