Dialogue Dismisser and Navigation Tracking
This page documents two independent, opt-in subsystems that sit alongside the core WebView: a pair of dialogue (overlay) dismissal implementations and a unified navigation (URL-cycle) tracker. Both are built on the same composable module convention — maybeCreate → mergeUserScripts → attach — that the package uses for its other optional feature modules. Understanding this page requires one crucial insight up front: the repository ships two divergent dialogue-dismissal implementations, only one of which is wired to a shipped setting, and the DialogueDismisser / NavigationTracker modules are intentionally unwired building blocks ready to be composed by callers or a future setting.
Sources: dialogue_dismisser.dart, navigation_tracker.dart, main.dart
Two Dialogue Dismissal Implementations
Section titled “Two Dialogue Dismissal Implementations”The single most important architectural fact on this page is that “dialogue dismissal” means two different things in this codebase. The distinction is captured in an explicit Architecture Decision Record, and conflating them would either break the spec’s acceptance contract or silently change documented behavior.
The legacy brute-force implementation is driven by the boolean InAppWebViewSettings.dismissDialogues (default false). When enabled, it removes every element whose computed position is fixed or sticky from the top-level document, resets overflow/margin on the document element and body, and retries three times to catch late overlays. This is the shipped, spec-compliant behavior traced to acceptance criteria SC-001..SC-005. The content-aware DialogueDismisser module, by contrast, removes only overlays whose text matches keyword presets (cookie / GDPR / in-app-download / newsletter), deliberately leaving legitimate sticky/fixed elements — price banners, nav bars, chat widgets — untouched.
| Dimension | Legacy dismissDialogues |
DialogueDismisser module |
|---|---|---|
| Trigger | InAppWebViewSettings.dismissDialogues == true |
Caller-supplied presets set |
| Selection | Every fixed/sticky element |
Text-matched overlay candidates only |
| Wiring status | Wired in InAppWebView / HeadlessInAppWebView |
Unwired (experimental, self-tested) |
| Timing | onLoadStop, 3× retries @ 800ms |
Document-start script + timed/observer retries |
| Spec trace | A1–A5 / SC-001..SC-005 | Out-of-trace baseline (U1–U7) |
| Reports events | No (returns removed count) | Yes, via __zikzakDialogueDismissed__ |
Sources: adr-001-dismiss-dialogues-vs-dialogue-dismisser.md, dismiss_dialogues_legacy.dart
The following diagram shows the decision boundary and where each implementation lives relative to the WebView lifecycle.
graph TD Settings["InAppWebViewSettings.dismissDialogues (bool, default false)"] OnLoadStop["onLoadStop callback"] Legacy["runLegacyDismissDialogues()<br/>brute-force fixed/sticky removal"] Dismisser["DialogueDismisser module<br/>content-aware, preset-matched"] Nav["NavigationTracker module<br/>unified URL-cycle stream"]
Settings -->|wired| OnLoadStop OnLoadStop --> Legacy Dismisser -.->|intentionally unwired| Caller["Caller / future setting"] Nav -.->|intentionally unwired| Caller
Legacy -->|removes ALL fixed/sticky| DOM1["Top-level DOM"] Dismisser -->|removes MATCHED overlays only| DOM2["Top-level DOM"]Sources: in_app_webview.dart, adr-001-dismiss-dialogues-vs-dialogue-dismisser.md
The Legacy dismissDialogues Flow
Section titled “The Legacy dismissDialogues Flow”The shipped behavior is deliberately kept in a small, public, verbatim module (dismiss_dialogues_legacy.dart) so its behavior can be characterized by tests and cannot drift silently. The InAppWebView constructor wires it into onLoadStop behind a guard: after the caller’s own onLoadStop runs, if shouldDismissDialogues(initialSettings) is true, it fires runLegacyDismissDialogues(controller) as an unawaited future. The runner injects the removal script up to three times, waiting 800ms between the first two attempts, and swallows any platform error so the WebView is never left broken.
sequenceDiagram participant Page participant Widget as InAppWebView participant Runner as runLegacyDismissDialogues Page->>Widget: onLoadStop(controller, url) Widget->>Widget: caller onLoadStop?.call() Widget->>Widget: shouldDismissDialogues(settings)? Widget->>Runner: unawaited(runLegacyDismissDialogues) loop i = 0..2 Runner->>Page: evaluateJavascript(legacyDismissDialoguesJs) Page-->>Runner: removed count Note over Runner: if i<2 wait 800ms endSources: in_app_webview.dart, dismiss_dialogues_legacy.dart
A subtle divergence worth noting for maintainers: HeadlessInAppWebView still carries an inlined copy of the same removal script inside its own onLoadStop, rather than calling the extracted runLegacyDismissDialogues helper the widget uses. The behavior is identical (3× retries, 800ms delay, error swallowed), but the duplication means the two call sites must be kept in sync. Sources: headless_in_app_webview.dart
The DialogueDismisser Module Architecture
Section titled “The DialogueDismisser Module Architecture”DialogueDismisser is a content-aware dismisser whose architecture deliberately mirrors NavigationTracker and NetworkCaptureManager. Its lifecycle is three static/instance steps: maybeCreate builds the dismisser (returning null for an empty preset set, so there is nothing to do), mergeUserScripts composes the caller’s scripts with the dismisser’s injected UserScript, and attach(controller) registers the __zikzakDialogueDismissed__ JavaScript handler and flushes any events the page buffered before registration. A key design property is that the module works without a WebView — handleJsPayload operates on a plain instance, and only attach touches the JS bridge, which makes the whole thing unit-testable in pure Dart.
The injected script is forMainFrameOnly: true at AT_DOCUMENT_START (consent popups live in the main frame), and each dismissal is reported back as a DialogueDismissal record carrying the matched preset, a method (currently always removed — the dismisser removes elements directly rather than clicking accept/close buttons), a text snippet, and the pageUrl.
Sources: dialogue_dismisser.dart, dialogue_dismissal.dart
Content-Aware Classification Rules
Section titled “Content-Aware Classification Rules”Classification is defined twice — once in pure Dart (DialogueDismissRules) for unit-testability, and mirrored in the injected JavaScript — so both sides agree on which overlays qualify. Four concrete presets each carry a list of JS/Dart-compatible keyword patterns, and all is a meta-preset meaning the union of the four (explicitly not the legacy brute-force behavior). Text is normalized with a Turkish-aware lowercase (İ→i, I→ı before lowercasing) and whitespace collapse so matching is stable across locales; the pattern for in-app-download uses a word boundary (\bindir\b) so indir does not match inside indirim (a discount banner).
| Preset | Example patterns | Intent |
|---|---|---|
cookieConsent |
cookie, çerez, cerez |
Cookie banners |
gdpr |
consent, gdpr, kvkk, gizlilik, kabul et |
Consent / privacy dialogs |
inAppDownload |
download.{0,20}app, app store, uygulama, \bindir\b |
“Install our app” nudges |
newsletter |
newsletter, subscribe, bülten |
Newsletter signups |
Sources: dialogue_dismiss_rules.dart, dialogue_dismisser_test.dart
The JavaScript candidate detector is where the real-world hardening lives. It gathers candidates from strong selectors (OneTrust, Cookiebot, Didomi, generic [class*="banner"]/[id*="modal"]), [role="dialog"]/[aria-modal="true"], and any consent-named or overlay-positioned element. It then applies several safeguards: a nested-candidate dedupe that keeps only the deepest candidate (so removing a sticky header does not take a legitimate nav bar with it), a shadow-DOM-aware text collector that skips SCRIPT/STYLE subtrees (CMP web components bury 60K+ of CSS at the top of their shadow root), and viewport-relative area guards so a full-screen app shell that merely contains consent text survives while the actual banner is removed. Unmatched candidates are deliberately not marked processed, so late-rendered shadow content is re-evaluated on later scans. Sources: dialogue_dismisser_js.dart, dialogue_dismisser_js.dart
Navigation Tracking
Section titled “Navigation Tracking”NavigationTracker unifies every URL-change source the package exposes into one ordered, deduplicated stream of UrlCycleEntry objects. It merges two input channels: the widget callbacks forwarded via onLoadStart, onUpdateVisitedHistory, onServerRedirect, and onUserOverride; and an injected tracker UserScript (document-start, all frames) that monkey-patches history.pushState/replaceState and listens to popstate/hashchange/pageshow, reporting through the __zikzakNavigationTracker__ handler with trigger jsHistory. Each entry records the full url, a millisecond timestamp, a UrlCycleTrigger, and an isMainFrame flag.
The dedup rule is precise: the same URL observed within a 500ms window collapses to a single entry, keeping the earliest trigger. A mainFrameOnly flag (default true) drops sub-frame changes. As with the dismisser, the tracker works without a WebView — handleJsPayload and the forwarder methods operate on a plain instance, and attach only wires the bridge and flushes the in-page queue via window.__zikzakNavigationTracker__.ready().
| Trigger | Source |
|---|---|
loadStart |
onLoadStart widget callback |
visitedHistory |
onUpdateVisitedHistory widget callback |
jsHistory |
Injected script (history API / popstate / hashchange / pageshow) |
redirect |
onServerRedirect (iOS/macOS), reuses last URL |
userOverride |
shouldOverrideUrlLoading observation |
Sources: navigation_tracker.dart, url_cycle_entry.dart, navigation_tracker_js.dart
The Shared Module Wiring Convention
Section titled “The Shared Module Wiring Convention”Both DialogueDismisser and NavigationTracker follow the exact same three-method convention as NetworkCaptureManager, which is the only one of the three currently wired into InAppWebView/HeadlessInAppWebView. This is why the ADR concludes the modules can be promoted to first-class features with zero architectural change once a distinct setting is added — the wiring hook already exists in the same shape.
| Step | Responsibility | Null-safety |
|---|---|---|
maybeCreate(...) |
Build the module, or null when disabled/empty |
Returns null for empty presets |
mergeUserScripts(scripts, module) |
Append the module’s UserScript to caller scripts |
Returns caller scripts unchanged when null |
attach(controller) |
Register JS handler + flush buffered page queue | No-op target when module absent |
Sources: dialogue_dismisser.dart, navigation_tracker.dart, in_app_webview.dart
Testing and Verification
Section titled “Testing and Verification”Both modules are covered by pure-Dart characterization tests that require no platform WebView, which is a direct consequence of the “works without a WebView” design. The dialogue-dismisser suite verifies Turkish-aware normalization, per-preset classification (including that price/campaign banners like Sepette %20 indirim match nothing), JS serialization of only the enabled presets, the main-frame-only document-start UserScript shape, and payload routing to the dismissal callback. The navigation-tracker suite verifies JSON round-trips, the fixed trigger-name contract, forwarder ordering, the 500ms dedup boundary (same URL within window collapses; after window is a new entry), and the mainFrameOnly sub-frame filter. The shipped dismissDialogues boolean is separately characterized for its default-false contract.
Sources: dialogue_dismisser_test.dart, navigation_tracker_test.dart, dismiss_dialogues_setting_test.dart
Where to Go Next
Section titled “Where to Go Next”To see how the shared maybeCreate/mergeUserScripts/attach convention is wired end-to-end for the one module that is connected, read Network Capture, Interception, and Secret Redaction. For how the dialogue dismisser supports clean captures in the recording/replay flow, continue to Session Recording and Replay (Recipes) and VCR Cassettes and the WebView Pool. To understand the settings seam that a future content-aware setting would extend, see The Platform Interface: The Contract Seam and Domain Controller Facades: Navigation, JavaScript, Cookies, Settings.