Tracker Prevention for WKWebView
August 12, 2020
In 2017, Apple WebKit team announced “Intelligent Trackers Protection” feature which blocks cross-site trackers and cookies. Slowly WebKit team is adding new features to WebKit and bringing the same to Safari.
Safari 14 improves ITP and by default, it will block all the cross-site trackers by using on-device machine learning to identify trackers and the known trackers are identified by DuckDuckGo. Safari not only blocks the trackers, but it will also list all the trackers and websites in detail. Here is the screenshot of all trackers blocked from Safari 14. I have been using it from beta 1.
The interesting thing with ITP is we (third party developers) can start using it for our in-app browsers which uses
WKWebView without any extra effort. It comes free when you use
WKWebView and you have iOS 14 or macOS Big Sur installed.
In case if we want to opt-out from this default behaviour, we could simply set the purpose string
Info.plist. When present, this key causes the application’s Settings screen to display a user control to disable ITP. The setting cannot be read or changed through API calls.
NOTE: As of beta 4, I couldn’t get the settings even after adding purpose string. Probably it will work on upcoming beta’s
Incase if the app wants to be “Default Browser”, purpose strings is not necessary.
- WebKit App Bound domains blog post
Special thanks to Stuart who introduced to me this feature in NetNewsWire Slack channel when we discussed having tracker protection for app.