DEV Community

Rizwan
Rizwan

Posted on • Originally published at blog.rizwan.dev on

Tracker Prevention for WKWebView

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

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.

Safari Privacy Report

WKWebView

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 NSCrossWebsiteTrackingUsageDescription in 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.

Links

Special thanks to Stuart who introduced to me this feature in NetNewsWire Slack channel when we discussed having tracker protection for app.

AWS Q Developer image

Your AI Code Assistant

Generate and update README files, create data-flow diagrams, and keep your project fully documented. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Best practices for optimal infrastructure performance with Magento

Running a Magento store? Struggling with performance bottlenecks? Join us and get actionable insights and real-world strategies to keep your store fast and reliable.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️