/TrackerRadarKit

Primary LanguageSwiftApache License 2.0Apache-2.0

TrackerRadarKit

We are hiring!

DuckDuckGo is growing fast and we continue to expand our fully distributed team. We embrace diverse perspectives, and seek out passionate, self-motivated people, committed to our shared vision of raising the standard of trust online. If you are a senior software engineer capable in either iOS or Android, visit our careers page to find out more about our openings!

Building

TrackerRadarKit has one explicit dependency (https://github.com/apple/swift-argument-parser) that is automatically resolved when installing the swift package in Xcode. It can be added to an Xcode project as a swift package dependency or be used as an imported Swift package.

It can be built manually two ways:

  1. Build the TrackerRadarKit scheme by opening the Swift package in Xcode
  2. Run swift build -c release to build a release binary

SwiftLint

We use SwiftLint for enforcing Swift style and conventions, so you'll need to install it.

Validator

The Validator tool can be used to validate that Tracker Radar data can be parsed, transformed and compiled by WebKit's content rule list store. As such, it requires macos 10.13 to run.

To build, check out the code and run from the project root:

  • swift build

To run, execute the following from the project root:

  • .build/debug/Validator

Installation

We recommend the use of Swift Package Manager

How to block trackers

In order to block content on the web view you need to compile a content rule list using Apple's WKContentRuleListStore, then apply the compiled rule list to WKUserContentController.

TrackerRadarKit allows you to generate this list using DuckDuckGo's Tracker Radar as source. The main structs you'll need to use to create a content rule lists are:

Example

let trackerData: TrackerData = ...
let allowList: [String] = ...

let blockerBuilder = ContentBlockerRulesBuilder(trackerData: trackerData)
let rules = blockerBuilder.buildRules(withExceptions: allowList)

let data: Data

do {
    data = try JSONEncoder().encode(rules)
} catch {
    // Handle Error
}

let ruleList = String(data: data, encoding: .utf8)

License

DuckDuckGo is distributed under the Apache 2.0 license.