Skip to content

WebView fails to load after reboot if WiFi is slow to connect #33

@kimsey0

Description

@kimsey0

I'm running ImmichFrame Android on a cheap Frameo device. After a device reboot, the app displays a black screen when Use WebView? is enabled. The screen remains black indefinitely.

Root Cause

After investigating with diagnostic logging, I found that:

  1. The app launches before WiFi has connected
  2. WebView attempts to load the URL with no network available
  3. WebView "finishes" loading without triggering onReceivedError - it silently fails
  4. The existing retry logic in onReceivedError never fires, so no retry occurs
  5. Result: permanent black screen

When I disable Use WebView?, the app shows toast messages like "Retrying to fetch server settings... Attempt X of 36" and eventually succeeds once WiFi connects. This confirms the issue is specific to WebView's silent failure behavior.

Background

I understand the previous waitForNetwork check was removed in response to #21, where a VPN user found that Android's NET_CAPABILITY_INTERNET check returned false even when their VPN tunnel was working and could reach the ImmichFrame server.

Proposed Solution

Instead of relying on Android's network validation (which fails for VPN users) or WebView's error callbacks (which don't fire reliably), check actual server reachability before loading the WebView:

fun isServerReachable(url: String): Boolean {
    return try {
        val client = OkHttpClient.Builder()
            .connectTimeout(5, TimeUnit.SECONDS)
            .readTimeout(5, TimeUnit.SECONDS)
            .build()
        val request = Request.Builder().url(url).head().build()
        client.newCall(request).execute().use { response ->
            response.isSuccessful || response.code in 300..499
        }
    } catch (e: Exception) {
        false
    }
}

Then retry with toast feedback until the server is reachable.

Why this works for both cases:

  • Slow WiFi at boot: Server unreachable → retry until WiFi connects
  • VPN users: Once VPN tunnel is up, server is reachable even if Android reports "no internet"

This tests what actually matters: "can I reach my ImmichFrame server?"

I have a working implementation and can submit a PR if this approach is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions