Skip to content

fix(watcher): read Firefox page titles from the active window root - #428

Merged
ErikBjare merged 3 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/firefox-title-root
Dec 3, 2026
Merged

ErikBjare merged 3 commits into
ActivityWatch:masterfrom
TimeToBuildBob:fix/firefox-title-root

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Summary

Capture Firefox page titles from the matching active window root, where Gecko exposes the page WebView, rather than from an accessibility event's source (often only the toolbar).

  • Remove the Firefox-specific “never look up” gate; keep the existing 500ms retry / 5s recheck throttling.
  • Use the active root for the three already-supported Gecko package IDs, and reject roots belonging to another app.
  • Never descend into WebView content when looking for its title. The traversal remains bounded, and a missing title cannot recreate the deep-page traversal behind ActivityWatch crashes when using firefox browser on 0.14.4b1 #421.
  • Replace the old comment based on July's Firefox hierarchy with the behavior verified on Firefox 160.

This is a follow-up after #422, not another fix for the URL traversal ANR.

Reproduction and verification

CT102 Android API 34 emulator, Firefox 160.0.1, two locally served pages with distinct URLs and titles:

  1. Current master 91b4491c CI APK logs the Firefox URL but no Title: line.
  2. The accessibility dump has android.webkit.WebView text="B11D Page A" under the active root.
  3. Patched build logs Title: B11D Page A and Title: B11D Page B.
  4. Navigate B → A → B → Home: completed watcher events pair each URL with its own title, without carrying the preceding title forward.

Observed completed events (local fixture, no personal browsing data):

{"url":"10.0.2.2:8765/a.html","browser":"org.mozilla.firefox","title":"B11D Page A"}
{"url":"10.0.2.2:8765/b.html","browser":"org.mozilla.firefox","title":"B11D Page B"}
  • New Robolectric regression fails on unmodified master (expected Page A, got empty), passes with the fix.
  • Another-browser active-root regression prevents cross-app title attribution.
  • ./gradlew --no-daemon --max-workers=2 :mobile:testStandardDebugUnitTest: 479 tests, 0 failures.
  • :mobile:assembleStandardDebug: passes; tested using native libraries from the same current-master CI artifact.

Older Gecko versions that expose no page WebView/title still produce an empty title; no multi-window enumeration or unbounded fallback is added.

Git-Session-Id: cf75a813-f34f-431d-a1e8-d5f70423f278
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

What changed: 4 files, +92/-22 in mobile/src/test/java/net/activitywatch/android/watcher/, mobile/src/main/java/net/activitywatch/android/watcher/
Riskiest file: mobile/src/test/java/net/activitywatch/android/watcher/FirefoxTitleTest.kt (+69/-0)
Test: Run the repo's usual CI-equivalent checks locally

Review guide

Key files

  • mobile/src/test/java/net/activitywatch/android/watcher/FirefoxTitleTest.kt (+69/-0, Δ69)
  • mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt (+15/-16, Δ31)
  • mobile/src/test/java/net/activitywatch/android/watcher/TitleLookupGateTest.kt (+5/-3, Δ8)
  • mobile/src/main/java/net/activitywatch/android/watcher/TitleLookupGate.kt (+3/-3, Δ6)

Suggested verification

  • Run the repo's usual CI-equivalent checks locally

Auto-posted by scripts/github/pr-warmup-review-guide.py for #428.

@greptile-apps

greptile-apps Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

The PR reads Firefox titles from the matching active window root while keeping title throttling and avoiding page-content walks.

  • Gecko page titles come from the matching active window root.

Reviews (3) · Last reviewed commit: "fix(watcher): reject foreign roots befor..." · Reviewed by Greptile

Git-Session-Id: 26bdeeec-41b1-5629-84cc-195971587a75
@TimeToBuildBob

This comment has been minimized.

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click.

This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted.

@TimeToBuildBob

TimeToBuildBob commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Safe to merge — no P0/P1 findings on latest review

Updated after inline dispositions on finding threads — this is the current state; the verdict below is frozen at review time and is kept as the historical record of that pass.

Finding disposition
Finding Severity State
mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt:267 P2 superseded by latest review (not reproduced)
mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt:268 P2 accepted-tradeoff

The PR reads page titles for the three Gecko packages (GECKO_BROWSER_PACKAGES) from rootInActiveWindow instead of event.source, and skips the lookup when that root belongs to another package. TitleLookupGate.delayBeforeLookup no longer returns null for FIREFOX_PACKAGE, so Firefox uses the same 500ms retry and 5s recheck throttling as other browsers. findWebView now passes descendInto = { it.className != "android.webkit.WebView" } to findNode, so the search never enters a WebView's children. A new Robolectric FirefoxTitleTest is added, and the Firefox gate unit test is rewritten.

Needs a look — P2 only

Confidence 4/5

1 finding · ⚠️ 1 P2

⚠️ P2 medium — mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt:268

