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..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 @@ -54,10 +54,32 @@ class WebViewWidgetMessageInterceptor( // objects in log lines. view.evaluateJavascript( """ + // Removing any parts that result in a circular structure. Circular structures crash JSON.stringify. + function safeStringify(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]; + } + try { + return JSON.stringify(simpleObject); + } catch { + return "{Failed to stringify object}"; + } + } + function logFn(consoleLogFn, ...args) { consoleLogFn( args.map( - a => typeof a === "string" ? a : JSON.stringify(a) + a => typeof a === "string" ? a : safeStringify(a) ).join(' ') ); };