feat: Forward ElementCall logs to the native logs

This commit is contained in:
Valere
2026-03-30 14:40:04 +02:00
committed by Stefan Ceriu
parent 42ac71cbc0
commit bec8f55f29
2 changed files with 38 additions and 0 deletions
@@ -60,6 +60,8 @@ enum CallScreenJavaScriptMessageName: String, CaseIterable {
case onOutputDeviceSelect
/// Used to handle the webview back button
case onBackButtonPressed
/// Forward logs to the native side for debugging purposes.
case forwardLogs
private var postMessageScript: String {
switch self {
@@ -97,6 +99,25 @@ enum CallScreenJavaScriptMessageName: String, CaseIterable {
window.webkit.messageHandlers.\(rawValue).postMessage("");
}
"""
case .forwardLogs:
"""
(function() {
function forwardLog(level, args) {
const message = Array.from(args).map(a => {
try { return typeof a === 'object' ? JSON.stringify(a) : String(a); }
catch(e) { return String(a); }
}).join(' ');
window.webkit.messageHandlers.\(rawValue).postMessage({ level: level, message: message });
}
['log', 'debug', 'info', 'warn', 'error'].forEach(function(level) {
const original = console[level].bind(console);
console[level] = function(...args) {
original(...args);
forwardLog(level, args);
};
});
})();
"""
}
}