fix(android): prevent WebView white screen on resume

Stop forcing LAYER_TYPE_HARDWARE on the WebView in the shared
WebHelper.setupView() (used by both CapacitorMainActivity and the legacy
FullscreenActivity). The forced view-level hardware layer renders the
whole WebView into an off-screen GPU texture that can be released when
the app is backgrounded and is not always repainted on resume — the
likely cause of the blank/white screen reported after switching apps and
returning. GPU acceleration is unaffected: it comes from
android:hardwareAccelerated="true" in the manifest, not from this call.

The original setLayerType(LAYER_TYPE_HARDWARE) was added in 2021's
"feat: enable hardware acceleration" commit, likely under the
misconception that it was required to enable acceleration.

Note: the bug is device/GPU-specific and not locally reproducible, so
this is unverified hardening rather than a confirmed fix. The competing
cause — the WebView renderer process being killed under memory pressure
(no onRenderProcessGone handler) — is a separate, higher-risk follow-up.
This commit is contained in:
Johannes Millan 2026-06-10 20:39:23 +02:00
parent b87788c914
commit 6c45246750

View file

@ -23,7 +23,13 @@ class WebHelper {
@SuppressLint("SetJavaScriptEnabled")
fun setupView(wv: WebView, modifyUA: Boolean) : WebView {
wv.setLayerType(View.LAYER_TYPE_HARDWARE, null)
// Use the platform default layer type. Forcing LAYER_TYPE_HARDWARE (added in
// 2021's "enable hardware acceleration" commit) isn't needed for GPU
// acceleration — that comes from android:hardwareAccelerated="true" in the
// manifest. Rendering the WebView into a view-level off-screen texture is the
// likely cause of the blank/white screen some users report after backgrounding
// and returning (Play Store review; not locally reproducible).
wv.setLayerType(View.LAYER_TYPE_NONE, null)
wv.isFocusableInTouchMode = true
// Paint the WebView surface in the theme background so the adjustResize