I'm working on a iOS (swift) Secure Browser
Project. I need to implement one functionality in which we can show users how many tracking scripts are running in current WKWebView
and ability to stop those tracking script. (Just like Ghostery Privacy Browser
)
I'm able to track and list the scripts embedded in web page (I do this after scanning the content which has already loaded in the delegate didfinishload is called). But I'm not sure how do I stop them.
For fetching all scripts in webpage I'm reading all script tags in innerHTML
.
Please help me stop executing certain scripts in WKWebView
.
Thank you in advance
I don't think that reading all script tags is the way to detect scripts loaded by web page as it is very error prone.
For your task you would be better served by using an old UIWebView and implementing custom NSURLProtocol to do blocking/filtering. It is not possible to intercept all the request made by WKWebView (as it is loaded out of process and you get as much callbacks as Apple has implemented in WKNavigationDelegate). Contrary you can control everything loaded by UIWebView with simple custom NSURLProtocol implementation.