diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt index f7ab2c57afc..c74ae90abd8 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/utils/WebViewWidgetMessageInterceptor.kt @@ -140,26 +140,33 @@ class WebViewWidgetMessageInterceptor( } } - // Create a WebMessageListener, which will receive messages from the WebView and reply to them - val webMessageListener = WebViewCompat.WebMessageListener { _, message, _, _, _ -> - onMessageReceived(message.data) - } - - // Use WebMessageListener if supported, otherwise use JavascriptInterface - if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) { + // Always register JavascriptInterface as the baseline message channel. + // This works on all WebView implementations including Huawei. + webView.addJavascriptInterface(object { + @JavascriptInterface + fun postMessage(json: String?) { + onMessageReceived(json) + } + }, LISTENER_NAME) + + // Additionally register WebMessageListener on WebViews that reliably support it. + // Huawei WebView (Chromium < 119) reports WEB_MESSAGE_LISTENER as supported + // but silently drops messages, so we only trust it on Chromium 119+. + // See: https://github.com/element-hq/element-x-android/issues/6632 + val webViewVersionName = WebViewCompat.getCurrentWebViewPackage(webView.context)?.versionName.orEmpty() + Timber.d("Using WebView version: $webViewVersionName") + val webViewVersionCode = webViewVersionName.split(".").firstOrNull()?.toIntOrNull() ?: 0 + + if (webViewVersionCode >= 119 && + WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) { WebViewCompat.addWebMessageListener( webView, LISTENER_NAME, setOf("*"), - webMessageListener - ) - } else { - webView.addJavascriptInterface(object { - @JavascriptInterface - fun postMessage(json: String?) { - onMessageReceived(json) + WebViewCompat.WebMessageListener { _, message, _, _, _ -> + onMessageReceived(message.data) } - }, LISTENER_NAME) + ) } }