Skip to content

test(webview): execute theme hook while the document has no root - #376

Merged
ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:test/theme-hook-rootless-document
Oct 19, 2026
Merged

ErikBjare merged 2 commits into
ActivityWatch:masterfrom
TimeToBuildBob:test/theme-hook-rootless-document

Conversation

@TimeToBuildBob

Copy link
Copy Markdown
Contributor

What

Adds a real WebView instrumentation test for the rootless-document theme-hook failure fixed by #375. The JVM source-string assertion cannot show whether the hook actually survives document.documentElement === null.

The test loads an isolated fixture, removes its root, injects the production ANDROID_THEME_HOOK_JS, checks installation succeeded without reporting settlement, restores #app/#wrapper, and verifies the bridge receives the expected navigation token exactly once. More mutations and a repeated injection must not produce a second report. The WebView is destroyed in finally; no server, app preferences or permission changes are needed.

Dependency

Includes the existing #375 fix commit unchanged, followed by one test-only commit. Merge #375 first; after that this PR reduces to the instrumentation test. This does not edit the monitored #375 branch or add another production fix.

Verification

Executed on Bob's remote KVM Android 14 gptme-test emulator:

  • RED, master 68947c0 plus new test: fails with TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
  • GREEN, the same test plus fix(webview): keep the theme hook alive when the document has no root yet #375's 11c7f31: 1 test passed, BUILD SUCCESSFUL.
  • Both runs used ./gradlew --no-daemon :mobile:connectedStandardDebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=net.activitywatch.android.RootlessThemeHookTest.
  • The existing make test-e2e-main includes this class automatically; no workflow change is needed. Full CI is pending, not claimed green.

This is behavioral regression coverage, not a claim that the separate native navigation-tag race is fixed. The fixture uses the light theme to isolate missing-root observation from stylesheet-loading behavior already covered by DashboardThemePaintTest.

… yet

onPageFinished can deliver ANDROID_THEME_HOOK_JS into a document that has
not parsed its root element yet, when the previous navigation finishes
after the next one started. document.documentElement is then null, and
observing it threw, aborting the whole hook before checkSettled() ran.
That document could never report settlement, so the WebView stayed hidden
for good.

Observe document.documentElement || document instead: the Document covers
the same subtree and survives the empty-document window.

Evidence: ActivityWatch/aw-android master run 39307023808 (Build, commit
68947c0) failed DashboardThemePaintTest with 'Timed out waiting for
WebView state' at the final reveal, and the only console error in the
emulator logcat was this exact throw at hook line 76.

Git-Session-Id: 21420750-d15e-5941-9b24-25826fcda305
Git-Session-Id: 79c7f0bd-b70a-4964-b470-e6daef89d73e
@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

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

Summary

Adds a real WebView regression test for installing ANDROID_THEME_HOOK_JS while the document has no root.

  • The Android theme hook keeps watching until a rootless page gains its dashboard content.

TimeToBuildBob explicitly leaves the separate native navigation-tag race out of scope; this PR does not claim to fix it.

Reviews (1) · Last reviewed commit: "test(webview): execute theme hook while ..." · Reviewed by Greptile

@TimeToBuildBob

Copy link
Copy Markdown
Contributor Author

Greptile reviewed fd2d572 with no actionable findings (5/5); there are no inline review threads or unanswered human comments. CI is still running, so no rerun or code change is needed now. Merge remains maintainer-owned, with #375 to land first as described above.

@ErikBjare
ErikBjare merged commit 0e5be5d into ActivityWatch:master Oct 19, 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