feat: add global console shim for user scripts logging

This commit is contained in:
Udhay-Adithya
2025-09-10 12:32:57 +05:30
parent 994137e38c
commit 20982b93a6
2 changed files with 15 additions and 1 deletions

View File

@@ -1,4 +1,3 @@
export 'flutter_js_service.dart';
export 'hive_services.dart'; export 'hive_services.dart';
export 'history_service.dart'; export 'history_service.dart';
export 'window_services.dart'; export 'window_services.dart';

View File

@@ -609,6 +609,21 @@ const ad = {
}; };
// Provide a global console shim so user scripts using `console.*` are captured.
// We support log/info/warn/error. `info` aliases to `log`.
try {
// Overwrite or define a minimal console that routes to Dart.
// Used globalThis to ensure visibility across async tasks and inner scopes.
globalThis.console = {
log: (...args) => { try { sendMessage('consoleLog', JSON.stringify(args)); } catch (_) {} },
info: (...args) => { try { sendMessage('consoleLog', JSON.stringify(args)); } catch (_) {} },
warn: (...args) => { try { sendMessage('consoleWarn', JSON.stringify(args)); } catch (_) {} },
error: (...args) => { try { sendMessage('consoleError', JSON.stringify(args)); } catch (_) {} },
};
} catch (e) {
// Ignore if cannot define global console
}
// --- End of APIDash Setup Script --- // --- End of APIDash Setup Script ---
// User's script will be appended below this line by Dart. // User's script will be appended below this line by Dart.