For Gecko browsers, processBrowserEvent reads the URL from the toolbar (ADDRESSBAR_URL_BOX via extractFirefoxUrl) and then reads the title from the page WebView under a separate rootInActiveWindow snapshot. Nothing ties the two together. After handleUrl(newUrl) starts a new session, hasTitle is false, so the gate returns 0 and lookUpTitle runs straight away. If Gecko updates the toolbar URL before the content WebView's text changes (navigation start versus title change), the previous page's title is stored for the new URL. hasTitle then becomes true, and the next check is deferred by TITLE_RECHECK_MS (5s). A visit to page B that is shorter than about 5s is therefore written with page A's title. Previously Firefox never got a title, so this cross-attribution is new to the Gecko path.

How this was verified: Checked TitleLookupGate.delayBeforeLookup: with the FIREFOX_PACKAGE early return removed, it returns 0 once per TITLE_LOOKUP_MS while hasTitle is false. processBrowserEvent and scheduleTitleLookup both call lookUpTitle on a rootInActiveWindow node for Gecko packages, so a lookup that never matches still walks the chrome tree every interval.

Consensus: 2/3 passes agreed — pass 2 looked and disagreed

Files changed (4) — the diff as I read it
  • mobile/src/main/java/net/activitywatch/android/watcher/TitleLookupGate.kt — Removes the browser == FIREFOX_PACKAGE early return null from delayBeforeLookup, updates its KDoc, and adds @Suppress("UNUSED_PARAMETER") for the now-unused browser parameter.
  • mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt — Adds GECKO_BROWSER_PACKAGES; processBrowserEvent uses rootInActiveWindow as the title root for those packages and rejects foreign-package roots; findWebView no longer descends into WebView nodes; replaces the old TODO comment.
  • mobile/src/test/java/net/activitywatch/android/watcher/FirefoxTitleTest.kt — New Robolectric tests covering four cases: title read from the window root, no traversal into a titleless WebView via a CountingNode shadow, a foreign root not consuming the gate interval, and a foreign root not supplying the title.
  • mobile/src/test/java/net/activitywatch/android/watcher/TitleLookupGateTest.kt — Replaces firefoxIsNeverLookedUp with firefoxUsesTheSameBoundedRetryInterval, which expects 0 and then TITLE_LOOKUP_MS - 100, and removes the assertNull import.
Previous review passes
commit score findings engine when
c1ec77cb7390 4/5 1 subscription 2026-12-03 13:25 UTC

Reviewed 410acf890041 · panel: claude-code:claude-opus-5-5 + codex:gpt-6.1-sol + claude-code:claude-opus-5-5#2 · subscription engine · 84s · about this reviewer

Maintainer commands

@TimeToBuildBob review (own line) — fresh review · @TimeToBuildBob fix — a worker acts on the findings. Once per comment; 👀 = received.

Git-Session-Id: 6a36555b-0877-5dbc-bf0d-6cefb7a350fa
@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

@greptileai review

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Review adjudication — maintainer decision

  • Fixed: No code change this session. Earlier commits added mutation-checked titleless-page coverage (c1ec77cb7390) and rejected foreign roots before consuming the title gate (410acf890041); both threads are resolved.
  • Remaining (non-blocking): The AI-review P2 about a stale title during navigation is accepted as a best-effort accuracy trade-off, not rejected as false. A synthetic mixed URL-B/title-A state retains A until the existing 5s recheck; a shorter visit can retain the wrong title. The inline thread now contains the test evidence and disposition and is resolved. No document URL/navigation token is exposed by the title node; an arbitrary delay or single-root read would not guarantee URL/title identity. I recommend merging the bounded Firefox title restoration with this limitation visible, subject to maintainer judgment.
  • Verified against: 410acf8900410f71152ff76f2e4ad6cf227069de for every classification above. Both the latest AI-review marker and Greptile's last-reviewed footer cover this head. No push this session.
  • CI: All applicable checks pass, including JVM tests, API-29 E2E, R8 smoke and Rust build; release/build jobs are skipped by the PR workflow. Greptile is 5/5. Additionally ran 11 focused tests, 0 failures, including a scratch mixed-snapshot/recheck test against unchanged head source.
  • Domain risk: Slow-loading pages, rapid navigation/back-forward and tab switches in Firefox: inspect completed URL/title pairs, especially visits shorter than 5s. Existing real Firefox 160 A/B navigation evidence in the PR passed; the synthetic test does not establish how often Firefox exposes the mixed state.
  • Convergence: Detector reports round_convergence.status = no_current_blocking, stable_rounds = 0 (required_stable_rounds = 2), and should_request_review_after_fixes = false. Its Greptile-only history contains one finding-bearing review; this is not evidence of two stable rounds. No unresolved automated findings remain, and no new review was triggered.

No merge performed; leaving the accuracy trade-off and merge decision with the maintainer.

@ErikBjare
ErikBjare merged commit 3b820d6 into ActivityWatch:master Dec 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants