android icon indicating copy to clipboard operation
android copied to clipboard

Frontend stale-build recovery navigation (?ha_cache_bust=) is opened in the external browser instead of the WebView

Open skm7463 opened this issue 3 months ago • 3 comments

Describe the bug

When the frontend's stale-build recovery (Home Assistant Core 2026.9.0, frontend 20260826.4) reloads the page with location.replace(<same URL>?ha_cache_bust=<timestamp>), the Android app hands that navigation to the system browser instead of loading it in its own WebView. Chrome opens on top of the app at the server's URL, and because Chrome has no session it lands on the Home Assistant login page. With a permanently-failing import (my case, see below) this happens on every single app launch. Even with the frontend fix in home-assistant/frontend#53940 the recovery still fires legitimately after some updates, so the app will still bounce to Chrome then. Bram asked for this to be filed against the app.

To reproduce

  1. Core 2026.9.0. Register a Lovelace resource (or frontend: extra_module_url entry) pointing at a file that does not exist, e.g. /local/missing.js.
  2. Open the app. The dashboard loads and authenticates normally.
  3. Within a few seconds the frontend detects the failed import, wipes caches and navigates to https://<server>/?external_auth=1&ha_cache_bust=1788437722060.
  4. Chrome opens with that URL and shows the HA login page.

Server access log for one launch (the phone is 192.168.23.45; note the user agents):

13:15:22.082  GET /?external_auth=1                          200  "Mozilla/5.0 (Linux; Android 16; SM-S938B ...; wv) ... Home Assistant/2026.6.5-22884 (Android 16; SM-S938B)"
13:15:22.741  GET /?external_auth=1&ha_cache_bust=1788437722060  200  "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 ... Chrome/151.0.0.0 Mobile Safari/537.36"

First line is the app's WebView loading the frontend. Second line, 0.7 s later, is the same URL plus ha_cache_bust, fetched by Chrome itself (no wv, no app suffix). The URL is same-origin, same path, only a query parameter added. In a desktop browser the same navigation simply reloads the page.

Expected behavior

A location.replace / navigation to the app's own server origin should stay inside the WebView regardless of query parameters, so the frontend's recovery completes in-app (the frontend then strips ha_cache_bust on the next successful connect). Only genuinely foreign origins should go to the external browser.

Environment

  • Companion app 2026.6.5-full (22884), Android 16, Samsung SM-S938B
  • Core 2026.9.0, HAOS on Proxmox, connected over the internal URL (https, port 8123)
  • Not yet tested on 2026.8.x (FrontendScreen); happy to update and retest if that helps

Additional context

Root cause on my side was a dead extra_module_url file; fixed by removing it, and the core-side 31-day caching of the 404 is filed as a separate core issue. The app behaviour is independent of both: any navigation with ha_cache_bust in the query goes to Chrome.

skm7463 avatar Sep 03 '26 13:09 skm7463

Having the same issue after the latest update

Devilzeyez avatar Sep 04 '26 04:09 Devilzeyez

I tried also the newest 2026.8.4-full app.

But the problem only changes to "reloads the view" every few seconds. But the problem with the opened browser is solved. That doesn't happen with the beta app.

I restarted ha and as it looks, the restarts are gone. So I have "no" problems with the beta app at the moment, as long as the app stays open. Because when the app get closed, the problem with the reloads comes back until the next ha restart.

ChristianTannheimer avatar Sep 04 '26 05:09 ChristianTannheimer

I'm looking at this and indeed the 8.4 is fixing the issue (not yet in prod). The issue was that we were comparing URLs like this to decide if we stay in the app or not

} else if (!webView.url.toString().contains(target)) {                                                                                                                                                                                                                                                               
      Timber.d("Launching browser")

and webView.url is https://server/?external_auth=1; the target is that plus &ha_cache_bust=…, so contains is false and it launches the browser. Any added query param does this, not just ha_cache_bust.

Starting from the 8.4 we rework this logic by

uri.hasSameOrigin(urlFlow.value)

That only cheks the origin of the URL so https://server:PORT

I'm closing the issue as it is addressed. Hopefully going to land in prod during the week if Google approve the current build.

TimoPtr avatar Sep 07 '26 08:09 TimoPtr