WKWebViewWithURLProtocol icon indicating copy to clipboard operation
WKWebViewWithURLProtocol copied to clipboard

WKURLSchemeHandler for http and https resource requests

Open ArunaYarra opened this issue 1 year ago • 1 comments

Hi Wilddylan,

As you mentioned, if you target iOS 11, you can now use WKURLSchemeHandler to avoid this trick! 😆

Could you please assist me in how we can add WKURLSchemeHandler support to monitor HTTP/HTTPS resources instead of this private API? AFAIK WKURLSchemeHandler is for custom schemes.

Any sample code would be appreciated.

Thanks, Aruna

ArunaYarra avatar Nov 29 '24 07:11 ArunaYarra

`` Hi ArunaYarra,

Currently you can't intercept https/http scheme request using WKURLSchemeHandler Since Apple will throw error while you try to register

let webConf = WKWebViewConfiguration() webConf.setURLSchemeHandler({{wkurlschemehandler instance}}, forURLScheme: "https")

//*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ''https' is a URL scheme that WKWebView handles natively'

however you intercept requests with custom scheme in you webview. like the below listed code. :

for HTML:

"///<html> ////<body> ///<img src = "customscheme://file/fileid"> ///</body> ///</html>

ios registeration code : let webConf = WKWebViewConfiguration() webConf.setURLSchemeHandler({{wkurlschemehandler instance}}, forURLScheme: "customscheme")

Thanks, Prabu

dineshprabu-s avatar May 15 '25 14:05 dineshprabu-s