Intercept WebView requests and add Auth token in all subsequent resource request [GET .js, .png, .css].

Intercept WebView requests and add Auth token in all subsequent resource request [GET --> .js, .png, .css].

We have tried the below delegate methods and those call are not getting invoked.

We have a challenge with Webview when load our application URL.

  1. func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!) {
  2. func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

we are looking for some delegate or protocol to intercept the request to add the token for all the requests.

is there any possible solution to fix this issue?

Thanks

Usually in such cases you want to add tokens as a cookie attached to request, in that case you need to save that cookie to WKWebView first and then load page. At this point question is what your server expects? In which way that token must be passed?

p.s. Those delegate methods that you mentioned are designed to be invoked only for main resources like HTML pages and iframes so they are useless for sub-requests interception.

Intercept WebView requests and add Auth token in all subsequent resource request [GET .js, .png, .css].
 
 
Q