Add a log function for handling complex values to the WebView client.
This commit is contained in:
parent
a369218aeb
commit
37ebf5a2d5
1 changed files with 21 additions and 0 deletions
|
|
@ -41,6 +41,27 @@ class WebViewWidgetMessageInterceptor(
|
||||||
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
|
||||||
super.onPageStarted(view, url, favicon)
|
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.
|
// We inject this JS code when the page starts loading to attach a message listener to the window.
|
||||||
// This listener will receive both messages:
|
// This listener will receive both messages:
|
||||||
// - EC widget API -> Element X (message.data.api == "fromWidget")
|
// - EC widget API -> Element X (message.data.api == "fromWidget")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue