WKWebView does not support custom headers on outgoing requests
Originator: | james.eunson | ||
Number: | rdar://50057283 | Date Originated: | 4/19/2019 |
Status: | Open | Resolved: | |
Product: | iOS | Product Version: | 12.2 |
Classification: | Bug | Reproducible: | Always |
Area: WebKit Summary: UIWebView supports being able to modify headers on outgoing requests, whereas WKWebView does not. It is possible to achieve a partial solution by overriding `webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ())` in `WKNavigationDelegate`, however this does not cover XMLHttpRequest (XHR) requests, which are very important in single page applications. This significantly limits the usefulness of WKWebView for some applications. This is a downgrade from UIWebView for this use case. Steps to Reproduce: - Attempt to apply headers to any outgoing request, for example "x-secret-key": "1234" - Use a web application with XHR requests - Notice your header is not being applied Expected Results: Header should be applied to all requests. Actual Results: webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> ()) is not invoked for non-XHR requests. This means headers cannot be applied to XHR requests. Version/Build: Any up to and including iOS 12.2 Configuration: Nothing non-standard
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Really need this functionality!
I have read everything I could find about how it might be possible to add / modify request headers in WKWebView. The only working way at the moment is to have a local running proxy server that WKWebView starts requests against. This is highly highly flawed and bring a number of issues to the table.
Please Apple pretty please allow WKWebView to delegate to my app that I can get a chance to modify / add Headers for outgoing requests. Incoming Responses would be a bonus.
Kind regards, Andre