From 7e8efebe4d353a5e65ed3d7a6049c831add3b2ce Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Sun, 30 Aug 2026 12:38:04 +0200 Subject: [PATCH 1/2] Fix crash due to JSON.stringify on a cirular structure in injectes js. --- .../utils/WebViewWidgetMessageInterceptor.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 c74ae90abd..3e1aa015d0 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 @@ -54,10 +54,28 @@ class WebViewWidgetMessageInterceptor( // objects in log lines. view.evaluateJavascript( """ + // Removing any parts that result in a circular structure. Circular structures crash JSON.stringify. + function simpleStringify(object) { + const simpleObject = {}; + for (const prop in object) { + if (!object.hasOwnProperty(prop)) { + continue; + } + if (typeof(object[prop]) == 'object') { + continue; + } + if (typeof(object[prop]) == 'function') { + continue; + } + simpleObject[prop] = object[prop]; + } + return JSON.stringify(simpleObject); + } + function logFn(consoleLogFn, ...args) { consoleLogFn( args.map( - a => typeof a === "string" ? a : JSON.stringify(a) + a => typeof a === "string" ? a : simpleStringify(a) ).join(' ') ); }; From dc2d05f9daac762ce1c0a81330c0cbad97c735e9 Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Sun, 30 Aug 2026 13:12:57 +0200 Subject: [PATCH 2/2] also add try catch block --- .../call/impl/utils/WebViewWidgetMessageInterceptor.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 3e1aa015d0..db81975bf1 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 @@ -55,7 +55,7 @@ class WebViewWidgetMessageInterceptor( view.evaluateJavascript( """ // Removing any parts that result in a circular structure. Circular structures crash JSON.stringify. - function simpleStringify(object) { + function safeStringify(object) { const simpleObject = {}; for (const prop in object) { if (!object.hasOwnProperty(prop)) { @@ -69,13 +69,17 @@ class WebViewWidgetMessageInterceptor( } simpleObject[prop] = object[prop]; } - return JSON.stringify(simpleObject); + try { + return JSON.stringify(simpleObject); + } catch { + return "{Failed to stringify object}"; + } } function logFn(consoleLogFn, ...args) { consoleLogFn( args.map( - a => typeof a === "string" ? a : simpleStringify(a) + a => typeof a === "string" ? a : safeStringify(a) ).join(' ') ); };