Skip to content

fix(web-watcher): don't walk Firefox page content to find the URL bar - #422

Merged
ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix-421
Dec 3, 2026
Merged

ErikBjare merged 1 commit into
ActivityWatch:masterfrom
TimeToBuildBob:fix-421

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

Fixes #421.

Cause

extractFirefoxUrl searches rootInActiveWindow depth-first for ADDRESSBAR_URL_BOX. In Firefox 160.0.1 the page's android.webkit.WebView node sits under swipeRefresh, which comes before composable_toolbar. The search therefore walks the page first. On a large page it spends the whole MAX_TRAVERSAL_NODES budget (2000 getChild binder calls) on the service's main thread, on every event, and usually never reaches the URL bar.

Change

The URL bar search no longer fetches the children of WebView nodes. findNode gets an optional descendInto predicate for this; other callers are unchanged.

Verification

API 34 x86_64 emulator, Firefox 160.0.1, a local page with 3000 paragraphs (each a link and a button), load then six scroll swipes. "Truncated" counts the NodeTraversal: ... hit node budget (2000) warnings:

Build Truncated walks Url: log lines
0.14.4b1 release APK 73 5
current master, debug 60 24
this branch, debug (two runs) 0 / 0 81 / 89

In an earlier run on the release APK, consecutive truncation warnings were about 450 ms apart while scrolling, so the main thread had little idle time. I did not reproduce a system ANR dialog on the emulator, and I have not tested on the reporter's device.

:mobile:testStandardDebugUnitTest: 382 tests, 0 failures, including a new one for descendInto.

Not covered

  • A single getChild can still block if Firefox's own UI thread is busy. Moving the lookup off the main thread would be a larger change.
  • The comment on findWebView says page content is not a descendant of the window root. That did not match what I saw on 160.0.1, so Firefox page titles may be recoverable. I left that for a separate change.

The URL bar lookup walks the active window depth-first. Firefox places the
page's WebView ahead of the toolbar, so on a large page every accessibility
event spent the whole 2000-node budget in getChild binder calls on the main
thread, and usually never reached the URL bar.

Skip the children of WebView nodes.

Fixes ActivityWatch#421

Git-Session-Id: 18f46105-6b6d-4340-9042-0c7216e0dd30
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR skips children of android.webkit.WebView nodes when searching for Firefox’s URL bar.

  • Firefox URL searches skip page content to reach the toolbar.

Reviews (1) · Last reviewed commit: "fix(web-watcher): don't walk Firefox pag..." · Reviewed by Greptile

@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 Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI code review

Adds an optional descendInto: (T) -> Boolean predicate to the private traverse(), to findNodeIn() and to findNode(). When descendInto returns false for a child, that child is still passed to visit, then recycled without its children being fetched. WebWatcher.extractFirefoxUrl now passes descendInto = { it.className != "android.webkit.WebView" }, so the ADDRESSBAR_URL_BOX search skips web content. A new unit test covers the skip-subtree behaviour.

Safe to merge — no P0/P1 findings

Confidence 5/5

✅ No findings. The diff looks correct to me on this pass.

Files changed (3) — the diff as I read it
  • mobile/src/main/java/net/activitywatch/android/watcher/AccessibilityNodeTraversal.kt — Adds a defaulted descendInto parameter to traverse, findNodeIn and findNode; after a failed visit, a child rejected by descendInto is recycled and not pushed onto the stack.
  • mobile/src/main/java/net/activitywatch/android/watcher/WebWatcher.kt — extractFirefoxUrl calls findNode with descendInto = { it.className != "android.webkit.WebView" } and adds a comment referencing aw-android#421.
  • mobile/src/test/java/net/activitywatch/android/watcher/AccessibilityNodeTraversalTest.kt — Adds a test that a node excluded by descendInto is visited but its 4000 children are never fetched, asserting 3 getChild calls and the recycle counts.

Reviewed fbb7203ddea1 · panel: claude-code:claude-opus-5-5 + claude-code:claude-opus-5-5#2 + claude-code:claude-opus-5-5#3 · subscription engine · 40s · about this reviewer

Maintainer commands

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

@ErikBjare
ErikBjare merged commit f560aeb 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.

ActivityWatch crashes when using firefox browser on 0.14.4b1

2 participants