From 37ebf5a2d5947c880461d250bfad5c6c41a62cd2 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Fri, 27 Dec 2024 14:57:32 +0000 Subject: [PATCH] Add a log function for handling complex values to the WebView client. --- .../utils/WebViewWidgetMessageInterceptor.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 588fd25ac0..ea1e03cabb 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 @@ -41,6 +41,27 @@ class WebViewWidgetMessageInterceptor( override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { super.onPageStarted(view, url, favicon) + // Due to https://github.com/element-hq/element-x-android/issues/4097 + // we need to supply a logging implementation that correctly includes + // objects in log lines. + view?.evaluateJavascript( + """ + function logFn(logFn, ...args) { + logFn( + args.map( + a => typeof a === "string" ? a : JSON.stringify(a) + ).join(' ') + ); + }; + globalThis.console.debug = logFn.bind(null, console.debug); + globalThis.console.log = logFn.bind(null, console.log); + globalThis.console.info = logFn.bind(null, console.info); + globalThis.console.warn = logFn.bind(null, console.warn); + globalThis.console.error = logFn.bind(null, console.error); + """.trimIndent(), + null + ) + // We inject this JS code when the page starts loading to attach a message listener to the window. // This listener will receive both messages: // - EC widget API -> Element X (message.data.api == "fromWidget")