Dari
iOS

Getting started

Record WKWebView bridge traffic in an iOS app and inspect it in the desktop app

The Dari Swift package records your WKWebView bridge traffic and sends it to the same desktop app you use for Android. The list, details, filters, masking, search, and export work the same way. A smaller in-app inspector shows the messages on the device too.

iOS connections are macOS-only: apps connect from an iOS Simulator, or from an iPhone or iPad attached to the Mac over USB. Building and installing an iOS debug build already needs a Mac, so the desktop app on Windows and Linux shows Android devices only. Connections over Wi-Fi are not offered.

Requirements

  • iOS 16 or later (Dari 3.4.0 and earlier support iOS 15)
  • The Dari desktop app on a Mac. iOS connections need macOS: Simulators run only there, and USB devices are reached through macOS's usbmuxd.
  • For a physical device: a USB cable, the device unlocked once with Trust This Computer accepted, and the app installed from Xcode
  • adb is optional. Without it, the desktop app shows only iOS apps.

Install

  1. In Xcode, choose File → Add Package Dependencies… and enter https://github.com/easyhooon/dari.
  2. Choose Up to Next Major Version from 3.0.0.
  3. Add the Dari library to your app target, and DariUI too for the in-app inspector.

With Package.swift:

.package(url: "https://github.com/easyhooon/dari", from: "3.0.0")
// target dependencies
.product(name: "Dari", package: "dari")
.product(name: "DariUI", package: "dari") // optional: the in-app inspector

Compatibility

  • The iOS SDK and the Android library share the version line from 3.0.0. iOS needs Dari desktop 3.0.0 or later.
  • The wire protocol stays at version 1, so desktop 3.x still connects to Android apps on Dari 2.x, and desktop 2.x keeps working with Android apps on 3.x.
  • Android apps need no migration for 3.0.0. The handshake gains optional platform and osVersion fields, which older peers ignore.

Start Dari

Call start() once, early in app launch, and only in builds you inspect.

import Dari

@main
struct MyApp: App {
    init() {
        #if DEBUG
        try? Dari.shared.start()
        Dari.shared.setEnvironment(["server": "dev"]) // optional labels shown in the desktop app
        #endif
    }
    // ...
}

While Dari is running, any process that can reach the device's loopback can read the recorded messages. Never call start() in an App Store build.

start() takes a DariConfiguration:

OptionDefaultMeaning
maxEntries500Messages kept in memory; the oldest are dropped first
retentionPeriodnilSeconds a message is kept; older ones are dropped when a new one is recorded
persistsMessagesfalseKeep messages across relaunches (3.6.0+); see Keep messages across relaunches
maxContentLength500,000Longer payloads are truncated, as on Android
fireAndForgetfalseRecord requests as finished when they are sent
ports38670...38677Loopback ports to try; the desktop app probes the same range

Keep messages across relaunches

By default, messages live in memory and are gone when the app relaunches or crashes. To keep them, as Android does:

try? Dari.shared.start(DariConfiguration(persistsMessages: true))
  • Messages are written to Application Support/Dari/messages.jsonl as they're recorded, and come back on the next start(), in the in-app inspector and in the desktop app.
  • maxEntries and retentionPeriod apply to the stored messages too. There is no separate size limit, as on Android: with 500 messages at the 500,000-character limit the file could reach hundreds of MB, though real bridge traffic is usually a few MB.
  • Stored messages load in the background, so start() doesn't slow app launch. They appear a moment later, before the messages recorded since launch.
  • Responses never complete a request from an earlier launch, even when the bridge reuses callback ids.
  • A crash can lose the last few milliseconds of messages.
  • Payloads are stored as recorded, including tokens. The file is excluded from backups and protected until the device is first unlocked. Clear in either inspector deletes it, and starting with persistsMessages: false deletes it too. stop() keeps it for the next start().

Add your own masking

The desktop app's Mask sensitive values setting covers keys such as token or password. For other fields, such as account numbers or resident IDs, rewrite messages before they're sent:

Dari.shared.setPayloadRedactor { message in
    var message = message
    message.requestData = message.requestData?.replacingOccurrences(
        of: #""accountNo":"[^"]*""#, with: #""accountNo":"***""#, options: .regularExpression
    )
    return message
}
  • It runs on every message sent to the desktop app, after the built-in masking when that is on. Recorded messages stay as they are.
  • You can change requestData, responseData and pageUrl. Unlike Android, handler names and the other fields are read-only.
  • Raw protobuf previews aren't sent while it's set, because it can't edit raw bytes.
  • If it throws, both payloads are replaced with [dari: payload hidden, redactor failed] and the page URL is dropped, instead of being sent as they are.
  • It runs on background threads, possibly several at once, so the closure must be @Sendable. Pass nil to remove it.

In-app inspector

Add the DariUI library to check messages on the device, without a Mac:

import DariUI

// From your app's debug menu
Dari.shared.presentInspector()

// Or in your own SwiftUI sheet
.sheet(isPresented: $showingDari) { DariInspectorView() }
  • A list of recorded messages, newest first, with search over handler, tag and payloads.
  • Overview, Request and Response for each message, with pretty JSON and the protobuf Decoded / Raw views.
  • Share one message as text, or export all of them as text or JSON from the ⋯ menu. Clear is there too, and also clears a connected desktop app.
  • Mask Sensitive Values in the ⋯ menu masks tokens, passwords and the like in the list, detail, search, share and export, with the same rules as the desktop app. It's off by default and remembered across launches. Raw protobuf views are hidden while it's on.
  • The desktop app's masking setting and setPayloadRedactor apply only to what's sent to the desktop app, not here.
  • There's no notification or shake-to-open yet; open it from your own debug menu. Like the rest of Dari, use it only in debug builds.

Sample app

sample-ios/DariSample.xcodeproj loads a page with Web → App and App → Web scenarios: success, error, slow response, no response, fire-and-forget, masking, and protobuf, plus an Inspector button that opens the in-app inspector. Its bridge records itself with @DariBridge and sends callbacks through dariEvaluateJavaScript, as in Compile-time capture with macros. The parsers live in SampleCapture. To try automatic capture instead, add -DariAutoCapture YES to the scheme's launch arguments. Open it in Xcode 16 or later and run the DariSample scheme on a Simulator.

Next steps

On this page